Ejemplo n.º 1
0
bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {
	case LFUN_INSET_DISSOLVE: {
		bool const main_inset = &buffer().inset() == this;
		bool const target_inset = cmd.argument().empty() 
			|| cmd.getArg(0) == insetName(lyxCode());
		bool const one_cell = nargs() == 1;

		if (target_inset)
			status.setEnabled(!main_inset && one_cell);
		return target_inset;
	}

	default:
		// Dispatch only to text_ if the cursor is inside
		// the text_. It is not for context menus (bug 5797).
		bool ret = false;
		if (cur.text() == &text_)
			ret = text_.getStatus(cur, cmd, status);
		
		if (!ret)
			ret = Inset::getStatus(cur, cmd, status);
		return ret;
	}
}
Ejemplo n.º 2
0
bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		string const first_arg = cmd.getArg(0);
		if (first_arg == "changetype") {
			string const type = cmd.getArg(1);
			status.setOnOff(type == type_);
			bool varia = type != "Unnumbered";
			// check if the immediate parent inset allows caption variation
			if (cur.depth() > 1) {
				varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type);
			}
			status.setEnabled(varia
					  && buffer().params().documentClass().hasInsetLayout(
						from_ascii("Caption:" + type)));
			return true;
		}
		return InsetText::getStatus(cur, cmd, status);
	}

	case LFUN_INSET_TOGGLE:
		// pass back to owner
		cur.undispatched();
		return false;

	default:
		return InsetText::getStatus(cur, cmd, status);
	}
}
Ejemplo n.º 3
0
void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY:
		setInfo(to_utf8(cmd.argument()));
		break;

	case LFUN_INSET_COPY_AS: {
		cap::clearSelection();
		Cursor copy(cur);
		copy.pushBackward(*this);
		copy.pit() = 0;
		copy.pos() = 0;
		copy.resetAnchor();
		copy.pit() = copy.lastpit();
		copy.pos() = copy.lastpos();
		copy.setSelection();
		cap::copySelection(copy);
		break;
	}

	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 4
0
bool InsetCommand::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {
	// suppress these
	case LFUN_ERT_INSERT:
		status.setEnabled(false);
		return true;
	
	// we handle these
	case LFUN_INSET_MODIFY:
		if (cmd.getArg(0) == "changetype") {
			string const newtype = cmd.getArg(1);
			status.setEnabled(p_.isCompatibleCommand(p_.code(), newtype));
			status.setOnOff(newtype == p_.getCmdName());
		} 
		status.setEnabled(true);
		return true;
	
	case LFUN_INSET_DIALOG_UPDATE:
		status.setEnabled(true);
		return true;
	
	default:
		return Inset::getStatus(cur, cmd, status);
	}
}
Ejemplo n.º 5
0
bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
		FuncStatus & flag) const
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY: {
		istringstream is(to_utf8(cmd.argument()));
		string s;
		is >> s;
		if (s != "tabular")
			break;
		is >> s;
		if (s == "add-vline-left" || s == "add-vline-right") {
			flag.setEnabled(false);
			flag.message(bformat(
				from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
				from_utf8(s)));
			return true;
		}
		if (s == "append-column" || s == "delete-column") {
			flag.setEnabled(false);
			flag.message(bformat(
				from_utf8(N_("Changing number of columns not allowed in "
					     "'cases': feature %1$s")), from_utf8(s)));
			return true;
		}
		break;
	}
	default:
		break;
	}
	return InsetMathGrid::getStatus(cur, cmd, flag);
}
Ejemplo n.º 6
0
bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
		FuncStatus & flag) const
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY:
		flag.setEnabled(true);
		break;

	case LFUN_BRANCH_ACTIVATE:
		flag.setEnabled(!isBranchSelected());
		break;

	case LFUN_BRANCH_DEACTIVATE:
		flag.setEnabled(isBranchSelected());
		break;

	case LFUN_INSET_TOGGLE:
		if (cmd.argument() == "assign")
			flag.setEnabled(true);
		else
			return InsetCollapsable::getStatus(cur, cmd, flag);	
		break;

	default:
		return InsetCollapsable::getStatus(cur, cmd, flag);
	}
	return true;
}
Ejemplo n.º 7
0
Archivo: Inset.cpp Proyecto: bsjung/Lyx
void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
{
	switch (cmd.action()) {
	case LFUN_MOUSE_RELEASE:
		// if the derived inset did not explicitly handle mouse_release,
		// we assume we request the settings dialog
		if (!cur.selection() && cmd.button() == mouse_button::button1
			  && hasSettings()) {
			FuncRequest tmpcmd(LFUN_INSET_SETTINGS);
			dispatch(cur, tmpcmd);
		}
		break;

	case LFUN_INSET_SETTINGS:
		if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
			showInsetDialog(&cur.bv());
			cur.dispatched();
		} else
			cur.undispatched();
		break;

	default:
		cur.noScreenUpdate();
		cur.undispatched();
		break;
	}
}
Ejemplo n.º 8
0
void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);

	// See bug #9042, for instance.
	if (isPassThru()) {
		// Force any new text to latex_language FIXME: This
		// should only be necessary in constructor, but new
		// paragraphs that are created by pressing enter at
		// the start of an existing paragraph get the buffer
		// language and not latex_language, so we take this
		// brute force approach.
		cur.current_font.setLanguage(latex_language);
		cur.real_current_font.setLanguage(latex_language);
	}

	switch (cmd.action()) {
	case LFUN_PASTE:
	case LFUN_CLIPBOARD_PASTE:
	case LFUN_SELECTION_PASTE:
	case LFUN_PRIMARY_SELECTION_PASTE:
		text_.dispatch(cur, cmd);
		// If we we can only store plain text, we must reset all
		// attributes.
		// FIXME: Change only the pasted paragraphs
		fixParagraphsFont();
		break;

	case LFUN_INSET_DISSOLVE: {
		bool const main_inset = text_.isMainText();
		bool const target_inset = cmd.argument().empty()
			|| cmd.getArg(0) == insetName(lyxCode());
		// cur.inset() is the tabular when this is a single cell (bug #9954)
		bool const one_cell = cur.inset().nargs() == 1;

		if (!main_inset && target_inset && one_cell) {
			// Text::dissolveInset assumes that the cursor
			// is inside the Inset.
			if (&cur.inset() != this)
				cur.pushBackward(*this);
			cur.beginUndoGroup();
			text_.dispatch(cur, cmd);
			cur.endUndoGroup();
		} else
			cur.undispatched();
		break;
	}

	default:
		text_.dispatch(cur, cmd);
	}

	if (!cur.result().dispatched())
		Inset::doDispatch(cur, cmd);
}
Ejemplo n.º 9
0
bool Inset::getStatus(Cursor &, FuncRequest const & cmd,
	FuncStatus & flag) const
{
	// LFUN_INSET_APPLY is sent from the dialogs when the data should
	// be applied. This is either changed to LFUN_INSET_MODIFY (if the
	// dialog belongs to us) or LFUN_INSET_INSERT (if the dialog does
	// not belong to us, i. e. the dialog was open, and the user moved
	// the cursor in our inset) in lyx::getStatus().
	// Dialogs::checkStatus() ensures that the dialog is deactivated if
	// LFUN_INSET_APPLY is disabled.

	switch (cmd.action()) {
	case LFUN_INSET_MODIFY:
		// Allow modification of our data.
		// This needs to be handled in the doDispatch method of our
		// instantiatable children.
		// FIXME: Why don't we let the insets determine whether this
		// should be enabled or not ? Now we need this check for 
		// the tabular features. (vfr)
		if (cmd.getArg(0) == "tabular")
			return false;
		flag.setEnabled(true);
		return true;

	case LFUN_INSET_INSERT:
		// Don't allow insertion of new insets.
		// Every inset that wants to allow new insets from open
		// dialogs needs to override this.
		flag.setEnabled(false);
		return true;

	case LFUN_INSET_SETTINGS:
		if (cmd.argument().empty() || cmd.getArg(0) == insetName(lyxCode())) {
			bool const enable = hasSettings();
			flag.setEnabled(enable);
			return true;
		} else {
			return false;
		}

	case LFUN_IN_MATHMACROTEMPLATE:
		// By default we're not in a MathMacroTemplate inset
		flag.setEnabled(false);
		return true;

	case LFUN_IN_IPA:
		// By default we're not in an IPA inset
		flag.setEnabled(false);
		return true;

	default:
		break;
	}
	return false;
}
Ejemplo n.º 10
0
bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {
	case LFUN_INSET_DISSOLVE: {
		bool const main_inset = text_.isMainText();
		bool const target_inset = cmd.argument().empty()
			|| cmd.getArg(0) == insetName(lyxCode());
		// cur.inset() is the tabular when this is a single cell (bug #9954)
		bool const one_cell = cur.inset().nargs() == 1;

		if (target_inset)
			status.setEnabled(!main_inset && one_cell);
		return target_inset;
	}

	case LFUN_ARGUMENT_INSERT: {
		string const arg = cmd.getArg(0);
		if (arg.empty()) {
			status.setEnabled(false);
			return true;
		}
		if (text_.isMainText() || !cur.paragraph().layout().args().empty())
			return text_.getStatus(cur, cmd, status);

		Layout::LaTeXArgMap args = getLayout().args();
		Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
		if (lait != args.end()) {
			status.setEnabled(true);
			for (Paragraph const & par : paragraphs())
				for (auto const & table : par.insetList())
					if (InsetArgument const * ins = table.inset->asInsetArgument())
						if (ins->name() == arg) {
							// we have this already
							status.setEnabled(false);
							return true;
						}
		} else
			status.setEnabled(false);
		return true;
	}

	default:
		// Dispatch only to text_ if the cursor is inside
		// the text_. It is not for context menus (bug 5797).
		bool ret = false;
		if (cur.text() == &text_)
			ret = text_.getStatus(cur, cmd, status);

		if (!ret)
			ret = Inset::getStatus(cur, cmd, status);
		return ret;
	}
}
Ejemplo n.º 11
0
void InsetTOC::doDispatch(Cursor & cur, FuncRequest & cmd) {
	switch (cmd.action()) {
	case LFUN_MOUSE_RELEASE:
		if (!cur.selection() && cmd.button() == mouse_button::button1) {
			cur.bv().showDialog("toc", params2string(params()));
			cur.dispatched();
		}
		break;
	
	default:
		InsetCommand::doDispatch(cur, cmd);
	}
}
Ejemplo n.º 12
0
bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY:
		if (cmd.getArg(0) == "ert") {
			status.setEnabled(true);
			return true;
		}
		//fall through

	default:
		return InsetCollapsable::getStatus(cur, cmd, status);
	}
}
Ejemplo n.º 13
0
DispatchResult const & GuiCommandBuffer::dispatch(string const & str)
{
	if (str.empty()) {
		static DispatchResult empty_dr;
		return empty_dr;
	}

	history_.push_back(trim(str));
	history_pos_ = history_.end();
	upPB->setEnabled(history_pos_ != history_.begin());
	downPB->setEnabled(history_pos_ != history_.end());
	FuncRequest func = lyxaction.lookupFunc(str);
	func.setOrigin(FuncRequest::COMMANDBUFFER);
	return lyx::dispatch(func);
}
Ejemplo n.º 14
0
void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY:
		if (cmd.getArg(0) == "ert") {
			cur.recordUndoInset(ATOMIC_UNDO, this);
			setStatus(cur, string2params(to_utf8(cmd.argument())));
			break;
		}
		//fall-through
	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}

}
Ejemplo n.º 15
0
void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	if (cmd.action() == LFUN_INSET_MODIFY) {
		buffer().removeBiblioTempFiles();
		cache.recalculate = true;
	}
	InsetCommand::doDispatch(cur, cmd);
}
Ejemplo n.º 16
0
void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY: {
		InsetBranchParams params;
		InsetBranch::string2params(to_utf8(cmd.argument()), params);

		cur.recordUndoInset(ATOMIC_UNDO, this);
		params_.branch = params.branch;
		// what we really want here is a TOC update, but that means
		// a full buffer update
		cur.forceBufferUpdate();
		break;
	}
	case LFUN_BRANCH_ACTIVATE:
	case LFUN_BRANCH_DEACTIVATE: {
		// FIXME: I do not like this cast, but have no other idea...
		Buffer const * buf = buffer().masterBuffer();
		BranchList const & branchlist = buf->params().branchlist();
		Branch * our_branch = const_cast<Branch *>(branchlist.find(params_.branch));
		if (!our_branch) {
			// child only?
			our_branch = buffer().params().branchlist().find(params_.branch);
			if (!our_branch)
				break;
		}
		bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE);
		if (our_branch->isSelected() != activate) {
			our_branch->setSelected(activate);
			cur.forceBufferUpdate();
		}
		break;
	}
	case LFUN_INSET_TOGGLE:
		if (cmd.argument() == "assign")
			setStatus(cur, isBranchSelected() ? Open : Collapsed);
		else
			InsetCollapsable::doDispatch(cur, cmd);
		break;

	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 17
0
void InsetCaption::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		if (cmd.getArg(0) == "changetype") {
			cur.recordUndoInset(ATOMIC_UNDO, this);
			type_ = cmd.getArg(1);
			cur.forceBufferUpdate();
			break;
		}
	}

	default:
		InsetText::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 18
0
void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		cur.recordUndoInset(ATOMIC_UNDO, this);
		InsetListings::string2params(to_utf8(cmd.argument()), params());
		break;
	}

	case LFUN_INSET_DIALOG_UPDATE:
		cur.bv().updateDialog("listings", params2string(params()));
		break;

	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 19
0
void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
{
	Inset * inset = itemInset();
	FuncRequest tmpcmd(cmd);

	QModelIndex const & index = tocTV->currentIndex();
	TocItem const & item =
		gui_view_.tocModels().currentItem(current_type_, index);

	// Start an undo group.
	cur.beginUndoGroup();

	switch (cmd.action())
	{
	case LFUN_CHANGE_ACCEPT:
	case LFUN_CHANGE_REJECT:
	case LFUN_SECTION_SELECT:
		dispatch(item.action());
		cur.dispatch(tmpcmd);
		break;

	case LFUN_LABEL_COPY_AS_REF: {
		// For labels in math, we need to supply the label as a string
		FuncRequest label_copy(LFUN_LABEL_COPY_AS_REF, item.asString());
		if (inset)
			inset->dispatch(cur, label_copy);
		break;
	}
	
	case LFUN_OUTLINE_UP:
	case LFUN_OUTLINE_DOWN:
	case LFUN_OUTLINE_IN:
	case LFUN_OUTLINE_OUT:
		outline(cmd.action());
		break;

	default:
		if (inset)
			inset->dispatch(cur, tmpcmd);
	}
	cur.endUndoGroup();
}
Ejemplo n.º 20
0
bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
		FuncStatus & flag) const
{
	switch (cmd.action()) {
	case LFUN_TABULAR_FEATURE: {
		string s = cmd.getArg(0);
		if (s == "add-vline-left" || s == "add-vline-right") {
			flag.message(bformat(
				from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
				name_));
			flag.setEnabled(false);
			return true;
		}
		break;
	}
	default:
		break;
	}
	return InsetMathGrid::getStatus(cur, cmd, flag);
}
Ejemplo n.º 21
0
bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
		FuncStatus & flag) const
{
	switch (cmd.action()) {
	case LFUN_INSET_DISSOLVE:
		if (!cmd.argument().empty()) {
			InsetLayout const & il = getLayout();
			InsetLayout::InsetLyXType const type = 
				translateLyXType(to_utf8(cmd.argument()));
			if (il.lyxtype() == type) {
				FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
				return InsetCollapsable::getStatus(cur, temp_cmd, flag);
			} else
				return false;
		}
		// fall-through
	default:
		return InsetCollapsable::getStatus(cur, cmd, flag);
	}
}
Ejemplo n.º 22
0
bool InsetInfo::validateModifyArgument(docstring const & arg) const
{
	string type;
	string const name = trim(split(to_utf8(arg), type, ' '));

	switch (nameTranslator().find(type)) {
	case UNKNOWN_INFO:
		return false;

	case SHORTCUT_INFO:
	case SHORTCUTS_INFO:
	case MENU_INFO:
	case ICON_INFO: {
		FuncRequest func = lyxaction.lookupFunc(name);
		return func.action() != LFUN_UNKNOWN_ACTION;
	}

	case LYXRC_INFO: {
		ostringstream oss;
		lyxrc.write(oss, true, name);
		return !oss.str().empty();
	}

	case PACKAGE_INFO:
	case TEXTCLASS_INFO:
		return true;

	case BUFFER_INFO:
		if (name == "name" || name == "path" || name == "class")
			return true;
		if (name == "vcs-revision" || name == "vcs-tree-revision" ||
		       name == "vcs-author" || name == "vcs-date" || name == "vcs-time")
			return buffer().lyxvc().inUse();
		return false;

	case LYX_INFO:
		return name == "version";
	}

	return false;
}
Ejemplo n.º 23
0
bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
		FuncStatus & flag) const
{
	switch (cmd.action()) {
	case LFUN_INSET_EDIT:
		flag.setEnabled(getParam("type").empty() || getParam("type") == "file:");
		return true;

	default:
		return InsetCommand::getStatus(cur, cmd, flag);
	}
}
Ejemplo n.º 24
0
CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name, 
					  string const & def)
{
	string const name2 = trim(name);

	if (name2.empty()) 
		return CmdDefNameEmpty;

	if (cmdDefMap.find(name) != cmdDefMap.end())
		return CmdDefExists;

	FuncRequest	func = lyxaction.lookupFunc(def);
	if (func.action() == LFUN_NOACTION
		|| func.action() == LFUN_UNKNOWN_ACTION) {
			return CmdDefInvalid;
	}

	cmdDefMap[name2] = func;

	return CmdDefOk;
}
Ejemplo n.º 25
0
bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {
	case LFUN_INSET_DIALOG_UPDATE:
	case LFUN_INSET_MODIFY:
		status.setEnabled(true);
		return true;
	default:
		return InsetCommand::getStatus(cur, cmd, status);
	}
}
Ejemplo n.º 26
0
void InsetHyperlink::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_EDIT:
		viewTarget();
		break;

	default:
		InsetCommand::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 27
0
void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY:
		cur.recordUndoInset(ATOMIC_UNDO, this);
		string2params(to_utf8(cmd.argument()), params_);
		setButtonLabel();
		// what we really want here is a TOC update, but that means
		// a full buffer update
		cur.forceBufferUpdate();
		break;

	case LFUN_INSET_DIALOG_UPDATE:
		cur.bv().updateDialog("note", params2string(params()));
		break;

	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 28
0
void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		InsetCommandParams p(NOMENCL_PRINT_CODE);
		// FIXME UNICODE
		InsetCommand::string2params("nomencl_print",
			to_utf8(cmd.argument()), p);
		if (p.getCmdName().empty()) {
			cur.noScreenUpdate();
			break;
		}
		setParams(p);
		break;
	}

	default:
		InsetCommand::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 29
0
void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {
	case LFUN_INSET_DISSOLVE:
		if (!cmd.argument().empty()) {
			InsetLayout const & il = getLayout();
			InsetLayout::InsetLyXType const type = 
				translateLyXType(to_utf8(cmd.argument()));
			
			if (il.lyxtype() == type) {
				FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
				InsetCollapsable::doDispatch(cur, temp_cmd);
			} else
				cur.undispatched();
			break;
		}
		// fall-through
	default:
		InsetCollapsable::doDispatch(cur, cmd);
		break;
	}
}
Ejemplo n.º 30
0
void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		InsetCommandParams p(LINE_CODE);
		// FIXME UNICODE
		InsetCommand::string2params(to_utf8(cmd.argument()), p);
		if (p.getCmdName().empty()) {
			cur.noScreenUpdate();
			break;
		}
		cur.recordUndo();
		setParams(p);
		break;
	}

	default:
		InsetCommand::doDispatch(cur, cmd);
		break;
	}
}