Folding: Toggling folds by clicking the indicator

This commit is contained in:
arch1t3cht 2022-07-26 22:19:53 +02:00
parent 2176954aee
commit 818fcd51f4
3 changed files with 31 additions and 0 deletions

View file

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

View file

@ -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<AssDialogue *> 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) {

View file

@ -15,6 +15,7 @@
// Aegisub Project http://www.aegisub.org/
#include "flyweight_hash.h"
#include "wx/event.h"
#include <memory>
#include <string>
@ -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; }