From f4132c1634a1d216c44d0b8acab522b09e5c8a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Sun, 10 May 2015 13:06:25 +0200 Subject: [PATCH 1/3] Add "repeat" option to column editor. This allows the inserted text to be repeated x times. As an example, if we have selected 6 columns and let initial number = 10, increase by = 5 and repeat = 2, then the column editor will insert the following: 10 10 15 15 20 20 --- .../ScitillaComponent/ScintillaEditView.cpp | 46 ++++++++++++++----- .../src/ScitillaComponent/ScintillaEditView.h | 2 +- .../src/ScitillaComponent/columnEditor.cpp | 36 +++++++++++++-- .../src/ScitillaComponent/columnEditor.rc | 20 ++++---- .../src/ScitillaComponent/columnEditor_rc.h | 2 + 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index ed0f9cc4..ebedefd7 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -2587,8 +2587,10 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const TCHAR *str) } } -void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int incr, UCHAR format) +void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const int kiInitial, const int kiIncr, const int kiRepeat, const UCHAR format) { + assert(kiRepeat > 0); + // 0000 00 00 : Dec BASE_10 // 0000 00 01 : Hex BASE_16 // 0000 00 10 : Oct BASE_08 @@ -2611,28 +2613,49 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int in else if (f == BASE_02) base = 2; - int endNumber = initial + incr * (cmi.size() - 1); - int nbEnd = getNbDigits(endNumber, base); - int nbInit = getNbDigits(initial, base); - int nb = max(nbInit, nbEnd); - const int stringSize = 512; TCHAR str[stringSize]; + // Compute the numbers to be placed at each column. + std::vector numbers; + { + int curNumber = kiInitial; + const unsigned int kiMaxSize = cmi.size(); + while(numbers.size() < kiMaxSize) + { + for(int i = 0; i < kiRepeat; i++) + { + numbers.push_back(curNumber); + if (numbers.size() >= kiMaxSize) + { + break; + } + } + curNumber += kiIncr; + } + } + + assert(numbers.size()> 0); + + const int kibEnd = getNbDigits(*numbers.rbegin(), base); + const int kibInit = getNbDigits(kiInitial, base); + const int kib = std::max(kibInit, kibEnd); + int totalDiff = 0; - for (size_t i = 0, len = cmi.size() ; i < len ; ++i) + const size_t len = cmi.size(); + for (size_t i = 0 ; i < len ; i++) { if (cmi[i].isValid()) { - int len2beReplace = cmi[i]._selRpos - cmi[i]._selLpos; - int diff = nb - len2beReplace; + const int len2beReplaced = cmi[i]._selRpos - cmi[i]._selLpos; + const int diff = kib - len2beReplaced; cmi[i]._selLpos += totalDiff; cmi[i]._selRpos += totalDiff; - int2str(str, stringSize, initial, base, nb, isZeroLeading); + int2str(str, stringSize, numbers.at(i), base, kib, isZeroLeading); - bool hasVirtualSpc = cmi[i]._nbVirtualAnchorSpc > 0; + const bool hasVirtualSpc = cmi[i]._nbVirtualAnchorSpc > 0; if (hasVirtualSpc) // if virtual space is present, then insert space { for (int j = 0, k = cmi[i]._selLpos; j < cmi[i]._nbVirtualCaretSpc ; ++j, ++k) @@ -2650,7 +2673,6 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int in const char *strA = wmc->wchar2char(str, cp); execute(SCI_REPLACETARGET, (WPARAM)-1, (LPARAM)strA); - initial += incr; if (hasVirtualSpc) { totalDiff += cmi[i]._nbVirtualAnchorSpc + lstrlen(str); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index e296ba64..e5a8cfc0 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -576,7 +576,7 @@ public: ColumnModeInfos getColumnModeSelectInfo(); void columnReplace(ColumnModeInfos & cmi, const TCHAR *str); - void columnReplace(ColumnModeInfos & cmi, int initial, int incr, UCHAR format); + void columnReplace(ColumnModeInfos & cmi, const int initial, const int incr, const int repeat, const UCHAR format); void foldChanged(int line, int levelNow, int levelPrev); void clearIndicator(int indicatorNumber) { diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.cpp b/PowerEditor/src/ScitillaComponent/columnEditor.cpp index b5e8b790..19520940 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor.cpp +++ b/PowerEditor/src/ScitillaComponent/columnEditor.cpp @@ -29,6 +29,7 @@ #include "precompiledHeaders.h" #include "columnEditor.h" #include "ScintillaEditView.h" +#include void ColumnEditorDlg::display(bool toShow) const @@ -136,6 +137,11 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) { int initialNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INITNUM_EDIT, NULL, TRUE); int increaseNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INCREASENUM_EDIT, NULL, TRUE); + int repeat = ::GetDlgItemInt(_hSelf, IDC_COL_REPEATNUM_EDIT, NULL, TRUE); + if (repeat == 0) + { + repeat = 1; // Without this we might get an infinite loop while calculating the set "numbers" below. + } UCHAR format = getFormat(); display(false); @@ -143,7 +149,7 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) { ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo(); std::sort(colInfos.begin(), colInfos.end(), SortInPositionOrder()); - (*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format); + (*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, repeat, format); std::sort(colInfos.begin(), colInfos.end(), SortInSelectOrder()); (*_ppEditView)->setMultiSelections(colInfos); } @@ -155,6 +161,26 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) int endPos = (*_ppEditView)->execute(SCI_GETLENGTH); int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos); + // Compute the numbers to be placed at each column. + std::vector numbers; + { + int curNumber = initialNumber; + const unsigned int kiMaxSize = 1 + (unsigned int)endLine - (unsigned int)cursorLine; + while (numbers.size() < kiMaxSize) + { + for (int i = 0; i < repeat; i++) + { + numbers.push_back(curNumber); + if (numbers.size() >= kiMaxSize) + { + break; + } + } + curNumber += increaseNumber; + } + } + assert(numbers.size() > 0); + int lineAllocatedLen = 1024; TCHAR *line = new TCHAR[lineAllocatedLen]; @@ -170,8 +196,7 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) else if (f == BASE_02) base = 2; - int nbLine = endLine - cursorLine + 1; - int endNumber = initialNumber + increaseNumber * (nbLine - 1); + int endNumber = *numbers.rbegin(); int nbEnd = getNbDigits(endNumber, base); int nbInit = getNbDigits(initialNumber, base); int nb = max(nbInit, nbEnd); @@ -196,8 +221,7 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) // // Calcule generic_string // - int2str(str, stringSize, initialNumber, base, nb, isZeroLeading); - initialNumber += increaseNumber; + int2str(str, stringSize, numbers.at(i - cursorLine), base, nb, isZeroLeading); if (lineEndCol < cursorCol) { @@ -264,6 +288,8 @@ void ColumnEditorDlg::switchTo(bool toText) ::EnableWindow(hNum, !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INCRNUM_STATIC), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INCREASENUM_EDIT), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_REPEATNUM_STATIC), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_REPEATNUM_EDIT), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_FORMAT_GRP_STATIC), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_DEC_RADIO), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_HEX_RADIO), !toText); diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.rc b/PowerEditor/src/ScitillaComponent/columnEditor.rc index db20a1b1..c0d6b733 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor.rc +++ b/PowerEditor/src/ScitillaComponent/columnEditor.rc @@ -30,14 +30,14 @@ #include "columnEditor_rc.h" -IDD_COLUMNEDIT DIALOGEX 26, 41, 223, 206 +IDD_COLUMNEDIT DIALOGEX 26, 41, 223, 221 STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE CAPTION "Column / Multi-Selection Editor" FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 BEGIN GROUPBOX "Text to Insert",IDC_COL_TEXT_GRP_STATIC,12,10,124,54 - GROUPBOX "Number to Insert",IDC_COL_NUM_GRP_STATIC,12,75,204,119 + GROUPBOX "Number to Insert",IDC_COL_NUM_GRP_STATIC,12,75,204,139 CONTROL "",IDC_COL_TEXT_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP | WS_GROUP,7,10,8,9 CONTROL "",IDC_COL_NUM_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP | WS_GROUP, 7,75,8,9 EDITTEXT IDC_COL_TEXT_EDIT,25,32,97,14,ES_AUTOHSCROLL @@ -46,13 +46,17 @@ BEGIN RTEXT "Increase by :",IDC_COL_INCRNUM_STATIC,16,112,75,8 EDITTEXT IDC_COL_INCREASENUM_EDIT,95,110,38,12,ES_NUMBER - CONTROL "Leading zeros", IDC_COL_LEADZERO_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,140,112,70,10 + + RTEXT "Repeat :",IDC_COL_REPEATNUM_STATIC,16,133,75,8 + EDITTEXT IDC_COL_REPEATNUM_EDIT,95,131,38,12,ES_NUMBER + + CONTROL "Leading zeros", IDC_COL_LEADZERO_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,140,133,70,10 - CONTROL "Dec",IDC_COL_DEC_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,148,50,10 - CONTROL "Hex",IDC_COL_HEX_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,148,50,10 - CONTROL "Oct",IDC_COL_OCT_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,167,50,10 - CONTROL "Bin",IDC_COL_BIN_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,167,50,10 - GROUPBOX "Format",IDC_COL_FORMAT_GRP_STATIC,20,132,188,54,BS_CENTER + CONTROL "Dec",IDC_COL_DEC_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,169,50,10 + CONTROL "Hex",IDC_COL_HEX_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,169,50,10 + CONTROL "Oct",IDC_COL_OCT_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,188,50,10 + CONTROL "Bin",IDC_COL_BIN_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,188,50,10 + GROUPBOX "Format",IDC_COL_FORMAT_GRP_STATIC,20,153,188,54,BS_CENTER DEFPUSHBUTTON "OK",IDOK,145,13,70,14,BS_NOTIFY PUSHBUTTON "Cancel",IDCANCEL,145,36,70,14,BS_NOTIFY END diff --git a/PowerEditor/src/ScitillaComponent/columnEditor_rc.h b/PowerEditor/src/ScitillaComponent/columnEditor_rc.h index 22eeb9e1..82f676b7 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor_rc.h +++ b/PowerEditor/src/ScitillaComponent/columnEditor_rc.h @@ -45,5 +45,7 @@ #define IDC_COL_NUM_GRP_STATIC (IDD_COLUMNEDIT + 13) #define IDC_COL_TEXT_EDIT (IDD_COLUMNEDIT + 14) #define IDC_COL_LEADZERO_CHECK (IDD_COLUMNEDIT + 15) + #define IDC_COL_REPEATNUM_STATIC (IDD_COLUMNEDIT + 16) + #define IDC_COL_REPEATNUM_EDIT (IDD_COLUMNEDIT + 17) #endif// COLUMNEDITOR_RC_H From 014c06c89c528104312df4f7b21674d4bde20951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Fri, 15 May 2015 11:46:39 +0200 Subject: [PATCH 2/3] Remove const. --- .../src/ScitillaComponent/ScintillaEditView.cpp | 10 +++++----- PowerEditor/src/ScitillaComponent/ScintillaEditView.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index ebedefd7..6136466f 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -2587,7 +2587,7 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const TCHAR *str) } } -void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const int kiInitial, const int kiIncr, const int kiRepeat, const UCHAR format) +void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, const UCHAR format) { assert(kiRepeat > 0); @@ -2619,11 +2619,11 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const int kiInitial // Compute the numbers to be placed at each column. std::vector numbers; { - int curNumber = kiInitial; + int curNumber = initial; const unsigned int kiMaxSize = cmi.size(); while(numbers.size() < kiMaxSize) { - for(int i = 0; i < kiRepeat; i++) + for(int i = 0; i < repeat; i++) { numbers.push_back(curNumber); if (numbers.size() >= kiMaxSize) @@ -2631,14 +2631,14 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const int kiInitial break; } } - curNumber += kiIncr; + curNumber += incr; } } assert(numbers.size()> 0); const int kibEnd = getNbDigits(*numbers.rbegin(), base); - const int kibInit = getNbDigits(kiInitial, base); + const int kibInit = getNbDigits(initial, base); const int kib = std::max(kibInit, kibEnd); int totalDiff = 0; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index e5a8cfc0..cc6e3c9d 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -576,7 +576,7 @@ public: ColumnModeInfos getColumnModeSelectInfo(); void columnReplace(ColumnModeInfos & cmi, const TCHAR *str); - void columnReplace(ColumnModeInfos & cmi, const int initial, const int incr, const int repeat, const UCHAR format); + void columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, UCHAR format); void foldChanged(int line, int levelNow, int levelPrev); void clearIndicator(int indicatorNumber) { From 98cafadc3f3515aaf91630d84deb1105558a5507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Fri, 15 May 2015 11:49:42 +0200 Subject: [PATCH 3/3] Remove const. --- PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 6136466f..3683bb26 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -2587,9 +2587,9 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, const TCHAR *str) } } -void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, const UCHAR format) +void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, UCHAR format) { - assert(kiRepeat > 0); + assert(repeat > 0); // 0000 00 00 : Dec BASE_10 // 0000 00 01 : Hex BASE_16