From: Jean-Marc Lasgouttes [lasgout...@lyx.org]
Sent: Thursday, July 12, 2012 5:20 AM

Le 12/07/2012 09:44, Scott Kostyshak a écrit :
>> It seems that there are many LFUNs that would fall under the description
>> of the "Argument" flag (currently help-open is the only LFUN to specify
>> it). If this flag were accurately used, would it be desired to have a
>> centralized checking of an empty argument?

>I think theargument flag is not flexible enough to be useful.

Why not? The attached patch checks whether the LFUN being called in GuiView.cpp 
has the Argument flag and is trying to use an empty argument. If so, the 
command is disabled (from getStatus). I think it is similar to checking 
NoBuffer. Why should checking for whether there's no argument be treated 
differently from checking whether there's no open buffer? Shouldn't both be 
done in getStatus and not by each individual LFUN?

The patch adds the Argument property to a few LFUNs and removes some now 
unnecessary case-specific checks. These are just for examples though and the 
patch is not meant to be complete.

Scott
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 39018ce..dddf86f 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2177,7 +2177,7 @@ void LyXAction::init()
  * \li Origin: sanda, 13 Jan 2009
  * \endvar
  */
-		{ LFUN_VC_COMMAND, "vc-command", NoBuffer | ReadOnly, System },
+		{ LFUN_VC_COMMAND, "vc-command", NoBuffer | ReadOnly | Argument, System },
 /*!
  * \var lyx::FuncCode lyx::LFUN_VC_LOCKING_TOGGLE
  * \li Action: Toggles the locking property of the edited file.
@@ -2598,7 +2598,7 @@ void LyXAction::init()
  * \li Origin: Edwin, 21 May 2007
  * \endvar
  */
-		{ LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer, Buffer },
+		{ LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer | Argument, Buffer },
 /*!
  * \var lyx::FuncCode lyx::LFUN_MENU_OPEN
  * \li Action: Opens the menu given by its name.
@@ -2681,7 +2681,7 @@ void LyXAction::init()
  * \li Origin: leeming, 17 Jun 2003
  * \endvar
  */
-		{ LFUN_DIALOG_SHOW, "dialog-show", NoBuffer, Edit },
+		{ LFUN_DIALOG_SHOW, "dialog-show", NoBuffer | Argument, Edit },
 /*!
  * \var lyx::FuncCode lyx::LFUN_DIALOG_SHOW_NEW_INSET
  * \li Action: Shows hidden dialog or create new one for a given inset settings etc.
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 52a4379..b7eb4b6 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -1601,6 +1601,12 @@ void GuiView::resetAutosaveTimers()
 bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 {
 	bool enable = true;
+	if (lyxaction.funcHasFlag(cmd.action(), LyXAction::Argument) && cmd.argument().empty()) {
+		flag.message(from_utf8(N_("Command not allowed with"
+					"out any argument")));
+		flag.setEnabled(false);
+		return true;
+	}
 	Buffer * buf = currentBufferView()
 		? &currentBufferView()->buffer() : 0;
 	Buffer * doc_buffer = documentBufferView()
@@ -1860,8 +1866,6 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 		enable = doc_buffer && doc_buffer->lyxvc().repoUpdateEnabled();
 		break;
 	case LFUN_VC_COMMAND: {
-		if (cmd.argument().empty())
-			enable = false;
 		if (!doc_buffer && contains(cmd.getArg(0), 'D'))
 			enable = false;
 		break;

Reply via email to