From ef6f609fb2e7a2a0763cc2abe56000b48b68f37c Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 19 Jul 2020 02:12:35 +0200 Subject: [PATCH 1/5] Add commented debug defines to diagnostics component --- addons/diagnostic/script_component.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/diagnostic/script_component.hpp b/addons/diagnostic/script_component.hpp index b85aea835..3282a4ebb 100644 --- a/addons/diagnostic/script_component.hpp +++ b/addons/diagnostic/script_component.hpp @@ -1,6 +1,9 @@ #define COMPONENT diagnostic #include "\x\cba\addons\main\script_mod.hpp" +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE + #ifdef DEBUG_ENABLED_DIAGNOSTIC #define DEBUG_MODE_FULL #endif From d5dad38a8638af768bc8178d24248219acfc7018 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 19 Jul 2020 03:27:21 +0200 Subject: [PATCH 2/5] Add Tab support for indentation in debug console --- .../fnc_initExtendedDebugConsole.sqf | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf index ccfe61395..3089f6d1f 100644 --- a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf +++ b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf @@ -2,6 +2,7 @@ #include "script_component.hpp" #define MAX_STATEMENTS 50 +#define INDENT_SPACES " " params ["_display"]; @@ -63,6 +64,43 @@ _expression ctrlAddEventHandler ["KeyDown", { _this call FUNC(logStatement); }; + + if (_key isEqualTo DIK_TAB) then { + _expression setVariable [QGVAR(tabDown), true]; + }; + + false +}]; + +// Reset Tab status on autocomplete +_expression ctrlAddEventHandler ["KeyUp", { + params ["_expression", "_key"]; + + if (_key isEqualTo DIK_TAB) then { + _expression setVariable [QGVAR(tabDown), false]; + }; +}]; + +// Tab without autocomplete will move focus to another control, add whitespace +_expression ctrlAddEventHandler ["KillFocus", { + params ["_expression"]; + + if (_expression getVariable [QGVAR(tabDown), false]) then { + _expression setVariable [QGVAR(tabDown), false]; + + (ctrlTextSelection _expression) params ["_selStart", "_selLength"]; + private _text = ctrlText _expression; + + // replace selection with whitespace + _expression ctrlSetText ([_text select [0, _selStart], _text select [_selStart + _selLength, count _text - 1]] joinString INDENT_SPACES); + _expression ctrlSetTextSelection [_selStart + 4, 0]; + + // change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor + _expression spawn { + ctrlSetFocus _this; + }; + }; + false }]; From 55a7d5af78c79871b4903a4930e9a2529db89334 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 19 Jul 2020 18:33:30 +0200 Subject: [PATCH 3/5] Add whitespace removal with Shift+Tab, add settings for indentation --- addons/diagnostic/XEH_preInit.sqf | 1 + .../fnc_initExtendedDebugConsole.sqf | 61 ++++++++++++++++--- addons/diagnostic/initSettings.sqf | 12 ++++ addons/diagnostic/script_component.hpp | 3 + addons/diagnostic/stringtable.xml | 16 +++++ 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 addons/diagnostic/initSettings.sqf diff --git a/addons/diagnostic/XEH_preInit.sqf b/addons/diagnostic/XEH_preInit.sqf index 56401bb0e..b66a11199 100644 --- a/addons/diagnostic/XEH_preInit.sqf +++ b/addons/diagnostic/XEH_preInit.sqf @@ -6,6 +6,7 @@ LOG(MSG_INIT); ADDON = false; #include "XEH_PREP.sqf" +#include "initSettings.sqf"; [QGVAR(debug), {_this call CBA_fnc_debug}] call CBA_fnc_addEventHandler; diff --git a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf index 3089f6d1f..e4c3117fc 100644 --- a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf +++ b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf @@ -3,6 +3,7 @@ #define MAX_STATEMENTS 50 #define INDENT_SPACES " " +#define INDENT_TAB (toString [ASCII_TAB]) params ["_display"]; @@ -66,7 +67,7 @@ _expression ctrlAddEventHandler ["KeyDown", { }; if (_key isEqualTo DIK_TAB) then { - _expression setVariable [QGVAR(tabDown), true]; + _expression setVariable [QGVAR(tabKey), [true, _shift]]; }; false @@ -77,7 +78,7 @@ _expression ctrlAddEventHandler ["KeyUp", { params ["_expression", "_key"]; if (_key isEqualTo DIK_TAB) then { - _expression setVariable [QGVAR(tabDown), false]; + _expression setVariable [QGVAR(tabKey), nil]; }; }]; @@ -85,15 +86,17 @@ _expression ctrlAddEventHandler ["KeyUp", { _expression ctrlAddEventHandler ["KillFocus", { params ["_expression"]; - if (_expression getVariable [QGVAR(tabDown), false]) then { - _expression setVariable [QGVAR(tabDown), false]; + if (GVAR(ConsoleIndentType) == -1) exitWith {}; + private _tabKey = _expression getVariable [QGVAR(tabKey), [false, false]]; + if (_tabKey isEqualTo [true, false]) then { (ctrlTextSelection _expression) params ["_selStart", "_selLength"]; private _text = ctrlText _expression; // replace selection with whitespace - _expression ctrlSetText ([_text select [0, _selStart], _text select [_selStart + _selLength, count _text - 1]] joinString INDENT_SPACES); - _expression ctrlSetTextSelection [_selStart + 4, 0]; + private _indentType = [INDENT_SPACES, INDENT_TAB] select GVAR(ConsoleIndentType); + _expression ctrlSetText ([_text select [0, _selStart], _text select [_selStart + _selLength, count _text - 1]] joinString _indentType); + _expression ctrlSetTextSelection [_selStart + count _indentType, 0]; // change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor _expression spawn { @@ -101,7 +104,20 @@ _expression ctrlAddEventHandler ["KillFocus", { }; }; - false + if (_tabKey isEqualTo [true, true]) then { + (ctrlTextSelection _expression) params ["_selStart"]; + private _text = ctrlText _expression; + + [_expression, _text, _selStart] call FUNC(removeIndentation); + + // change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor + _expression spawn { + ctrlSetFocus _this; + }; + + }; + + _expression setVariable [QGVAR(tabDown), nil]; }]; private _expressionBackground = _display displayCtrl IDC_RSCDEBUGCONSOLE_EXPRESSIONBACKGROUND; @@ -257,6 +273,37 @@ FUNC(nextStatement) = { _nextButton ctrlEnable (_statementIndex > 0); }; +FUNC(removeIndentation) = { + params ["_control", "_text", "_index"]; + + private _chars = toArray _text; + private _indexRev = count _chars - _index; + + reverse _chars; + + private _stepBack = 0; + // whitespace type to remove + private _whitespace = [ASCII_SPACE, ASCII_TAB]; + { + if !(_x in _whitespace) exitWith {}; + // do not remove mixed whitespace types + _whitespace = [_x]; + + _chars set [_indexRev + _forEachIndex, -1]; + INC(_stepBack); + + // remove only one Tab + if (_x == ASCII_TAB) exitWith {}; + } forEach (_chars select [_indexRev, count INDENT_SPACES]); + + _chars = _chars - [-1]; + + reverse _chars; + + _expression ctrlSetText toString _chars; + _expression ctrlSetTextSelection [_index - _stepBack, 0]; +}; + // remove forced pause for watch fields { (_display displayCtrl _x) ctrlAddEventHandler ["SetFocus", { diff --git a/addons/diagnostic/initSettings.sqf b/addons/diagnostic/initSettings.sqf new file mode 100644 index 000000000..3655c71f8 --- /dev/null +++ b/addons/diagnostic/initSettings.sqf @@ -0,0 +1,12 @@ + +[ + QGVAR(ConsoleIndentType), "LIST", + [LLSTRING(ConsoleIndentType), LLSTRING(ConsoleIndentTypeTooltip)], + LELSTRING(Ui,Category), + [ + [-1, 0, 1], + [localize "STR_A3_OPTIONS_DISABLED", LLSTRING(ConsoleIndentSpaces), LLSTRING(ConsoleIndentTab)], + 0 + ], + 2 +] call CBA_fnc_addSetting; diff --git a/addons/diagnostic/script_component.hpp b/addons/diagnostic/script_component.hpp index 3282a4ebb..4b43fb2dc 100644 --- a/addons/diagnostic/script_component.hpp +++ b/addons/diagnostic/script_component.hpp @@ -21,3 +21,6 @@ #define IDC_DEBUGCONSOLE_PREV 90110 #define IDC_DEBUGCONSOLE_NEXT 90111 + +#define ASCII_TAB 9 +#define ASCII_SPACE 32 diff --git a/addons/diagnostic/stringtable.xml b/addons/diagnostic/stringtable.xml index 0fc507f54..654293e22 100644 --- a/addons/diagnostic/stringtable.xml +++ b/addons/diagnostic/stringtable.xml @@ -92,5 +92,21 @@ [CBA] Abilita il debug remoto. Richiede la console di debug. [CBA] Povoluje ladění vzdáleného cíle. Vyžaduje ladící konzoli. + + Debug console indentation + Indentacja w konsoli debugowania + + + Type of indentation that can be added to expression in the debug console by pressing Tab key or removed by pressing Shift + Tab. + Rodzaj indentacji która może być dodana do wyrażenia w konsoli debugowania za pomocą klawisza Tab lub usunięta za pomocą Shift + Tab. + + + 4 Spaces + 4 Spacje + + + Tab + Tab + From 7279403dee4bc81cff01a2776d091692acb88e6a Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 19 Jul 2020 18:36:13 +0200 Subject: [PATCH 4/5] Remove Tab indentation type Does not work well, tab has width of 1 space in the edit box, also tabs are replaced with 4 spaces when pasted into debug console. --- addons/diagnostic/fnc_initExtendedDebugConsole.sqf | 1 - addons/diagnostic/initSettings.sqf | 4 ++-- addons/diagnostic/stringtable.xml | 4 ---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf index e4c3117fc..93eaa575e 100644 --- a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf +++ b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf @@ -3,7 +3,6 @@ #define MAX_STATEMENTS 50 #define INDENT_SPACES " " -#define INDENT_TAB (toString [ASCII_TAB]) params ["_display"]; diff --git a/addons/diagnostic/initSettings.sqf b/addons/diagnostic/initSettings.sqf index 3655c71f8..ad835950c 100644 --- a/addons/diagnostic/initSettings.sqf +++ b/addons/diagnostic/initSettings.sqf @@ -4,8 +4,8 @@ [LLSTRING(ConsoleIndentType), LLSTRING(ConsoleIndentTypeTooltip)], LELSTRING(Ui,Category), [ - [-1, 0, 1], - [localize "STR_A3_OPTIONS_DISABLED", LLSTRING(ConsoleIndentSpaces), LLSTRING(ConsoleIndentTab)], + [-1, 0], + [localize "STR_A3_OPTIONS_DISABLED", LLSTRING(ConsoleIndentSpaces)], 0 ], 2 diff --git a/addons/diagnostic/stringtable.xml b/addons/diagnostic/stringtable.xml index 654293e22..016d5b7ce 100644 --- a/addons/diagnostic/stringtable.xml +++ b/addons/diagnostic/stringtable.xml @@ -104,9 +104,5 @@ 4 Spaces 4 Spacje - - Tab - Tab - From 70753df3bd2f4a3a7a68816b268e5458bc8b86c5 Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Mon, 20 Jul 2020 16:23:38 +0200 Subject: [PATCH 5/5] Remove Tab indentation leftovers --- addons/diagnostic/fnc_initExtendedDebugConsole.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf index 93eaa575e..ad7839e11 100644 --- a/addons/diagnostic/fnc_initExtendedDebugConsole.sqf +++ b/addons/diagnostic/fnc_initExtendedDebugConsole.sqf @@ -93,7 +93,7 @@ _expression ctrlAddEventHandler ["KillFocus", { private _text = ctrlText _expression; // replace selection with whitespace - private _indentType = [INDENT_SPACES, INDENT_TAB] select GVAR(ConsoleIndentType); + private _indentType = [INDENT_SPACES] select GVAR(ConsoleIndentType); _expression ctrlSetText ([_text select [0, _selStart], _text select [_selStart + _selLength, count _text - 1]] joinString _indentType); _expression ctrlSetTextSelection [_selStart + count _indentType, 0];