This patch allows frontends to declare which lfuns are not implemented
(preamble and toolips for qt2) and make the menus frontends ignore
such unknown functions. Also, it makes the Edit>Thesaurus magically
disappear if lyx is not compiled with aiksaurus support.

While there is a lot to do to improve the menubackend later, I think
that this approach (basically adding a lyx_gui::getStatus) is even
something we may want to keep in 1.4.0cvs (until the whole getstatus
concept goes to hell, of course).

It also makes sure that qt/lyx des not have a stray separator at the
top of the help menu :)

OK to apply?

JMarc

? config.h.in
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.996
diff -u -p -r1.996 ChangeLog
--- src/ChangeLog	16 Dec 2002 12:47:30 -0000	1.996
+++ src/ChangeLog	17 Dec 2002 17:45:50 -0000
@@ -1,3 +1,9 @@
+2002-12-17  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* lyxfunc.C (getStatus): query lyx_gui::getStatus() to catter for
+	unimplemented lfuns. Make LFUN_THESAURUS_ENTRY status unknown if
+	thesaurus is not compiled in
+
 2002-12-16  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* lyxrc.[Ch]:
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.386
diff -u -p -r1.386 lyxfunc.C
--- src/lyxfunc.C	12 Dec 2002 13:46:05 -0000	1.386
+++ src/lyxfunc.C	17 Dec 2002 17:45:50 -0000
@@ -271,9 +271,20 @@ FuncStatus LyXFunc::getStatus(FuncReques
 		return flag.disabled(true);
 	}
 
-	if (ev.action == LFUN_UNKNOWN_ACTION) {
+	switch (ev.action) {
+	case LFUN_UNKNOWN_ACTION:
+#ifndef HAVE_LIBAIKSAURUS
+	case LFUN_THESAURUS_ENTRY:
+#endif
+		flag.unknown(true);
+		break;
+	default:
+		flag |= lyx_gui::getStatus(ev);
+	}
+	
+	if (flag.unknown()) {
 		setStatusMessage(N_("Unknown action"));
-		return flag.unknown(true);
+		return flag;
 	}
 
 	// the default error message if we disable the command
@@ -331,11 +342,6 @@ FuncStatus LyXFunc::getStatus(FuncReques
 		}
 		disable = !mathcursor && !view()->getLyXText()->selection.set();
 		break;
-#ifndef HAVE_LIBAIKSAURUS
-	case LFUN_THESAURUS_ENTRY:
-		disable = true;
-		break;
-#endif
 	case LFUN_RUNCHKTEX:
 		disable = lyxrc.chktex_command == "none";
 		break;
Index: src/frontends/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/ChangeLog,v
retrieving revision 1.143
diff -u -p -r1.143 ChangeLog
--- src/frontends/ChangeLog	12 Dec 2002 13:46:05 -0000	1.143
+++ src/frontends/ChangeLog	17 Dec 2002 17:45:50 -0000
@@ -1,3 +1,8 @@
+2002-12-17  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* lyx_gui.h: add new function lyx_gui::getStatus, which can be
+	used by a frontend to indicate that some lfun is not implemented.
+
 2002-12-12  John Levon  <[EMAIL PROTECTED]>
 
 	* LyXKeySym.h: add isText()
Index: src/frontends/lyx_gui.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/lyx_gui.h,v
retrieving revision 1.14
diff -u -p -r1.14 lyx_gui.h
--- src/frontends/lyx_gui.h	4 Nov 2002 02:12:31 -0000	1.14
+++ src/frontends/lyx_gui.h	17 Dec 2002 17:45:50 -0000
@@ -14,12 +14,14 @@
 
 #include "LColor.h"
 #include "LString.h"
+#include "FuncStatus.h"
 
 #include <vector>
 
 class Dialogs;
 class LyXFont;
 class LyXComm;
+class FuncRequest;
 
 /// GUI interaction
 namespace lyx_gui {
@@ -43,6 +45,13 @@ void start(string const & batch, std::ve
  * quit running LyX
  */
 void exit();
+
+
+/**
+ * return the status flag for a given action. This can be used to tell
+ * that a given lfun is not implemented by a frontend
+ */
+FuncStatus getStatus(FuncRequest const & ev);
 
 /** Eg, passing LColor::black returns "000000",
  *      passing LColor::white returns "ffffff".
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.356
diff -u -p -r1.356 ChangeLog
--- src/frontends/qt2/ChangeLog	17 Dec 2002 17:28:04 -0000	1.356
+++ src/frontends/qt2/ChangeLog	17 Dec 2002 17:45:50 -0000
@@ -1,3 +1,11 @@
+2002-12-17  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* QLPopupMenu.C (populate): ignore unknown lfuns; do not insert
+	separator as first item of a menu
+
+	* lyx_gui.C (getStatus): indicate that LFUN_LAYOUT_PREAMBLE and
+	LFUN_TOOLTIPS_TOGGLE are not implemented
+
 2002-12-13  Juergen Spitzmueller  <[EMAIL PROTECTED]>
 
 	* QBibtexDialog.[Ch]
Index: src/frontends/qt2/QLPopupMenu.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLPopupMenu.C,v
retrieving revision 1.11
diff -u -p -r1.11 QLPopupMenu.C
--- src/frontends/qt2/QLPopupMenu.C	17 Dec 2002 02:43:16 -0000	1.11
+++ src/frontends/qt2/QLPopupMenu.C	17 Dec 2002 17:45:50 -0000
@@ -118,7 +118,8 @@ void QLPopupMenu::populate(Menu * menu)
 	Menu::const_iterator end = menu->end();
 	for (; m != end; ++m) {
 		if (m->kind() == MenuItem::Separator) {
-			insertSeparator();
+			if (count() > 0)
+				insertSeparator();
 		} else if (m->kind() == MenuItem::Submenu) {
 			pair<int, QLPopupMenu *> res = createMenu(this, &(*m), owner_);
 			setItemEnabled(res.first, !disabled(m->submenu()));
@@ -126,7 +127,8 @@ void QLPopupMenu::populate(Menu * menu)
 		} else {
 			FuncStatus const status =
 				owner_->view()->getLyXFunc().getStatus(m->action());
-			if (status.disabled() && m->optional())
+			if ((status.disabled() && m->optional())
+				|| status.unknown())
 				continue;
 			insertItem(getLabel(*m).c_str(), m->action());
 			setItemEnabled(m->action(), !status.disabled());
Index: src/frontends/qt2/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v
retrieving revision 1.24
diff -u -p -r1.24 lyx_gui.C
--- src/frontends/qt2/lyx_gui.C	7 Nov 2002 22:46:30 -0000	1.24
+++ src/frontends/qt2/lyx_gui.C	17 Dec 2002 17:45:50 -0000
@@ -26,6 +26,7 @@
 #include "lyx_main.h"
 #include "lyxrc.h"
 #include "lyxfont.h"
+#include "funcrequest.h"
 
 // FIXME: move this stuff out again
 #include "bufferlist.h"
@@ -165,6 +166,21 @@ void lyx_gui::start(string const & batch
 void lyx_gui::exit()
 {
 	qApp->exit(0);
+}
+
+
+FuncStatus lyx_gui::getStatus(FuncRequest const & ev)
+{
+	FuncStatus flag;
+	switch (ev.action) {
+	case LFUN_LAYOUT_PREAMBLE:
+	case LFUN_TOOLTIPS_TOGGLE:
+		flag.unknown(true);
+		break;
+	default:
+		break;
+	}
+	return flag;
 }
 
 
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.641
diff -u -p -r1.641 ChangeLog
--- src/frontends/xforms/ChangeLog	17 Dec 2002 12:31:27 -0000	1.641
+++ src/frontends/xforms/ChangeLog	17 Dec 2002 17:45:50 -0000
@@ -1,3 +1,9 @@
+2002-12-17  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* Menubar_pimpl.C (create_submenu): correctly ignore unknown lfuns
+
+	* lyx_gui.C (getStatus): implement as a dummy action
+
 2002-12-16  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* XPainter.C: missed a #ifdef USE_XFORMS_IMAGE_LOADER.
Index: src/frontends/xforms/Menubar_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Menubar_pimpl.C,v
retrieving revision 1.79
diff -u -p -r1.79 Menubar_pimpl.C
--- src/frontends/xforms/Menubar_pimpl.C	16 Dec 2002 11:38:21 -0000	1.79
+++ src/frontends/xforms/Menubar_pimpl.C	17 Dec 2002 17:45:50 -0000
@@ -230,12 +230,14 @@ int Menubar::Pimpl::create_submenu(Windo
 	vector<string> extra_labels(menu.size());
 	vector<string>::iterator it = extra_labels.begin();
 	vector<string>::iterator last = it;
-	for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it)
+	for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it) {
+		FuncStatus flag = view->getLyXFunc().getStatus(i->action());
 		if (i->kind() == MenuItem::Separator)
 			*last = "%l";
-		else if (!i->optional() ||
-			 !(view->getLyXFunc().getStatus(i->action()).disabled()))
+		else if (!(i->optional() && flag.disabled())
+			 && ! flag.unknown())
 			last = it;
+	}
 
 	it = extra_labels.begin();
 	size_type count = 0;
@@ -263,11 +265,11 @@ int Menubar::Pimpl::create_submenu(Windo
 		case MenuItem::Command: {
 			FuncStatus const flag =
 				view->getLyXFunc().getStatus(item.action());
-			// handle optional entries.
-			if (item.optional()
-			    && (flag.disabled())) {
+			// handle optional or unknown entries.
+			if (flag.unknown()
+			    || (item.optional() && flag.disabled())) {
 				lyxerr[Debug::GUI]
-					<< "Skipping optional item "
+					<< "Skipping item "
 					<< item.label() << endl;
 				break;
 			}
@@ -296,7 +298,7 @@ int Menubar::Pimpl::create_submenu(Windo
 				pupmode += "%B";
 			if (flag.onoff(false))
 				pupmode += "%b";
-			if (flag.disabled() || flag.unknown())
+			if (flag.disabled())
 				pupmode += "%i";
 			else
 				all_disabled = false;
Index: src/frontends/xforms/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/lyx_gui.C,v
retrieving revision 1.30
diff -u -p -r1.30 lyx_gui.C
--- src/frontends/xforms/lyx_gui.C	16 Dec 2002 11:38:21 -0000	1.30
+++ src/frontends/xforms/lyx_gui.C	17 Dec 2002 17:45:50 -0000
@@ -317,6 +317,12 @@ void lyx_gui::exit()
 }
 
 
+FuncStatus lyx_gui::getStatus(FuncRequest const & /*ev*/)
+{
+	// Nothing interesting to do here
+	return FuncStatus();
+}
+
 string const lyx_gui::hexname(LColor::color col)
 {
 	string const name = lcolor.getX11Name(col);

Reply via email to