Merge pull request #46 from andreas-jonsson/repeat

[ENHANCEMENT] Add "repeat" option to column editor.
This commit is contained in:
Don HO 2015-05-24 18:40:04 +02:00
commit e70eb054b0
5 changed files with 80 additions and 26 deletions

View File

@ -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, int initial, int incr, int repeat, UCHAR format)
{
assert(repeat > 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<int> numbers;
{
int curNumber = initial;
const unsigned int kiMaxSize = cmi.size();
while(numbers.size() < kiMaxSize)
{
for(int i = 0; i < repeat; i++)
{
numbers.push_back(curNumber);
if (numbers.size() >= kiMaxSize)
{
break;
}
}
curNumber += incr;
}
}
assert(numbers.size()> 0);
const int kibEnd = getNbDigits(*numbers.rbegin(), base);
const int kibInit = getNbDigits(initial, base);
const int kib = std::max<int>(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);

View File

@ -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, int initial, int incr, int repeat, UCHAR format);
void foldChanged(int line, int levelNow, int levelPrev);
void clearIndicator(int indicatorNumber) {

View File

@ -29,6 +29,7 @@
#include "precompiledHeaders.h"
#include "columnEditor.h"
#include "ScintillaEditView.h"
#include <vector>
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<int> 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);

View File

@ -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
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
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,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

View File

@ -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