+ add: make TinyExpr evaluation optional (menu -> settings)

This commit is contained in:
RaiKoHoff 2020-07-21 18:06:59 +02:00
parent aba6caf489
commit 36006eb7f0
7 changed files with 35 additions and 20 deletions

View File

@ -653,6 +653,7 @@
#define IDM_VIEW_SHOW_HYPLNK_CALLTIP 40472
#define IDM_VIEW_SPLIT_UNDOTYPSEQ_LNBRK 40473
#define IDM_VIEW_EDIT_LINECOMMENT 40474
#define IDM_VIEW_EVALTINYEXPRONSEL 40475
#define IDM_SET_RENDER_TECH_DEFAULT 40500
#define IDM_SET_RENDER_TECH_D2D 40501

View File

@ -428,6 +428,7 @@ BEGIN
MENUITEM "&Verlasse Notepad3", IDM_VIEW_ESCEXIT
END
MENUITEM "Speichern vor Werkzeug Start", IDM_VIEW_SAVEBEFORERUNNINGTOOLS
MENUITEM "Berechne Tiny-Expressions", IDM_VIEW_EVALTINYEXPRONSEL
MENUITEM SEPARATOR
POPUP "&Erinnern an"
BEGIN

View File

@ -428,6 +428,7 @@ BEGIN
MENUITEM "E&xit Notepad3", IDM_VIEW_ESCEXIT
END
MENUITEM "Save &Before Running Tools", IDM_VIEW_SAVEBEFORERUNNINGTOOLS
MENUITEM "Calculate Tiny-E&xpressions", IDM_VIEW_EVALTINYEXPRONSEL
MENUITEM SEPARATOR
POPUP "&Remember"
BEGIN

View File

@ -1444,7 +1444,9 @@ void LoadSettings()
Settings.PrintMargin.bottom = clampi(IniSectionGetInt(IniSecSettings, L"PrintMarginBottom", Defaults.PrintMargin.bottom), 0, 40000);
GET_BOOL_VALUE_FROM_INISECTION(SaveBeforeRunningTools, false);
GET_CAST_INT_VALUE_FROM_INISECTION(FILE_WATCHING_MODE, FileWatchingMode, FWM_DONT_CARE, FWM_DONT_CARE, FWM_AUTORELOAD); FileWatching.FileWatchingMode = Settings.FileWatchingMode;
GET_BOOL_VALUE_FROM_INISECTION(EvalTinyExprOnSelection, true);
GET_CAST_INT_VALUE_FROM_INISECTION(FILE_WATCHING_MODE, FileWatchingMode, FWM_DONT_CARE, FWM_DONT_CARE, FWM_AUTORELOAD);
FileWatching.FileWatchingMode = Settings.FileWatchingMode;
GET_BOOL_VALUE_FROM_INISECTION(ResetFileWatching, true); FileWatching.ResetFileWatching = Settings.ResetFileWatching;
GET_INT_VALUE_FROM_INISECTION(EscFunction, 0, 0, 2);
GET_BOOL_VALUE_FROM_INISECTION(AlwaysOnTop, false);
@ -1879,6 +1881,7 @@ static bool _SaveSettings(bool bForceSaveSettings)
IniSectionDelete(IniSecSettings, L"PrintMarginBottom", false);
}
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveBeforeRunningTools);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, EvalTinyExprOnSelection);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileWatchingMode);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ResetFileWatching);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EscFunction);

View File

@ -3477,6 +3477,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
CheckCmd(hmenu, IDM_VIEW_NOSAVEFINDREPL, Settings.SaveFindReplace);
EnableCmd(hmenu, IDM_VIEW_NOSAVEFINDREPL, sav);
CheckCmd(hmenu, IDM_VIEW_SAVEBEFORERUNNINGTOOLS, Settings.SaveBeforeRunningTools);
CheckCmd(hmenu, IDM_VIEW_EVALTINYEXPRONSEL, Settings.EvalTinyExprOnSelection);
EnableCmd(hmenu, IDM_VIEW_SAVEBEFORERUNNINGTOOLS, sav);
CheckCmd(hmenu, IDM_VIEW_CHANGENOTIFY, Settings.FileWatchingMode);
@ -5512,6 +5513,11 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
Settings.SaveBeforeRunningTools = !Settings.SaveBeforeRunningTools;
break;
case IDM_VIEW_EVALTINYEXPRONSEL:
Settings.EvalTinyExprOnSelection = !Settings.EvalTinyExprOnSelection;
UpdateStatusbar(false);
break;
case IDM_VIEW_CHANGENOTIFY:
if (ChangeNotifyDlg(hwnd)) {
InstallFileWatching(Globals.CurrentFile);
@ -8524,28 +8530,31 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw)
tchExpression[1] = L'-';
tchExpression[2] = L'\0';
if (bIsSelCharCountable)
if (Settings.EvalTinyExprOnSelection)
{
static char chSelectionBuffer[XHUGE_BUFFER];
DocPos const iSelSize = SciCall_GetSelText(NULL);
if (iSelSize < COUNTOF(chSelectionBuffer)) // should be fast !
{
SciCall_GetSelText(chSelectionBuffer);
//~StrDelChrA(chExpression, " \r\n\t\v");
StrDelChrA(chSelectionBuffer, "\r\n");
s_dExpression = te_interp(chSelectionBuffer, &s_iExprError);
if (bIsSelCharCountable) {
static char chSelectionBuffer[XHUGE_BUFFER];
DocPos const iSelSize = SciCall_GetSelText(NULL);
if (iSelSize < COUNTOF(chSelectionBuffer)) // should be fast !
{
SciCall_GetSelText(chSelectionBuffer);
//~StrDelChrA(chExpression, " \r\n\t\v");
StrDelChrA(chSelectionBuffer, "\r\n");
s_dExpression = te_interp(chSelectionBuffer, &s_iExprError);
}
else {
s_iExprError = -1;
}
}
else {
s_iExprError = -1;
else if (Sci_IsMultiOrRectangleSelection() && !bIsSelectionEmpty) {
s_dExpression = _InterpMultiSelectionTinyExpr(&s_iExprError);
}
else
s_iExprError = -2;
}
else if (Sci_IsMultiOrRectangleSelection() && !bIsSelectionEmpty)
{
s_dExpression = _InterpMultiSelectionTinyExpr(&s_iExprError);
else {
s_iExprError = -3;
}
else
s_iExprError = -2;
if (!s_iExprError) {
if (fabs(s_dExpression) > 99999999.9999)

View File

@ -427,6 +427,7 @@ typedef struct _settings_t
int PrintColorMode;
int PrintZoom;
bool SaveBeforeRunningTools;
bool EvalTinyExprOnSelection;
FILE_WATCHING_MODE FileWatchingMode;
bool ResetFileWatching;
int EscFunction;

View File

@ -332,7 +332,7 @@ static const te_variable functions[] = {
static const te_variable *find_builtin(const char *name, size_t len) {
int imin = 0;
int imax = COUNTOF(functions) - 1;
int imax = COUNTOF(functions) - 2;
/*Binary search.*/
while (imax >= imin) {
@ -347,7 +347,6 @@ static const te_variable *find_builtin(const char *name, size_t len) {
imax = i - 1;
}
}
return 0;
}