Skip to content

Commit

Permalink
added Save Button
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Sep 11, 2024
1 parent 62a9f1d commit 3310cb9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
59 changes: 54 additions & 5 deletions src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void MultiReplace::positionAndResizeControls(int windowWidth, int windowHeight)
int comboWidth = windowWidth - 365;
int frameX = windowWidth - 320;
int listWidth = windowWidth - 260;
int listHeight = windowHeight - 295;
int listHeight = windowHeight - 310;
int checkboxX = buttonX - 105;

// Static positions and sizes
Expand Down Expand Up @@ -168,6 +168,8 @@ void MultiReplace::positionAndResizeControls(int windowWidth, int windowHeight)
ctrlMap[IDC_CLEAR_MARKS_BUTTON] = { buttonX, 223, 160, 30, WC_BUTTON, getLangStrLPCWSTR(L"panel_clear_all_marks"), BS_PUSHBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_LOAD_FROM_CSV_BUTTON] = { buttonX, 284, 160, 30, WC_BUTTON, getLangStrLPCWSTR(L"panel_load_list"), BS_PUSHBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_SAVE_TO_CSV_BUTTON] = { buttonX, 319, 160, 30, WC_BUTTON, getLangStrLPCWSTR(L"panel_save_list"), BS_PUSHBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_SAVE_BUTTON] = { buttonX, 319, 35, 30, WC_BUTTON, L"💾", BS_PUSHBUTTON | WS_TABSTOP, getLangStrLPCWSTR(L"tooltip_save") }; // "Save" Button mit Symbol
ctrlMap[IDC_SAVE_AS_BUTTON] = { buttonX + 40, 319, 120, 30, WC_BUTTON, getLangStrLPCWSTR(L"panel_save_as"), BS_PUSHBUTTON | WS_TABSTOP, NULL }; // "Save As" Button mit Text
ctrlMap[IDC_EXPORT_BASH_BUTTON] = { buttonX, 354, 160, 30, WC_BUTTON, getLangStrLPCWSTR(L"panel_export_to_bash"), BS_PUSHBUTTON | WS_TABSTOP, NULL };
ctrlMap[IDC_UP_BUTTON] = { buttonX + 5, 404, 30, 30, WC_BUTTON, L"", BS_PUSHBUTTON | WS_TABSTOP | BS_CENTER, NULL };
ctrlMap[IDC_DOWN_BUTTON] = { buttonX + 5, 404 + 30 + 5, 30, 30, WC_BUTTON, L"", BS_PUSHBUTTON | WS_TABSTOP | BS_CENTER, NULL };
Expand Down Expand Up @@ -318,15 +320,14 @@ void MultiReplace::initializeDragAndDrop() {
}
}


void MultiReplace::moveAndResizeControls() {
// IDs of controls to be moved or resized
const int controlIds[] = {
IDC_FIND_EDIT, IDC_REPLACE_EDIT, IDC_SWAP_BUTTON, IDC_STATIC_FRAME, IDC_COPY_TO_LIST_BUTTON, IDC_REPLACE_ALL_BUTTON,
IDC_REPLACE_BUTTON, IDC_REPLACE_ALL_SMALL_BUTTON, IDC_2_BUTTONS_MODE, IDC_FIND_BUTTON, IDC_FIND_NEXT_BUTTON,
IDC_FIND_PREV_BUTTON, IDC_MARK_BUTTON, IDC_MARK_MATCHES_BUTTON, IDC_CLEAR_MARKS_BUTTON, IDC_COPY_MARKED_TEXT_BUTTON,
IDC_USE_LIST_CHECKBOX, IDC_LOAD_FROM_CSV_BUTTON, IDC_SAVE_TO_CSV_BUTTON, IDC_SHIFT_FRAME, IDC_UP_BUTTON, IDC_DOWN_BUTTON,
IDC_SHIFT_TEXT, IDC_EXPORT_BASH_BUTTON
IDC_USE_LIST_CHECKBOX, IDC_LOAD_FROM_CSV_BUTTON, IDC_SAVE_TO_CSV_BUTTON, IDC_SAVE_BUTTON, IDC_SAVE_AS_BUTTON,
IDC_SHIFT_FRAME, IDC_UP_BUTTON, IDC_DOWN_BUTTON, IDC_SHIFT_TEXT, IDC_EXPORT_BASH_BUTTON
};

std::unordered_map<int, HWND> hwndMap; // Store HWNDs to avoid multiple calls to GetDlgItem
Expand Down Expand Up @@ -392,6 +393,11 @@ void MultiReplace::updateButtonVisibilityBasedOnMode() {
ShowWindow(GetDlgItem(_hSelf, IDC_MARK_MATCHES_BUTTON), twoButtonsMode ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(_hSelf, IDC_COPY_MARKED_TEXT_BUTTON), twoButtonsMode ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(_hSelf, IDC_MARK_BUTTON), twoButtonsMode ? SW_HIDE : SW_SHOW);

// for save buttons
ShowWindow(GetDlgItem(_hSelf, IDC_SAVE_BUTTON), twoButtonsMode ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(_hSelf, IDC_SAVE_AS_BUTTON), twoButtonsMode ? SW_SHOW : SW_HIDE);
ShowWindow(GetDlgItem(_hSelf, IDC_SAVE_TO_CSV_BUTTON), twoButtonsMode ? SW_HIDE : SW_SHOW);
}

void MultiReplace::setUIElementVisibility() {
Expand Down Expand Up @@ -691,7 +697,7 @@ void MultiReplace::updateListViewAndColumns(HWND listView, LPARAM lParam) {
ListView_SetColumnWidth(listView, 4, perColumnWidth); // Find Text
ListView_SetColumnWidth(listView, 5, perColumnWidth); // Replace Text

MoveWindow(listHwnd, 20, 284, newWidth - 260, newHeight - 295, TRUE);
MoveWindow(listHwnd, 20, 284, newWidth - 260, newHeight - 310, TRUE);

SendMessage(widths.listView, WM_SETREDRAW, TRUE, 0);
//InvalidateRect(widths.listView, NULL, TRUE);
Expand Down Expand Up @@ -2364,6 +2370,7 @@ INT_PTR CALLBACK MultiReplace::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
}
break;

case IDC_SAVE_AS_BUTTON:
case IDC_SAVE_TO_CSV_BUTTON:
{
std::wstring csvDescription = getLangStr(L"filetype_csv"); // "CSV Files (*.csv)"
Expand Down Expand Up @@ -5787,6 +5794,39 @@ void MultiReplace::showStatusMessage(const std::wstring& messageText, COLORREF c
UpdateWindow(GetParent(hStatusMessage));
}

void MultiReplace::showListFilePath() {
const size_t MAX_PATH_DISPLAY_LENGTH = 120; // Maximum length for the displayed path

// Use the stored file path and shorten it if necessary
std::wstring displayPath = listFilePath;

// Shorten the path if it exceeds the maximum length
if (displayPath.size() > MAX_PATH_DISPLAY_LENGTH) {
size_t lastSlashPos = displayPath.find_last_of(L"\\/");
std::wstring fileName = (lastSlashPos != std::wstring::npos) ? displayPath.substr(lastSlashPos + 1) : displayPath;
if (fileName.size() > MAX_PATH_DISPLAY_LENGTH) {
displayPath = fileName.substr(0, MAX_PATH_DISPLAY_LENGTH - 3) + L"...";
}
else {
size_t remainingLength = MAX_PATH_DISPLAY_LENGTH - fileName.size();
displayPath = displayPath.substr(0, remainingLength) + L"..." + fileName;
}
}

// Get the handle for the path display control
HWND hPathDisplay = GetDlgItem(_hSelf, IDC_PATH_DISPLAY);

// Set the new path text
SetWindowText(hPathDisplay, displayPath.c_str());

// Invalidate the area of the parent where the control resides
RECT rect;
GetWindowRect(hPathDisplay, &rect);
MapWindowPoints(HWND_DESKTOP, GetParent(hPathDisplay), (LPPOINT)&rect, 2);
InvalidateRect(GetParent(hPathDisplay), &rect, TRUE);
UpdateWindow(GetParent(hPathDisplay));
}

std::wstring MultiReplace::getSelectedText() {
SIZE_T length = SendMessage(nppData._scintillaMainHandle, SCI_GETSELTEXT, 0, 0);

Expand Down Expand Up @@ -6120,6 +6160,11 @@ void MultiReplace::saveListToCsv(const std::wstring& filePath, const std::vector
EnableWindow(_replaceListView, TRUE);
}

void MultiReplace::saveListToCurrentFile() {
// Dummy-Implementierung
showStatusMessage(getLangStr(L"status_save_to_file"), RGB(0, 128, 0));
}

void MultiReplace::loadListFromCsvSilent(const std::wstring& filePath, std::vector<ReplaceItemData>& list) {
// Open file in binary mode to read UTF-8 data
std::ifstream inFile(filePath);
Expand Down Expand Up @@ -6184,6 +6229,10 @@ void MultiReplace::loadListFromCsvSilent(const std::wstring& filePath, std::vect
void MultiReplace::loadListFromCsv(const std::wstring& filePath) {
try {
loadListFromCsvSilent(filePath, replaceListData);
// Store the file path only if loading was successful
listFilePath = filePath;
// Display the path below the list
showListFilePath();
}
catch (const CsvLoadException& ex) {
// Resolve the error key to a localized string when displaying the message
Expand Down
5 changes: 5 additions & 0 deletions src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ class MultiReplace : public StaticDialog
SciFnDirect pSciMsg = nullptr;
sptr_t pSciWndData = 0;

// List related
std::wstring listFilePath = L""; //to store the file path of loaded list

// GUI control-related constants
const std::vector<int> selectionRadioDisabledButtons = {
IDC_FIND_BUTTON, IDC_FIND_NEXT_BUTTON, IDC_REPLACE_BUTTON
Expand Down Expand Up @@ -536,6 +539,7 @@ class MultiReplace : public StaticDialog
void updateHeaderSelection();
void updateHeaderSortDirection();
void showStatusMessage(const std::wstring& messageText, COLORREF color);
void showListFilePath();
void displayResultCentered(size_t posStart, size_t posEnd, bool isDownwards);
std::wstring getSelectedText();
LRESULT getEOLLength();
Expand All @@ -555,6 +559,7 @@ class MultiReplace : public StaticDialog
std::wstring MultiReplace::openFileDialog(bool saveFile, const std::vector<std::pair<std::wstring, std::wstring>>& filters, const WCHAR* title, DWORD flags, const std::wstring& fileExtension);
bool saveListToCsvSilent(const std::wstring& filePath, const std::vector<ReplaceItemData>& list);
void saveListToCsv(const std::wstring& filePath, const std::vector<ReplaceItemData>& list);
void saveListToCurrentFile();
void loadListFromCsvSilent(const std::wstring& filePath, std::vector<ReplaceItemData>& list);
std::wstring escapeCsvValue(const std::wstring& value);
std::wstring unescapeCsvValue(const std::wstring& value);
Expand Down
19 changes: 11 additions & 8 deletions src/StaticDialog/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@
#define IDC_DELETE_REPLACE_ITEM_BUTTON 5019
#define IDC_LOAD_FROM_CSV_BUTTON 5020
#define IDC_SAVE_TO_CSV_BUTTON 5021
#define IDC_EXPORT_BASH_BUTTON 5022
#define IDC_UP_BUTTON 5023
#define IDC_DOWN_BUTTON 5024
#define IDC_SHIFT_FRAME 5025
#define IDC_SHIFT_TEXT 5026
#define ID_REPLACE_ALL_OPTION 5027
#define ID_REPLACE_IN_ALL_DOCS_OPTION 5028
#define IDC_SAVE_BUTTON 5022
#define IDC_SAVE_AS_BUTTON 5023
#define IDC_EXPORT_BASH_BUTTON 5024
#define IDC_UP_BUTTON 5025
#define IDC_DOWN_BUTTON 5026
#define IDC_SHIFT_FRAME 5027
#define IDC_SHIFT_TEXT 5028
#define ID_REPLACE_ALL_OPTION 5029
#define ID_REPLACE_IN_ALL_DOCS_OPTION 5030

#define IDC_STATIC_FIND 5100
#define IDC_STATIC_REPLACE 5101
#define IDC_STATUS_MESSAGE 5102
#define IDC_PATH_DISPLAY 5103

#define IDC_WHOLE_WORD_CHECKBOX 5200
#define IDC_MATCH_CASE_CHECKBOX 5201
Expand Down Expand Up @@ -126,7 +129,7 @@
#define POS_X 92
#define POS_Y 40
#define MIN_WIDTH 1023
#define MIN_HEIGHT 485
#define MIN_HEIGHT 500

#define IDC_WEBSITE_LINK_VALUE TEXT("https://github.com/daddel80/notepadpp-multireplace/issues")

Expand Down
1 change: 1 addition & 0 deletions src/language_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ std::unordered_map<std::wstring, std::wstring> languageMap = {
{ L"panel_clear_all_marks", L"Clear all marks" },
{ L"panel_load_list", L"Load List" },
{ L"panel_save_list", L"Save List" },
{ L"panel_save_as", L"Save As..." },
{ L"panel_export_to_bash", L"Export to Bash" },
{ L"panel_shift_lines", L"Shift Lines" },
{ L"panel_use_list", L"Use List" },
Expand Down

0 comments on commit 3310cb9

Please sign in to comment.