16#ifndef LUA_DEBUGGER_CODE_EDITOR_H
17#define LUA_DEBUGGER_CODE_EDITOR_H
22#include <QPlainTextEdit>
24#include <QRegularExpression>
26#include <QSyntaxHighlighter>
27#include <QTextCharFormat>
34class QContextMenuEvent;
37class QStandardItemModel;
38class QSyntaxHighlighter;
56 QColor editorBackground;
61 QColor gutterBackground;
105 QRegularExpression pattern;
106 QTextCharFormat format;
109 QVector<Rule> rules_;
110 QTextCharFormat stringFormat_;
111 QTextCharFormat commentFormat_;
112 QRegularExpression singleLineComment_;
115 bool highlightLongBlock(
const QString &text,
bool isComment,
bool continuingPrevious, qint32 eqCountFromState,
116 qint32 &nextStateEqCount);
118 qint32 findLongBlockStart(
const QString &text, qint32 from,
bool isComment, qint32 &eqCount,
119 qint32 &tokenLength)
const;
121 qint32 findLongBlockEnd(
const QString &text, qint32 from, qint32 eqCount)
const;
127 void buildRules(
bool isDark);
253 bool eventFilter(QObject *watched, QEvent *event)
override;
257 void updateLineNumberAreaWidth(
int newBlockCount);
259 void rebuildLineHighlights();
261 void updateLineNumberArea(
const QRect &rect,
int dy);
265 QWidget *lineNumberArea;
267 QSyntaxHighlighter *syntaxHighlighter;
269 qint32 pausedExecutionLine_ = -1;
277 void applyEditorPalette();
359 qint32 lineAtY(qint32 yPx)
const;
366 bool hasBreakpointAtLine(qint32 line)
const;
374 qint32 nearestVisibleDropLine(qint32 yPx, qint32 sourceLine)
const;
380 qint32 pressedLine_ = -1;
383 qint32 dragTargetLine_ = -1;
386 bool leftPressArmed_ =
false;
389 bool draggingBreakpoint_ =
false;
392 bool pressShiftToggle_ =
false;
395 bool pressHadBreakpoint_ =
false;
431 void attach(QTabWidget *codeTabs, QTreeView *variablesTree, QTreeView *watchTree, QStandardItemModel *watchModel,
432 QTreeView *stackTree, QTreeView *fileTree, QTreeView *breakpointsTree,
433 QPlainTextEdit *evalInputEdit, QPlainTextEdit *evalOutputEdit);
472 QTabWidget *codeTabs_ =
nullptr;
474 QTreeView *variablesTree_ =
nullptr;
476 QTreeView *watchTree_ =
nullptr;
478 QStandardItemModel *watchModel_ =
nullptr;
480 QTreeView *stackTree_ =
nullptr;
482 QTreeView *fileTree_ =
nullptr;
484 QTreeView *breakpointsTree_ =
nullptr;
486 QPlainTextEdit *evalInputEdit_ =
nullptr;
488 QPlainTextEdit *evalOutputEdit_ =
nullptr;
537 QTabWidget *
tabs()
const {
return tabs_; }
647 void onCodeViewBreakpointToggled(
const QString &file_path, qint32 line,
bool toggleActive);
653 QTabWidget *tabs_ =
nullptr;
656 QString lastOpenDirectory_;
A widget for displaying line numbers in the code editor.
Definition lua_debugger_code_editor.h:284
qint32 dragTargetLine() const
Current drag target line, or -1 if not dragging.
Definition lua_debugger_code_editor.h:305
void mouseMoveEvent(QMouseEvent *event) override
Track drag gestures in the breakpoint gutter.
Definition lua_debugger_code_editor.cpp:935
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:1050
void paintEvent(QPaintEvent *event) override
Delegate painting back to the code view.
Definition lua_debugger_code_editor.h:316
void mousePressEvent(QMouseEvent *event) override
Toggle breakpoints when the gutter is clicked.
Definition lua_debugger_code_editor.cpp:891
qint32 dragSourceLine() const
Source line being dragged, or -1 if not dragging.
Definition lua_debugger_code_editor.h:310
void mouseReleaseEvent(QMouseEvent *event) override
Commit click vs drag-drop action on mouse release.
Definition lua_debugger_code_editor.cpp:965
bool isDraggingBreakpoint() const
True if a breakpoint drag-and-drop is currently in progress.
Definition lua_debugger_code_editor.h:300
LineNumberArea(LuaDebuggerCodeView *editor)
Construct the helper widget bound to a specific code view.
Definition lua_debugger_code_editor.h:290
QSize sizeHint() const override
Size the gutter according to the editor's width requirements.
Definition lua_debugger_code_editor.h:295
Owns the script tab strip and the documents inside it.
Definition lua_debugger_code_editor.h:515
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:1272
QTabWidget * tabs() const
Borrowed reference to the tab strip. Exposed so other controllers (breakpoints, reload coordinator) c...
Definition lua_debugger_code_editor.h:537
bool ensureUnsavedChangesHandled(const QString &title)
If any tab is modified, prompt to save / discard / cancel.
Definition lua_debugger_code_editor.cpp:1401
bool saveCodeView(LuaDebuggerCodeView *view)
Persist one editor buffer to its file path.
Definition lua_debugger_code_editor.cpp:1442
void clearAllDocumentModified()
Mark every open document as unmodified without saving.
Definition lua_debugger_code_editor.cpp:1425
LuaDebuggerCodeView * currentCodeView() const
The code editor in the active tab, or nullptr.
Definition lua_debugger_code_editor.cpp:1368
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:1259
void clearAllCodeHighlights()
Drop the current-line stripe on every open editor.
Definition lua_debugger_code_editor.cpp:1535
void updateSaveActionState()
Enable Save when the current tab has unsaved edits.
Definition lua_debugger_code_editor.cpp:1508
void updateWindowModifiedState()
Reflect unsaved scripts in the window title (e.g. close hint).
Definition lua_debugger_code_editor.cpp:1518
qint32 unsavedOpenScriptTabCount() const
How many open code tabs currently have unsaved edits.
Definition lua_debugger_code_editor.cpp:1377
void attach(QTabWidget *tabs)
Attaches the controller to the given tab widget.
Definition lua_debugger_code_editor.cpp:1242
void updateTabTextForCodeView(LuaDebuggerCodeView *view)
Update the tab label (e.g. trailing " *") for one editor.
Definition lua_debugger_code_editor.cpp:1489
void onTabCloseRequested(int index)
Handles a request to close a specific tab.
Definition lua_debugger_code_editor.cpp:1593
bool saveAllModified()
Save every tab that has unsaved edits.
Definition lua_debugger_code_editor.cpp:1468
void onCurrentTabChanged(int index)
Handles a change in the active tab.
Definition lua_debugger_code_editor.cpp:1580
void onSaveFile()
Save the active script tab (toolbar action).
Definition lua_debugger_code_editor.cpp:1569
LuaDebuggerCodeView * loadFile(const QString &file_path)
Load file_path into a code tab, creating one if necessary.
Definition lua_debugger_code_editor.cpp:1277
bool hasUnsavedChanges() const
True if any open tab has unsaved edits.
Definition lua_debugger_code_editor.cpp:1396
void openInitialBreakpointFiles(const QVector< QString > &files)
Open each initial breakpoint file once tabs are ready.
Definition lua_debugger_code_editor.cpp:1527
void applyThemeToAllTabs()
Re-apply the active syntax-highlight theme to every open editor.
Definition lua_debugger_code_editor.cpp:1552
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_editor.h:136
void breakpointMoveRequested(const QString &filename, qint32 fromLine, qint32 toLine)
Request moving a breakpoint in filename from fromLine to toLine after a gutter drag-and-drop gesture.
void clearCurrentLineHighlight()
Clear the debugger paused-line highlight (caret stripe unchanged).
Definition lua_debugger_code_editor.cpp:595
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:392
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:544
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:431
void setFilename(const QString &f)
Set the file path this editor is currently hosting, for use in breakpoint management and the "edited"...
Definition lua_debugger_code_editor.h:164
void updateBreakpointMarkers()
Refresh breakpoint markers in the gutter area.
Definition lua_debugger_code_editor.cpp:621
void resizeEvent(QResizeEvent *event) override
Update margins whenever Qt reports a size change.
Definition lua_debugger_code_editor.cpp:471
void lineNumberAreaPaintEvent(QPaintEvent *event)
Paint the custom gutter that hosts line numbers and breakpoints.
Definition lua_debugger_code_editor.cpp:668
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:441
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:577
bool eventFilter(QObject *watched, QEvent *event) override
Forward Esc to LuaDebuggerDialog (keys go to viewport, not the dialog).
Definition lua_debugger_code_editor.cpp:479
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:626
QString getFilename() const
Get the file path associated with this editor.
Definition lua_debugger_code_editor.h:170
void setEditorFont(const QFont &font)
Apply a monospace font to both editor text and gutter.
Definition lua_debugger_code_editor.cpp:606
Top-level dialog hosting the Lua debugger UI components.
Definition lua_debugger_dialog.h:189
Owns the dialog's font story end-to-end.
Definition lua_debugger_code_editor.h:414
LuaDebuggerFontPolicy()=default
Default constructor for the font policy.
void applyAll()
Apply zoomed monospace to code editors and panel mono + regular header fonts to the side panels....
Definition lua_debugger_code_editor.cpp:1111
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:1095
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:1204
void applyToPanels()
Apply panel-mono bodies + regular headers to all side panels and re-sync watch QStandardItem fonts....
Definition lua_debugger_code_editor.cpp:1140
QFont monospaceFont(bool zoomed) const
Effective monospace font; respects the main-app preference and the optional zoom step....
Definition lua_debugger_code_editor.cpp:1217
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:1117
QFont regularFont() const
Effective regular UI font for tree-column headers.
Definition lua_debugger_code_editor.cpp:1229
Syntax highlighter tuned for Lua keywords, strings, numbers, comments and Lua's long-bracket strings/...
Definition lua_debugger_code_editor.h:90
void highlightBlock(const QString &text) override
Apply highlighting to a single text block.
Definition lua_debugger_code_editor.cpp:205
void setTheme(bool isDark)
Rebuild the rule set for the new theme and rehighlight.
Definition lua_debugger_code_editor.cpp:153
bool luaDebuggerThemeIsDark()
Resolve the effective theme based on the debugger preference and Wireshark's current colour scheme wh...
LuaDebuggerEditorPalette luaDebuggerEditorPaletteFor(bool isDark)
Return the editor palette for the requested theme.
Definition lua_debugger_code_editor.cpp:65
Single source of truth for the script editor's theme-aware colours.
Definition lua_debugger_code_editor.h:55
QColor pausedLine
Background for the line the debugger is paused on.
Definition lua_debugger_code_editor.h:65