wxMaxima
Loading...
Searching...
No Matches
WorksheetSearch.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
37#ifndef WORKSHEETSEARCH_H
38#define WORKSHEETSEARCH_H
39
40#include <wx/regex.h>
41#include <wx/string.h>
42
43class Cell;
44class EditorCell;
45class GroupCell;
46
47namespace WorksheetSearch {
48
56class Matcher {
57public:
58 virtual ~Matcher() = default;
60 virtual bool Matches(wxString text) const = 0;
62 virtual bool FindInEditor(EditorCell *editor, bool down) const = 0;
63};
64
66class StringMatcher final : public Matcher {
67public:
68 StringMatcher(const wxString &str, bool ignoreCase)
69 : m_str(str), m_ignoreCase(ignoreCase) {}
70 bool Matches(wxString text) const override;
71 bool FindInEditor(EditorCell *editor, bool down) const override;
72
73private:
74 wxString m_str;
75 bool m_ignoreCase;
76};
77
79class RegexMatcher final : public Matcher {
80public:
81 explicit RegexMatcher(const wxString &pattern)
82 : m_pattern(pattern), m_regex(pattern) {}
84 bool IsValid() const { return m_regex.IsValid(); }
85 bool Matches(wxString text) const override;
86 bool FindInEditor(EditorCell *editor, bool down) const override;
87
88private:
89 wxString m_pattern;
90 wxRegEx m_regex;
91};
92
94enum class MatchPart { Prompt, Editor, Output };
95
99 GroupCell *m_group = nullptr;
100 MatchPart m_part = MatchPart::Prompt;
102 Cell *m_cell = nullptr;
104 bool m_wrapped = false;
105 bool Found() const { return m_group != nullptr; }
106};
107
115 GroupCell *m_group = nullptr;
117 bool m_inEditor = false;
119 Cell *m_atCell = nullptr;
120};
121
136 const SearchStart &start, bool down,
137 const Matcher &matcher, bool searchInInput,
138 bool searchInOutput);
139
140} // namespace WorksheetSearch
141
142#endif // WORKSHEETSEARCH_H
SearchTarget FindNextTarget(GroupCell *tree, GroupCell *last, const SearchStart &start, bool down, const Matcher &matcher, bool searchInInput, bool searchInOutput)
Find the next match, walking the group cells with wrap-around.
Definition: WorksheetSearch.cpp:185
MatchPart
Which part of a group cell a search match was found in.
Definition: WorksheetSearch.h:94
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:141
This class defines what the user sees as input cell.
Definition: EditorCell.h:59
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
Matches a search expression against worksheet text.
Definition: WorksheetSearch.h:56
virtual bool Matches(wxString text) const =0
Does this text contain a match?
virtual bool FindInEditor(EditorCell *editor, bool down) const =0
Search inside an editor, continuing that editor's previous search.
Regular-expression search.
Definition: WorksheetSearch.h:79
bool FindInEditor(EditorCell *editor, bool down) const override
Search inside an editor, continuing that editor's previous search.
Definition: WorksheetSearch.cpp:57
bool Matches(wxString text) const override
Does this text contain a match?
Definition: WorksheetSearch.cpp:53
bool IsValid() const
False if the pattern did not compile; searching would find nothing.
Definition: WorksheetSearch.h:84
Substring search, optionally case-insensitive.
Definition: WorksheetSearch.h:66
bool Matches(wxString text) const override
Does this text contain a match?
Definition: WorksheetSearch.cpp:37
bool FindInEditor(EditorCell *editor, bool down) const override
Search inside an editor, continuing that editor's previous search.
Definition: WorksheetSearch.cpp:46
Where a search starts: a group plus what the cursor is doing there.
Definition: WorksheetSearch.h:113
bool m_inEditor
True if this group's editor holds the cursor or the previous match.
Definition: WorksheetSearch.h:117
GroupCell * m_group
The group the search starts in; null = nowhere to search.
Definition: WorksheetSearch.h:115
Cell * m_atCell
The previously matched prompt or output cell in this group, if any.
Definition: WorksheetSearch.h:119
A search match: the group it is in and the matching part.
Definition: WorksheetSearch.h:97
Cell * m_cell
The matching prompt or output cell; null for an editor match.
Definition: WorksheetSearch.h:102
bool m_wrapped
True if the search passed the document end and started over.
Definition: WorksheetSearch.h:104
GroupCell * m_group
The group holding the match; null if nothing was found.
Definition: WorksheetSearch.h:99