コード例 #1
0
ファイル: GuiToolbar.cpp プロジェクト: cburschka/lyx
Action * GuiToolbar::addItem(ToolbarItem const & item)
{
	QString text = toqstr(item.label_);
	// Get the keys bound to this action, but keep only the
	// first one later
	KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func_);
	if (!bindings.empty())
		text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";

	Action * act = new Action(item.func_, getIcon(*item.func_, false), text,
	                          text, this);
	actions_.append(act);
	return act;
}
コード例 #2
0
ファイル: InsetInfo.cpp プロジェクト: bsjung/Lyx
void InsetInfo::updateInfo()
{
	BufferParams const & bp = buffer().params();	

	switch (type_) {
	case UNKNOWN_INFO:
		error("Unknown Info: %1$s");
		break;
	case SHORTCUT_INFO:
	case SHORTCUTS_INFO: {
		FuncRequest const func = lyxaction.lookupFunc(name_);
		if (func.action() == LFUN_UNKNOWN_ACTION) {
			error("Unknown action %1$s");
			break;
		}
		KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func);
		if (bindings.empty()) {
			// It is impropriate to use error() for undefined shortcut
			setText(_("undefined"));
			break;
		}
		if (type_ == SHORTCUT_INFO)
			setText(bindings.begin()->print(KeySequence::Portable));
		else
			setText(theTopLevelKeymap().printBindings(func, KeySequence::Portable));
		break;
	}
	case LYXRC_INFO: {
		ostringstream oss;
		if (name_.empty()) {
			setText(_("undefined"));
			break;
		}
		lyxrc.write(oss, true, name_);
		string result = oss.str();
		if (result.size() < 2) {
			setText(_("undefined"));
			break;
		}
		string::size_type loc = result.rfind("\n", result.size() - 2);
		loc = loc == string::npos ? 0 : loc + 1;
		if (result.size() < loc + name_.size() + 1
			  || result.substr(loc + 1, name_.size()) != name_) {
			setText(_("undefined"));
			break;
		}
		// remove leading comments and \\name and space
		result = result.substr(loc + name_.size() + 2);
		
		// remove \n and ""
		result = rtrim(result, "\n");
		result = trim(result, "\"");
		setText(from_utf8(result));
		break;
	}
	case PACKAGE_INFO:
		// check in packages.lst
		setText(LaTeXFeatures::isAvailable(name_) ? _("yes") : _("no"));
		break;

	case TEXTCLASS_INFO: {
		// name_ is the class name
		LayoutFileList const & list = LayoutFileList::get();
		bool available = false;
		if (list.haveClass(name_))
			available = list[name_].isTeXClassAvailable();
		setText(available ? _("yes") : _("no"));
		break;
	}
	case MENU_INFO: {
		docstring_list names;
		FuncRequest const func = lyxaction.lookupFunc(name_);
		if (func.action() == LFUN_UNKNOWN_ACTION) {
			error("Unknown action %1$s");
			break;
		}
		// iterate through the menubackend to find it
		if (!theApp()->searchMenu(func, names)) {
			error("No menu entry for action %1$s");
			break;
		}
		// if found, return its path.
		clear();
		Paragraph & par = paragraphs().front();
		Font const f(inherit_font, buffer().params().language);
		//Font fu = f;
		//fu.fontInfo().setUnderbar(FONT_ON);
		docstring_list::const_iterator beg = names.begin();
		docstring_list::const_iterator end = names.end();
		for (docstring_list::const_iterator it = beg ; 
		     it != end ; ++it) {
			// do not insert > for the top level menu item
			if (it != beg)
				par.insertInset(par.size(), new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
						Change(Change::UNCHANGED));
			//FIXME: add proper underlines here. This
			// involves rewriting searchMenu used above to
			// return a vector of menus. If we do not do
			// that, we might as well use below
			// Paragraph::insert on each string (JMarc)
			for (size_type i = 0; i != it->length(); ++i)
				par.insertChar(par.size(), (*it)[i], 
					       f, Change(Change::UNCHANGED));
		}
		break;
	}
	case ICON_INFO: {
		FuncRequest func = lyxaction.lookupFunc(name_);
		docstring icon_name = theApp()->iconName(func, true);
		//FIXME: We should use the icon directly instead of
		// going through FileName. The code below won't work
		// if the icon is embedded in the executable through
		// the Qt resource system.
		FileName file(to_utf8(icon_name));
		if (!file.exists())
			break;
		InsetGraphics * inset = new InsetGraphics(buffer_);
		InsetGraphicsParams igp;
		igp.filename = file;
		inset->setParams(igp);
		clear();
		paragraphs().front().insertInset(0, inset, 
						 Change(Change::UNCHANGED));
		break;
	}
	case BUFFER_INFO: {
		if (name_ == "name") {
			setText(from_utf8(buffer().fileName().onlyFileName()));
			break;
		}
		if (name_ == "path") {
			setText(from_utf8(buffer().filePath()));
			break;
		}
		if (name_ == "class") {
			setText(from_utf8(bp.documentClass().name()));
			break;
		}
		
		// everything that follows is for version control.
		// nothing that isn't version control should go below this line.
		if (!buffer().lyxvc().inUse()) {
			setText(_("No version control"));
			break;
		}
		LyXVC::RevisionInfo itype = LyXVC::Unknown;
		if (name_ == "vcs-revision")
			itype = LyXVC::File;
		else if (name_ == "vcs-tree-revision")
			itype = LyXVC::Tree;
		else if (name_ == "vcs-author")
			itype = LyXVC::Author;
		else if (name_ == "vcs-time")
			itype = LyXVC::Time;
		else if (name_ == "vcs-date")
			itype = LyXVC::Date;
		string binfo = buffer().lyxvc().revisionInfo(itype);
		if (binfo.empty())
			setText(bformat(_("[[%1$s unknown]]"), from_utf8(name_)));
		else
			setText(from_utf8(binfo));
		break;
	}
	case LYX_INFO:
		if (name_ == "version")
			setText(from_ascii(PACKAGE_VERSION));
		break;
	}
}