16#ifndef LUA_DEBUGGER_CODE_EDITOR_H
17#define LUA_DEBUGGER_CODE_EDITOR_H
22#include <QPlainTextEdit>
23#include <QRegularExpression>
25#include <QSyntaxHighlighter>
26#include <QTextCharFormat>
33class QContextMenuEvent;
36class QStandardItemModel;
37class QSyntaxHighlighter;
55 QColor editorBackground;
60 QColor gutterBackground;
100 QRegularExpression pattern;
101 QTextCharFormat format;
104 QVector<Rule> rules_;
105 QTextCharFormat stringFormat_;
106 QTextCharFormat commentFormat_;
107 QRegularExpression singleLineComment_;
110 bool highlightLongBlock(
const QString &text,
bool isComment,
bool continuingPrevious, qint32 eqCountFromState,
111 qint32 &nextStateEqCount);
113 qint32 findLongBlockStart(
const QString &text, qint32 from,
bool isComment, qint32 &eqCount,
114 qint32 &tokenLength)
const;
116 qint32 findLongBlockEnd(
const QString &text, qint32 from, qint32 eqCount)
const;
118 void buildRules(
bool isDark);
148 void setFilename(
const QString &f) { filename = f; }
149 QString getFilename()
const {
return filename; }
218 bool eventFilter(QObject *watched, QEvent *event)
override;
222 void updateLineNumberAreaWidth(
int newBlockCount);
224 void rebuildLineHighlights();
226 void updateLineNumberArea(
const QRect &rect,
int dy);
229 QWidget *lineNumberArea;
230 QSyntaxHighlighter *syntaxHighlighter;
232 qint32 pausedExecutionLine_ = -1;
237 void applyEditorPalette();
281 qint32 lineAtY(qint32 yPx)
const;
305 void attach(QTabWidget *codeTabs, QTreeView *variablesTree, QTreeView *watchTree, QStandardItemModel *watchModel,
306 QTreeView *stackTree, QTreeView *fileTree, QTreeView *breakpointsTree,
307 QPlainTextEdit *evalInputEdit, QPlainTextEdit *evalOutputEdit);
335 QTabWidget *codeTabs_ =
nullptr;
336 QTreeView *variablesTree_ =
nullptr;
337 QTreeView *watchTree_ =
nullptr;
338 QStandardItemModel *watchModel_ =
nullptr;
339 QTreeView *stackTree_ =
nullptr;
340 QTreeView *fileTree_ =
nullptr;
341 QTreeView *breakpointsTree_ =
nullptr;
342 QPlainTextEdit *evalInputEdit_ =
nullptr;
343 QPlainTextEdit *evalOutputEdit_ =
nullptr;
376 void attach(QTabWidget *
tabs);
382 QTabWidget *
tabs()
const {
return tabs_; }
449 void onTabCloseRequested(
int index);
450 void onCurrentTabChanged(
int index);
459 void onCodeViewBreakpointToggled(
const QString &file_path, qint32 line,
bool toggleActive);
462 QTabWidget *tabs_ =
nullptr;
463 QString lastOpenDirectory_;
Definition lua_debugger_code_editor.h:241
void contextMenuEvent(QContextMenuEvent *event) override
Right-click / Ctrl-click / two-finger trackpad tap on the breakpoint gutter: always pop the Edit / Di...
Definition lua_debugger_code_editor.cpp:882
void paintEvent(QPaintEvent *event) override
Delegate painting back to the code view.
Definition lua_debugger_code_editor.h:254
void mousePressEvent(QMouseEvent *event) override
Toggle breakpoints when the gutter is clicked.
Definition lua_debugger_code_editor.cpp:813
LineNumberArea(LuaDebuggerCodeView *editor)
Construct the helper widget bound to a specific code view.
Definition lua_debugger_code_editor.h:247
QSize sizeHint() const override
Size the gutter according to the editor's width requirements.
Definition lua_debugger_code_editor.h:250
Owns the script tab strip and the documents inside it.
Definition lua_debugger_code_editor.h:370
void setLastOpenDirectory(const QString &dir)
Remember the directory the user last opened a script from. Persists for the lifetime of the controlle...
Definition lua_debugger_code_editor.cpp:1104
QTabWidget * tabs() const
Borrowed reference to the tab strip. Exposed so other controllers (breakpoints, reload coordinator) c...
Definition lua_debugger_code_editor.h:382
bool ensureUnsavedChangesHandled(const QString &title)
If any tab is modified, prompt to save / discard / cancel.
Definition lua_debugger_code_editor.cpp:1230
bool saveCodeView(LuaDebuggerCodeView *view)
Persist one editor buffer to its file path.
Definition lua_debugger_code_editor.cpp:1271
void clearAllDocumentModified()
Mark every open document as unmodified without saving.
Definition lua_debugger_code_editor.cpp:1254
LuaDebuggerCodeView * currentCodeView() const
The code editor in the active tab, or nullptr.
Definition lua_debugger_code_editor.cpp:1197
QString lastOpenDirectory()
Directory to seed the next "Open Lua Script" dialog with. Lazily resolves to Documents (or $HOME) on ...
Definition lua_debugger_code_editor.cpp:1091
void clearAllCodeHighlights()
Drop the current-line stripe on every open editor.
Definition lua_debugger_code_editor.cpp:1364
void updateSaveActionState()
Enable Save when the current tab has unsaved edits.
Definition lua_debugger_code_editor.cpp:1337
void updateWindowModifiedState()
Reflect unsaved scripts in the window title (e.g. close hint).
Definition lua_debugger_code_editor.cpp:1347
qint32 unsavedOpenScriptTabCount() const
How many open code tabs currently have unsaved edits.
Definition lua_debugger_code_editor.cpp:1206
void updateTabTextForCodeView(LuaDebuggerCodeView *view)
Update the tab label (e.g. trailing " *") for one editor.
Definition lua_debugger_code_editor.cpp:1318
bool saveAllModified()
Save every tab that has unsaved edits.
Definition lua_debugger_code_editor.cpp:1297
void onSaveFile()
Save the active script tab (toolbar action).
Definition lua_debugger_code_editor.cpp:1398
LuaDebuggerCodeView * loadFile(const QString &file_path)
Load file_path into a code tab, creating one if necessary.
Definition lua_debugger_code_editor.cpp:1109
bool hasUnsavedChanges() const
True if any open tab has unsaved edits.
Definition lua_debugger_code_editor.cpp:1225
void openInitialBreakpointFiles(const QVector< QString > &files)
Open each initial breakpoint file once tabs are ready.
Definition lua_debugger_code_editor.cpp:1356
void applyThemeToAllTabs()
Re-apply the active syntax-highlight theme to every open editor.
Definition lua_debugger_code_editor.cpp:1381
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_editor.h:127
void clearCurrentLineHighlight()
Clear the debugger paused-line highlight (caret stripe unchanged).
Definition lua_debugger_code_editor.cpp:601
QString luaIdentifierUnderCursor(const QTextCursor &cursor) const
Return the Lua identifier under the given cursor position, or an empty string if the position is not ...
Definition lua_debugger_code_editor.cpp:398
void setCurrentLine(qint32 line)
Set the debugger "execution paused" line (amber bar) and move the caret to that line....
Definition lua_debugger_code_editor.cpp:550
QString watchExpressionForContextMenu(const QPoint &viewportPos) const
Watch text for the editor context menu: trimmed selection if any, otherwise the Lua identifier at vie...
Definition lua_debugger_code_editor.cpp:437
void updateBreakpointMarkers()
Refresh breakpoint markers in the gutter area.
Definition lua_debugger_code_editor.cpp:627
void resizeEvent(QResizeEvent *event) override
Update margins whenever Qt reports a size change.
Definition lua_debugger_code_editor.cpp:477
void lineNumberAreaPaintEvent(QPaintEvent *event)
Paint the custom gutter that hosts line numbers and breakpoints.
Definition lua_debugger_code_editor.cpp:674
void breakpointToggled(const QString &filename, qint32 line, bool toggleActive)
Emitted when a breakpoint icon is clicked within the gutter (right margin).
qint32 lineNumberAreaWidth()
Compute the width required for the gutter, including icons.
Definition lua_debugger_code_editor.cpp:447
void moveCaretToLineStart(qint32 line)
Move the caret to the start of a line without changing the paused line (e.g. go-to-line).
Definition lua_debugger_code_editor.cpp:583
bool eventFilter(QObject *watched, QEvent *event) override
Forward Esc to LuaDebuggerDialog (keys go to viewport, not the dialog).
Definition lua_debugger_code_editor.cpp:485
void breakpointGutterMenuRequested(const QString &filename, qint32 line, const QPoint &globalPos)
Request an Edit / Disable (Enable) / Remove popup for the breakpoint at filename:line,...
void applyTheme()
Re-apply theme colors from the current preference.
Definition lua_debugger_code_editor.cpp:632
void setEditorFont(const QFont &font)
Apply a monospace font to both editor text and gutter.
Definition lua_debugger_code_editor.cpp:612
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:165
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:300
void applyAll()
Apply zoomed monospace to code editors and panel mono + regular header fonts to the side panels....
Definition lua_debugger_code_editor.cpp:943
void attach(QTabWidget *codeTabs, QTreeView *variablesTree, QTreeView *watchTree, QStandardItemModel *watchModel, QTreeView *stackTree, QTreeView *fileTree, QTreeView *breakpointsTree, QPlainTextEdit *evalInputEdit, QPlainTextEdit *evalOutputEdit)
Seed the policy with the dialog's panel widgets. Idempotent.
Definition lua_debugger_code_editor.cpp:927
void reapplyToWatchItemModel()
Re-walk the watch model and seed each item's font to panel-mono, preserving its current bold flag (us...
Definition lua_debugger_code_editor.cpp:1036
void applyToPanels()
Apply panel-mono bodies + regular headers to all side panels and re-sync watch QStandardItem fonts....
Definition lua_debugger_code_editor.cpp:972
QFont monospaceFont(bool zoomed) const
Effective monospace font; respects the main-app preference and the optional zoom step....
Definition lua_debugger_code_editor.cpp:1049
void applyToCodeEditors(const QFont &font=QFont())
Apply the (optionally explicit) monospace to all open code-view tabs. When font is empty,...
Definition lua_debugger_code_editor.cpp:949
QFont regularFont() const
Effective regular UI font for tree-column headers.
Definition lua_debugger_code_editor.cpp:1061
Syntax highlighter tuned for Lua keywords, strings, numbers, comments and Lua's long-bracket strings/...
Definition lua_debugger_code_editor.h:85
void highlightBlock(const QString &text) override
Apply highlighting to a single text block.
Definition lua_debugger_code_editor.cpp:212
void setTheme(bool isDark)
Rebuild the rule set for the new theme and rehighlight.
Definition lua_debugger_code_editor.cpp:160
bool luaDebuggerThemeIsDark()
Resolve the effective theme based on the debugger preference and Wireshark's current colour scheme wh...
Definition lua_debugger_code_editor.cpp:62
LuaDebuggerEditorPalette luaDebuggerEditorPaletteFor(bool isDark)
Return the editor palette for the requested theme.
Definition lua_debugger_code_editor.cpp:72
Single source of truth for the script editor's theme-aware colours.
Definition lua_debugger_code_editor.h:54
QColor pausedLine
Background for the line the debugger is paused on.
Definition lua_debugger_code_editor.h:64