Skip to content

Commit

Permalink
Merge pull request #1357 from CBATeam/debug-console-tab-indent
Browse files Browse the repository at this point in the history
Diagnostics - Add indentation in debug console with Tab
  • Loading branch information
PabstMirror committed Jan 20, 2021
2 parents 039f236 + 70753df commit 1a70c0e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/diagnostic/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
84 changes: 84 additions & 0 deletions addons/diagnostic/fnc_initExtendedDebugConsole.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "script_component.hpp"

#define MAX_STATEMENTS 50
#define INDENT_SPACES " "

params ["_display"];

Expand Down Expand Up @@ -63,9 +64,61 @@ _expression ctrlAddEventHandler ["KeyDown", {

_this call FUNC(logStatement);
};

if (_key isEqualTo DIK_TAB) then {
_expression setVariable [QGVAR(tabKey), [true, _shift]];
};

false
}];

// Reset Tab status on autocomplete
_expression ctrlAddEventHandler ["KeyUp", {
params ["_expression", "_key"];

if (_key isEqualTo DIK_TAB) then {
_expression setVariable [QGVAR(tabKey), nil];
};
}];

// Tab without autocomplete will move focus to another control, add whitespace
_expression ctrlAddEventHandler ["KillFocus", {
params ["_expression"];

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
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];

// change focus on next frame, using spawn as CBA_fnc_execNextFrame will not work in editor
_expression spawn {
ctrlSetFocus _this;
};
};

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;

_position = ctrlPosition _expressionBackground;
Expand Down Expand Up @@ -219,6 +272,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", {
Expand Down
12 changes: 12 additions & 0 deletions addons/diagnostic/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[
QGVAR(ConsoleIndentType), "LIST",
[LLSTRING(ConsoleIndentType), LLSTRING(ConsoleIndentTypeTooltip)],
LELSTRING(Ui,Category),
[
[-1, 0],
[localize "STR_A3_OPTIONS_DISABLED", LLSTRING(ConsoleIndentSpaces)],
0
],
2
] call CBA_fnc_addSetting;
6 changes: 6 additions & 0 deletions addons/diagnostic/script_component.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,3 +21,6 @@

#define IDC_DEBUGCONSOLE_PREV 90110
#define IDC_DEBUGCONSOLE_NEXT 90111

#define ASCII_TAB 9
#define ASCII_SPACE 32
12 changes: 12 additions & 0 deletions addons/diagnostic/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,17 @@
<Italian>[CBA] Abilita il debug remoto. Richiede la console di debug.</Italian>
<Czech>[CBA] Povoluje ladění vzdáleného cíle. Vyžaduje ladící konzoli.</Czech>
</Key>
<Key ID="STR_CBA_Diagnostic_ConsoleIndentType">
<English>Debug console indentation</English>
<Polish>Indentacja w konsoli debugowania</Polish>
</Key>
<Key ID="STR_CBA_Diagnostic_ConsoleIndentTypeTooltip">
<English>Type of indentation that can be added to expression in the debug console by pressing Tab key or removed by pressing Shift + Tab.</English>
<Polish>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.</Polish>
</Key>
<Key ID="STR_CBA_Diagnostic_ConsoleIndentSpaces">
<English>4 Spaces</English>
<Polish>4 Spacje</Polish>
</Key>
</Package>
</Project>

0 comments on commit 1a70c0e

Please sign in to comment.