[NEW_FEATURE] Make column editor work in multi-selection mode.
[BUG_FIXED] Fix column editor inserting octal number broken issue. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@537 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
2b9ddf1816
commit
6a022cdb9a
@ -40,6 +40,7 @@
|
||||
#define generic_fopen _wfopen
|
||||
#define generic_fgets fgetws
|
||||
#define generic_stat _wstat
|
||||
#define generic_sprintf swprintf
|
||||
#define COPYDATA_FILENAMES COPYDATA_FILENAMESW
|
||||
#else
|
||||
#define NppMainEntry WinMain
|
||||
@ -60,6 +61,7 @@
|
||||
#define generic_fopen fopen
|
||||
#define generic_fgets fgets
|
||||
#define generic_stat _stat
|
||||
#define generic_sprintf sprintf
|
||||
#define COPYDATA_FILENAMES COPYDATA_FILENAMESA
|
||||
#endif
|
||||
|
||||
|
@ -2299,8 +2299,10 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(f, TEXT("%%%s"), fStr);
|
||||
wsprintf(str, f, number);
|
||||
// use sprintf or swprintf instead of wsprintf
|
||||
// to make octal format work
|
||||
generic_sprintf(f, TEXT("%%%s"), fStr);
|
||||
generic_sprintf(str, f, number);
|
||||
}
|
||||
int i = lstrlen(str);
|
||||
for ( ; i < nbChiffre ; i++)
|
||||
@ -2311,8 +2313,10 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo
|
||||
{
|
||||
if (base != 2)
|
||||
{
|
||||
wsprintf(f, TEXT("%%.%d%s"), nbChiffre, fStr);
|
||||
wsprintf(str, f, number);
|
||||
// use sprintf or swprintf instead of wsprintf
|
||||
// to make octal format work
|
||||
generic_sprintf(f, TEXT("%%.%d%s"), nbChiffre, fStr);
|
||||
generic_sprintf(str, f, number);
|
||||
}
|
||||
// else already done.
|
||||
}
|
||||
|
@ -154,11 +154,24 @@ struct ColumnModeInfo {
|
||||
bool isValid() const {
|
||||
return (_order >= 0 && _selLpos >= 0 && _selRpos >= 0 && _selLpos <= _selRpos);
|
||||
};
|
||||
/*
|
||||
bool hasVirtualSpace() const {
|
||||
return (_nbVirtualCaretSpc >= 0 && _nbVirtualAnchorSpc >= 0);
|
||||
};
|
||||
*/
|
||||
};
|
||||
|
||||
//
|
||||
// SortClass for vector<ColumnModeInfo>
|
||||
// sort in _order : increased order
|
||||
struct SortInSelectOrder {
|
||||
bool operator() (ColumnModeInfo & l, ColumnModeInfo & r) {
|
||||
return (l._order < r._order);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// SortClass for vector<ColumnModeInfo>
|
||||
// sort in _selLpos : increased order
|
||||
struct SortInPositionOrder {
|
||||
bool operator() (ColumnModeInfo & l, ColumnModeInfo & r) {
|
||||
return (l._selLpos < r._selLpos);
|
||||
}
|
||||
};
|
||||
|
||||
typedef vector<ColumnModeInfo> ColumnModeInfos;
|
||||
|
@ -20,214 +20,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#include "columnEditor.h"
|
||||
#include "ScintillaEditView.h"
|
||||
|
||||
/*
|
||||
BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG :
|
||||
{
|
||||
switchTo(activeText);
|
||||
::SendDlgItemMessage(_hSelf, IDC_COL_DEC_RADIO, BM_SETCHECK, TRUE, 0);
|
||||
goToCenter();
|
||||
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture();
|
||||
if (enableDlgTheme)
|
||||
{
|
||||
enableDlgTheme(_hSelf, ETDT_ENABLETAB);
|
||||
redraw();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
case WM_COMMAND :
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case IDCANCEL : // Close
|
||||
display(false);
|
||||
return TRUE;
|
||||
|
||||
case IDOK :
|
||||
{
|
||||
(*_ppEditView)->execute(SCI_BEGINUNDOACTION);
|
||||
|
||||
const int stringSize = 1024;
|
||||
TCHAR str[stringSize];
|
||||
|
||||
bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0));
|
||||
|
||||
if (isTextMode)
|
||||
{
|
||||
::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, stringSize, (LPARAM)str);
|
||||
|
||||
display(false);
|
||||
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE))
|
||||
{
|
||||
ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
|
||||
(*_ppEditView)->columnReplace(colInfos, str);
|
||||
(*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS);
|
||||
int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos);
|
||||
int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos);
|
||||
int endPos = (*_ppEditView)->execute(SCI_GETLENGTH);
|
||||
int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos);
|
||||
|
||||
int lineAllocatedLen = 1024;
|
||||
TCHAR *line = new TCHAR[lineAllocatedLen];
|
||||
|
||||
for (int i = cursorLine ; i <= endLine ; i++)
|
||||
{
|
||||
int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i);
|
||||
int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i);
|
||||
|
||||
int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd);
|
||||
int lineLen = lineEnd - lineBegin + 1;
|
||||
|
||||
if (lineLen > lineAllocatedLen)
|
||||
{
|
||||
delete [] line;
|
||||
line = new TCHAR[lineLen];
|
||||
}
|
||||
(*_ppEditView)->getGenericText(line, lineBegin, lineEnd);
|
||||
generic_string s2r(line);
|
||||
|
||||
if (lineEndCol < cursorCol)
|
||||
{
|
||||
generic_string s_space(cursorCol - lineEndCol, ' ');
|
||||
s2r.append(s_space);
|
||||
s2r.append(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol);
|
||||
int posRelative2Start = posAbs2Start - lineBegin;
|
||||
s2r.insert(posRelative2Start, str);
|
||||
}
|
||||
(*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd);
|
||||
}
|
||||
delete [] line;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int initialNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INITNUM_EDIT, NULL, TRUE);
|
||||
int increaseNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INCREASENUM_EDIT, NULL, TRUE);
|
||||
UCHAR format = getFormat();
|
||||
display(false);
|
||||
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE))
|
||||
{
|
||||
ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
|
||||
(*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format);
|
||||
(*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS);
|
||||
int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos);
|
||||
int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos);
|
||||
int endPos = (*_ppEditView)->execute(SCI_GETLENGTH);
|
||||
int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos);
|
||||
|
||||
int lineAllocatedLen = 1024;
|
||||
TCHAR *line = new TCHAR[lineAllocatedLen];
|
||||
|
||||
|
||||
UCHAR f = format & MASK_FORMAT;
|
||||
bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0;
|
||||
|
||||
int base = 10;
|
||||
if (f == BASE_16)
|
||||
base = 16;
|
||||
else if (f == BASE_08)
|
||||
base = 8;
|
||||
else if (f == BASE_02)
|
||||
base = 2;
|
||||
|
||||
int nbLine = endLine - cursorLine + 1;
|
||||
int endNumber = initialNumber + increaseNumber * (nbLine - 1);
|
||||
int nbEnd = getNbDigits(endNumber, base);
|
||||
int nbInit = getNbDigits(initialNumber, base);
|
||||
int nb = max(nbInit, nbEnd);
|
||||
|
||||
|
||||
for (int i = cursorLine ; i <= endLine ; i++)
|
||||
{
|
||||
int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i);
|
||||
int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i);
|
||||
|
||||
int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd);
|
||||
int lineLen = lineEnd - lineBegin + 1;
|
||||
|
||||
if (lineLen > lineAllocatedLen)
|
||||
{
|
||||
delete [] line;
|
||||
line = new TCHAR[lineLen];
|
||||
}
|
||||
(*_ppEditView)->getGenericText(line, lineBegin, lineEnd);
|
||||
generic_string s2r(line);
|
||||
|
||||
|
||||
//Calcule generic_string
|
||||
int2str(str, stringSize, initialNumber, base, nb, isZeroLeading);
|
||||
initialNumber += increaseNumber;
|
||||
|
||||
if (lineEndCol < cursorCol)
|
||||
{
|
||||
generic_string s_space(cursorCol - lineEndCol, ' ');
|
||||
s2r.append(s_space);
|
||||
s2r.append(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol);
|
||||
int posRelative2Start = posAbs2Start - lineBegin;
|
||||
s2r.insert(posRelative2Start, str);
|
||||
}
|
||||
|
||||
(*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd);
|
||||
}
|
||||
delete [] line;
|
||||
}
|
||||
}
|
||||
(*_ppEditView)->execute(SCI_ENDUNDOACTION);
|
||||
(*_ppEditView)->getFocus();
|
||||
return TRUE;
|
||||
}
|
||||
case IDC_COL_TEXT_RADIO :
|
||||
case IDC_COL_NUM_RADIO :
|
||||
{
|
||||
switchTo((wParam == IDC_COL_TEXT_RADIO)? activeText : activeNumeric);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
default :
|
||||
{
|
||||
switch (HIWORD(wParam))
|
||||
{
|
||||
case EN_SETFOCUS :
|
||||
case BN_SETFOCUS :
|
||||
//updateLinesNumbers();
|
||||
return TRUE;
|
||||
default :
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default :
|
||||
return FALSE;
|
||||
}
|
||||
//return FALSE;
|
||||
}
|
||||
*/
|
||||
|
||||
void ColumnEditorDlg::display(bool toShow) const
|
||||
{
|
||||
@ -278,10 +70,12 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
|
||||
|
||||
display(false);
|
||||
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE))
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE) || (*_ppEditView)->execute(SCI_GETSELECTIONS) > 1)
|
||||
{
|
||||
ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
|
||||
std::sort(colInfos.begin(), colInfos.end(), SortInPositionOrder());
|
||||
(*_ppEditView)->columnReplace(colInfos, str);
|
||||
std::sort(colInfos.begin(), colInfos.end(), SortInSelectOrder());
|
||||
(*_ppEditView)->setMultiSelections(colInfos);
|
||||
}
|
||||
else
|
||||
@ -335,11 +129,12 @@ BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
|
||||
UCHAR format = getFormat();
|
||||
display(false);
|
||||
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE))
|
||||
if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE) || (*_ppEditView)->execute(SCI_GETSELECTIONS) > 1)
|
||||
{
|
||||
ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
|
||||
std::sort(colInfos.begin(), colInfos.end(), SortInPositionOrder());
|
||||
(*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format);
|
||||
//(*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1]._selRpos);
|
||||
std::sort(colInfos.begin(), colInfos.end(), SortInSelectOrder());
|
||||
(*_ppEditView)->setMultiSelections(colInfos);
|
||||
}
|
||||
else
|
||||
|
@ -24,7 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
IDD_COLUMNEDIT DIALOGEX 26, 41, 223, 206
|
||||
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE
|
||||
CAPTION "Column Editor"
|
||||
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
|
||||
|
@ -91,8 +91,8 @@ BEGIN
|
||||
CONTROL "",IDC_CARETBLINKRATE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,161,29,67,13
|
||||
LTEXT "S",IDC_CARETBLINKRATE_S_STATIC,230,29,12,8
|
||||
LTEXT "F",IDC_CARETBLINKRATE_F_STATIC,149,29,12,8,0,WS_EX_RIGHT
|
||||
GROUPBOX "Multi-Editing Setting",IDC_MULTISELECTION_GB_STATIC,258,5,130,40,BS_CENTER
|
||||
CONTROL "Enable (Ctrl + Mouse click/selection)",IDC_CHECK_MULTISELECTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,276,22,100,10
|
||||
GROUPBOX "Multi-Editing Setting",IDC_MULTISELECTION_GB_STATIC,258,5,140,40,BS_CENTER
|
||||
CONTROL "Enable (Ctrl+Mouse click/selection)",IDC_CHECK_MULTISELECTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,266,22,130,10
|
||||
|
||||
END
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user