diff --git a/src/base_grid.cpp b/src/base_grid.cpp index 4c97c4cc7..b01a0dac2 100644 --- a/src/base_grid.cpp +++ b/src/base_grid.cpp @@ -459,6 +459,17 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { AssDialogue *dlg = GetVisDialogue(row); if (!dlg) row = 0; + // Find the column the mouse is over + int colx = event.GetX(); + int col; + for (col = 0; col < columns.size(); col++) { + int w = columns[col]->Width(); + if (colx < w) { + break; + } + colx -= w; + } + if (event.ButtonDown() && OPT_GET("Subtitle/Grid/Focus Allow")->GetBool()) SetFocus(); @@ -488,6 +499,10 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { CaptureMouse(); } + if (columns[col]->OnMouseEvent(dlg, context, event)) { + return; + } + if ((click || holding || dclick) && dlg) { int old_extend = extendRow; diff --git a/src/grid_column.cpp b/src/grid_column.cpp index 8abe69868..08e165a41 100644 --- a/src/grid_column.cpp +++ b/src/grid_column.cpp @@ -147,6 +147,18 @@ struct GridColumnFolds final : GridColumn { return " " + value; } + bool OnMouseEvent(AssDialogue *d, agi::Context *c, wxMouseEvent &event) const override { + if ((event.LeftDown() || event.LeftDClick()) && !event.ShiftDown() && !event.CmdDown() && !event.AltDown()) { + if (d->Fold.hasFold() && !d->Fold.isEnd()) { + std::vector lines; + lines.push_back(d); + c->foldController->ToggleFoldsAt(lines); + return true; + } + } + return false; + } + int Width(const agi::Context *c, WidthHelper &helper) const override { int maxdepth = c->foldController->GetMaxDepth(); if (maxdepth == 0) { diff --git a/src/grid_column.h b/src/grid_column.h index 16b70f2a9..d00d36478 100644 --- a/src/grid_column.h +++ b/src/grid_column.h @@ -15,6 +15,7 @@ // Aegisub Project http://www.aegisub.org/ #include "flyweight_hash.h" +#include "wx/event.h" #include #include @@ -68,6 +69,9 @@ public: virtual wxString const& Description() const = 0; virtual void Paint(wxDC &dc, int x, int y, const AssDialogue *d, const agi::Context *c) const; + // Returns true if the default action should be skipped + virtual bool OnMouseEvent(AssDialogue *d, agi::Context *c, wxMouseEvent &event) const { return false; } + int Width() const { return width; } bool Visible() const { return visible; }