commit 573c51033b191304e4c1b54e57c796f13b3e98b2
Author: Koji Yokota <[email protected]>
Date: Sun Jun 22 01:32:22 2025 +0900
Adapt to the getStatus() scheme
---
src/Cursor.cpp | 16 ++++++++-----
src/frontends/qt/GuiToolbar.cpp | 47 +++++++++++----------------------------
src/frontends/qt/GuiToolbar.h | 8 +++----
src/insets/InsetText.cpp | 14 ++++++++++++
src/mathed/InsetMathHull.cpp | 11 +++++++++
src/mathed/InsetMathIntertext.cpp | 2 ++
src/mathed/MathFactory.cpp | 3 ---
7 files changed, 54 insertions(+), 47 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index cbce61c5f6..4b4b39fd57 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -32,6 +32,7 @@
#include "Text.h"
#include "TextMetrics.h"
#include "TocBackend.h"
+#include "FuncStatus.h"
#include "support/debug.h"
#include "support/docstream.h"
@@ -44,7 +45,6 @@
#include "mathed/InsetMath.h"
#include "mathed/InsetMathBrace.h"
#include "mathed/InsetMathEnsureMath.h"
-#include "mathed/InsetMathHull.h"
#include "mathed/InsetMathScript.h"
#include "mathed/MacroTable.h"
#include "mathed/MathData.h"
@@ -1788,12 +1788,16 @@ bool Cursor::macroModeClose(bool cancel)
return true;
bool const user_macro = buffer()->getMacro(name, *this, false);
- // check if the inset can be used in the current math hull
- if (in != nullptr && in->asHullInset() &&
-
!in->asHullInset()->insetAllowed(insetCode("math"+to_utf8(name))))
+ MathAtom atom;
+ FuncRequest fr(LFUN_MATH_INSERT, "\\" + name);
+ FuncStatus status;
+ getStatus(fr, status);
+ // exit if the inset cannot be used e.g. in the current math hull
+ if (!status.enabled())
return false;
- MathAtom atom = user_macro ? MathAtom(new InsetMathMacro(buffer(),
name))
- : createInsetMath(name, buffer());
+ else
+ atom = user_macro ? MathAtom(new InsetMathMacro(buffer(), name))
+ : createInsetMath(name, buffer());
// try to put argument into macro, if we just inserted a macro
bool macroArg = false;
diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp
index a43d97447a..7821d6be64 100644
--- a/src/frontends/qt/GuiToolbar.cpp
+++ b/src/frontends/qt/GuiToolbar.cpp
@@ -42,8 +42,6 @@
#include "insets/InsetText.h"
-#include "mathed/MathFactory.h"
-
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstring_list.h"
@@ -426,11 +424,7 @@ void DynamicMenuButton::updateTriggered()
&& !m->isEmpty()
&& inset->insetAllowed(FLEX_CODE));
} else if (menutype == "dynamic-math-texts") {
- InsetMathHull * hull =
bv->cursor().inset().asInsetMath()->asHullInset();
- if (bv->cursor().inMathed() && hull != nullptr) {
- setEnabled(true);
- loadMathTexts(hull);
- }
+ setEnabled(loadMathTexts());
} else if (menutype == "textstyle-apply") {
m->clear();
setPopupMode(QToolButton::MenuButtonPopup);
@@ -536,39 +530,24 @@ void DynamicMenuButton::loadFlexInsets()
}
-void DynamicMenuButton::loadMathTexts(InsetMathHull * hull)
+bool DynamicMenuButton::loadMathTexts()
{
- string const & menutype = tbitem_.name;
- if (menutype != "dynamic-math-texts")
- return;
-
QMenu * m = menu();
m->clear();
+ bool isEnabled = false;
- HullType hullType = hull->getType();
- bool skippedMenu = false;
for (int i=0; i<mathTextMenuSize_; i++) {
- for (docstring const & command : mathedConflictList(hullType)) {
- if (from_utf8(mathTextMenu[i][0]) == command) {
- skippedMenu = true;
- break;
- }
- }
- if (!skippedMenu) {
- FuncRequest func(LFUN_MATH_INSERT,
- "\\" + mathTextMenu[i][0],
- FuncRequest::TOOLBAR);
- QString menuText = toqstr(from_utf8(mathTextMenu[i][1]
+ "\t\\" +
- mathTextMenu[i][0]));
- QString tooltip = toqstr(from_utf8(mathTextMenu[i][2]));
- Action * act =
- new Action(func, getIcon(func, false),
- menuText, tooltip, this);
- m->addAction(act);
- } else {
- skippedMenu = false;
- }
+ FuncRequest func(LFUN_MATH_INSERT, "\\" + mathTextMenu[i][0],
+ FuncRequest::TOOLBAR);
+ QString menuText = toqstr(from_utf8(mathTextMenu[i][1] + "\t\\"
+
+ mathTextMenu[i][0]));
+ QString tooltip = toqstr(from_utf8(mathTextMenu[i][2]));
+ Action * act =
+ new Action(func, getIcon(func, false), menuText,
tooltip, this);
+ m->addAction(act);
+ isEnabled |= lyx::getStatus(func).enabled();
}
+ return isEnabled;
}
diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h
index cd2db3fd5b..59242c7167 100644
--- a/src/frontends/qt/GuiToolbar.h
+++ b/src/frontends/qt/GuiToolbar.h
@@ -104,7 +104,7 @@ protected:
///
void loadFlexInsets();
///
- void loadMathTexts(InsetMathHull * hull);
+ bool loadMathTexts();
/// pimpl so we don't have to include big files
class Private;
Private * d;
@@ -129,10 +129,10 @@ private:
{"fbox", "Framed Text", "Framed text"},
{"framebox", "Framed Text with sizes", "Framed text with
variable frame sizes"},
{"text", "AMS Text", "Text in current font
with variable sizes"},
- {"textrm", "Roman text", "Text in roman font"},
- {"textnormal", "Normal font text", "Text using
\\normalfont"},
+ {"textrm", "Roman Text", "Text in roman font"},
+ {"textnormal", "Normal Font Text", "Text using
\\normalfont"},
{"intertext", "Intertext", "Text between
equations"},
- {"shortintertext", "Short intertext", "Text between equations
of short height"}
+ {"shortintertext", "Short Intertext", "Text between equations
of short height"}
};
};
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index b5641230f9..f2a8c261ba 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -405,6 +405,17 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const
& cmd,
return true;
}
+ // The below can be called when the math panel is on in the text mode
+ case LFUN_MATH_INSERT:
+ if (!cmd.argument().empty()) {
+ status.setEnabled(
+ insetAllowed(
+ insetCode(
+ to_utf8("math" +
ltrim(cmd.argument(), "\\")))));
+ return true;
+ }
+ // let else go down to default
+
default:
// Dispatch only to text_ if the cursor is inside
// the text_. It is not for context menus (bug 5797).
@@ -1047,6 +1058,9 @@ bool InsetText::insetAllowed(InsetCode code) const
// These are only allowed in index insets
case INDEXMACRO_CODE:
case INDEXMACRO_SORTKEY_CODE:
+ // The below cannot be called from the text mode directly
+ case MATH_INTERTEXT_CODE:
+ case MATH_SHORTINTERTEXT_CODE:
return false;
default:
return !isPassThru();
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 0746d897c0..6f91a0caf2 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -47,6 +47,7 @@
#include "Session.h"
+#include "insets/Inset.h"
#include "insets/InsetLabel.h"
#include "insets/InsetRef.h"
#include "insets/RenderPreview.h"
@@ -2243,6 +2244,16 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest
const & cmd,
return InsetMathGrid::getStatus(cur, cmd, status);
}
+ case LFUN_MATH_INSERT:
+ if (!cmd.argument().empty()) {
+ status.setEnabled(
+ insetAllowed(
+ insetCode(
+ to_utf8("math" +
ltrim(cmd.argument(), "\\")))));
+ return true;
+ } else
+ return InsetMathGrid::getStatus(cur, cmd, status);
+
default:
return InsetMathGrid::getStatus(cur, cmd, status);
}
diff --git a/src/mathed/InsetMathIntertext.cpp
b/src/mathed/InsetMathIntertext.cpp
index 8b9003b268..2287f68175 100644
--- a/src/mathed/InsetMathIntertext.cpp
+++ b/src/mathed/InsetMathIntertext.cpp
@@ -14,6 +14,7 @@
#include "Buffer.h"
#include "BufferView.h"
+#include "Cursor.h"
#include "Dimension.h"
#include "InsetMathChar.h"
#include "LaTeXFeatures.h"
@@ -105,4 +106,5 @@ void InsetMathIntertext::validate(LaTeXFeatures & features)
const
InsetMathNest::validate(features);
}
+
} // namespace lyx
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 7838c28a95..65678ba5fc 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -64,11 +64,8 @@
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/filetools.h" // LibFileSearch
-#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/Package.h"
-#include "frontends/alert.h"
#include "frontends/FontLoader.h"
#include "Buffer.h"
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs