diff --git a/language/common_res.h b/language/common_res.h index 587065b16..df8f0cac9 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -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 diff --git a/language/np3_de_de/menu_de_de.rc b/language/np3_de_de/menu_de_de.rc index 6df7a085a..d3d4d7025 100644 --- a/language/np3_de_de/menu_de_de.rc +++ b/language/np3_de_de/menu_de_de.rc @@ -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 diff --git a/language/np3_en_us/menu_en_us.rc b/language/np3_en_us/menu_en_us.rc index 15f7d1588..7a4afe107 100644 --- a/language/np3_en_us/menu_en_us.rc +++ b/language/np3_en_us/menu_en_us.rc @@ -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 diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index b07665a33..f4aa9d105 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -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); diff --git a/src/Notepad3.c b/src/Notepad3.c index 2edaefdfc..bc5b87f3d 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -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) diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 6b21697e1..c05d9924a 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -427,6 +427,7 @@ typedef struct _settings_t int PrintColorMode; int PrintZoom; bool SaveBeforeRunningTools; + bool EvalTinyExprOnSelection; FILE_WATCHING_MODE FileWatchingMode; bool ResetFileWatching; int EscFunction; diff --git a/tinyexpr/tinyexpr.c b/tinyexpr/tinyexpr.c index 9c3b5526d..8b5c6fcaf 100644 --- a/tinyexpr/tinyexpr.c +++ b/tinyexpr/tinyexpr.c @@ -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; }