Пример #1
0
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
		    && clickable(cur.bv(), cmd.x(), cmd.y()) && 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;
	}
}
Пример #2
0
void GuiCompleter::asyncUpdatePopup()
{
	Cursor cur = gui_->bufferView().cursor();
	if (!cur.inset().completionSupported(cur)
		  || !cur.bv().paragraphVisible(cur)) {
		popupVisible_ = false;
		return;
	}

	// get dimensions of completion prefix
	Dimension dim;
	int x;
	int y;
	cur.inset().completionPosAndDim(cur, x, y, dim);
	
	// and calculate the rect of the popup
	QRect rect;
	if (popup()->layoutDirection() == Qt::RightToLeft)
		rect = QRect(x + dim.width() - 200, y - dim.ascent() - 3, 200, dim.height() + 6);
	else
		rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
	
	// Resize the columns in the popup.
	// This should really be in the constructor. But somehow the treeview
	// has a bad memory about it and we have to tell him again and again.
	QTreeView * listView = static_cast<QTreeView *>(popup());
	listView->header()->setStretchLastSection(false);
	listView->header()->setResizeMode(0, QHeaderView::Stretch);
	listView->header()->setResizeMode(1, QHeaderView::Fixed);
	listView->header()->resizeSection(1, 22);
	
	// show/update popup
	complete(rect);
}
Пример #3
0
bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
{
	idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
	if (cur.idx() == target)
		return false;
	cur.idx() = target;
	cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
	return true;
}
Пример #4
0
bool InsetMathFracBase::idxUpDown(Cursor & cur, bool up) const
{
	// If we only have one cell, target = 0, otherwise
	// target = up ? 0 : 1, since upper cell has idx 0
	InsetMath::idx_type target = nargs() > 1 ? !up : 0;
	if (cur.idx() == target)
		return false;
	cur.idx() = target;
	cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
	return true;
}
Пример #5
0
bool reverseDirectionNeeded(Cursor const & cur)
{
	/*
	 * We determine the directions based on the direction of the
	 * bottom() --- i.e., outermost --- paragraph, because that is
	 * the only way to achieve consistency of the arrow's movements
	 * within a paragraph, and thus avoid situations in which the
	 * cursor gets stuck.
	 */
	return cur.bottom().paragraph().isRTL(cur.bv().buffer().params());
}
Пример #6
0
void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate)
{
	// value which should be kept selected
	QString old = currentCompletion();
	if (old.length() == 0)
		old = last_selection_;

	// set whether rtl
	bool rtl = false;
	if (cur.inTexted()) {
		Paragraph const & par = cur.paragraph();
		Font const & font =
			par.getFontSettings(cur.bv().buffer().params(), cur.pos());
		rtl = font.isVisibleRightToLeft();
	}
	popup()->setLayoutDirection(rtl ? Qt::RightToLeft : Qt::LeftToRight);

	// set new model
	CompletionList const * list = cur.inset().createCompletionList(cur);
	model_->setList(list);
	modelActive_ = true;
	if (list->sorted())
		setModelSorting(QCompleter::CaseSensitivelySortedModel);
	else
		setModelSorting(QCompleter::UnsortedModel);

	// set prefix
	QString newPrefix = toqstr(cur.inset().completionPrefix(cur));
	if (newPrefix != completionPrefix())
		setCompletionPrefix(newPrefix);

	// show popup
	if (popupUpdate)
		updatePopup(cur);

	// restore old selection
	setCurrentCompletion(old);
	
	// if popup is not empty, the new selection will
	// be our last valid one
	if (popupVisible() || inlineVisible()) {
		QString const & s = currentCompletion();
		if (s.length() > 0)
			last_selection_ = s;
		else
			last_selection_ = old;
	}

	// show inline completion
	if (inlineUpdate)
		updateInline(cur, currentCompletion());
}
Пример #7
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);
	}
}
Пример #8
0
bool InsetMathFrac::idxForward(Cursor & cur) const
{
	InsetMath::idx_type target = 0;
	if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
		if (nargs() == 3)
			target = 0;
		else if (nargs() == 2)
			target = 1;
	} else
		return false;
	if (cur.idx() == target)
		return false;
	cur.idx() = target;
	cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
	return true;
}
Пример #9
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;
	}
}
Пример #10
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;
	}
}
Пример #11
0
void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
{
	switch (cmd.action()) {
	case LFUN_INSET_MODIFY: {
		if (cmd.getArg(0) == "changetype") {
			cur.recordUndo();
			p_.setCmdName(cmd.getArg(1));
			cur.forceBufferUpdate();
			initView();
			break;
		}
		InsetCommandParams p(p_.code());
		InsetCommand::string2params(to_utf8(cmd.argument()), p);
		if (p.getCmdName().empty())
			cur.noScreenUpdate();
		else {
			cur.recordUndo();
			setParams(p);
		}
		// FIXME We might also want to check here if this one is in the TOC.
		// But I think most of those are labeled.
		if (isLabeled())
			cur.forceBufferUpdate();
		break;
	}

	case LFUN_INSET_DIALOG_UPDATE: {
		string const name = to_utf8(cmd.argument());
		cur.bv().updateDialog(name, params2string(params()));
		break;
	}

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

}
Пример #12
0
void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y, 
	Dimension & dim) const
{
	TextMetrics const & tm = cur.bv().textMetrics(&text_);
	tm.completionPosAndDim(cur, x, y, dim);
}
Пример #13
0
FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur,
	Clipboard::GraphicsType & type) const
{
	// create file dialog filter according to the existing types in the clipboard
	vector<Clipboard::GraphicsType> types;
	if (hasGraphicsContents(Clipboard::EmfGraphicsType))
		types.push_back(Clipboard::EmfGraphicsType);
	if (hasGraphicsContents(Clipboard::WmfGraphicsType))
		types.push_back(Clipboard::WmfGraphicsType);
	if (hasGraphicsContents(Clipboard::LinkBackGraphicsType))
		types.push_back(Clipboard::LinkBackGraphicsType);
	if (hasGraphicsContents(Clipboard::PdfGraphicsType))
		types.push_back(Clipboard::PdfGraphicsType);
	if (hasGraphicsContents(Clipboard::PngGraphicsType))
		types.push_back(Clipboard::PngGraphicsType);
	if (hasGraphicsContents(Clipboard::JpegGraphicsType))
		types.push_back(Clipboard::JpegGraphicsType);
	
	LASSERT(!types.empty(), /**/);
	
	// select prefered type if AnyGraphicsType was passed
	if (type == Clipboard::AnyGraphicsType)
		type = types.front();
	
	// which extension?
	map<Clipboard::GraphicsType, string> extensions;
	map<Clipboard::GraphicsType, docstring> typeNames;
	
	extensions[Clipboard::EmfGraphicsType] = "emf";
	extensions[Clipboard::WmfGraphicsType] = "wmf";
	extensions[Clipboard::LinkBackGraphicsType] = "linkback";
	extensions[Clipboard::PdfGraphicsType] = "pdf";
	extensions[Clipboard::PngGraphicsType] = "png";
	extensions[Clipboard::JpegGraphicsType] = "jpeg";
	
	typeNames[Clipboard::EmfGraphicsType] = _("Enhanced Metafile");
	typeNames[Clipboard::WmfGraphicsType] = _("Windows Metafile");
	typeNames[Clipboard::LinkBackGraphicsType] = _("LinkBack PDF");
	typeNames[Clipboard::PdfGraphicsType] = _("PDF");
	typeNames[Clipboard::PngGraphicsType] = _("PNG");
	typeNames[Clipboard::JpegGraphicsType] = _("JPEG");
	
	// find unused filename with primary extension
	string document_path = cur.buffer()->fileName().onlyPath().absFileName();
	unsigned newfile_number = 0;
	FileName filename;
	do {
		++newfile_number;
		filename = FileName(addName(document_path,
			to_utf8(_("pasted"))
			+ convert<string>(newfile_number) + "."
			+ extensions[type]));
	} while (filename.isReadableFile());
	
	while (true) {
		// create file type filter, putting the prefered on to the front
		QStringList filter;
		for (size_t i = 0; i != types.size(); ++i) {
			docstring s = bformat(_("%1$s Files"), typeNames[types[i]])
				+ " (*." + from_ascii(extensions[types[i]]) + ")";
			if (types[i] == type)
				filter.prepend(toqstr(s));
			else
				filter.append(toqstr(s));
		}
		filter = fileFilters(filter.join(";;"));
		
		// show save dialog for the graphic
		FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
		FileDialog::Result result =
		dlg.save(toqstr(filename.onlyPath().absFileName()), filter,
			 toqstr(filename.onlyFileName()));
		
		if (result.first == FileDialog::Later)
			return FileName();
		
		string newFilename = fromqstr(result.second);
		if (newFilename.empty()) {
			cur.bv().message(_("Canceled."));
			return FileName();
		}
		filename.set(newFilename);
		
		// check the extension (the user could have changed it)
		if (!suffixIs(ascii_lowercase(filename.absFileName()),
			      "." + extensions[type])) {
			// the user changed the extension. Check if the type is available
			size_t i;
			for (i = 1; i != types.size(); ++i) {
				if (suffixIs(ascii_lowercase(filename.absFileName()),
					     "." + extensions[types[i]])) {
					type = types[i];
					break;
				}
			}
			
			// invalid extension found, or none at all. In the latter
			// case set the default extensions.
			if (i == types.size()
			    && filename.onlyFileName().find('.') == string::npos) {
				filename.changeExtension("." + extensions[type]);
			}
		}
		
		// check whether the file exists and warn the user
		if (!filename.exists())
			break;
		int ret = frontend::Alert::prompt(
			_("Overwrite external file?"),
			bformat(_("File %1$s already exists, do you want to overwrite it?"),
			from_utf8(filename.absFileName())), 1, 1, _("&Overwrite"), _("&Cancel"));
		if (ret == 0)
			// overwrite, hence break the dialog loop
			break;
		
		// not overwrite, hence show the dialog again (i.e. loop)
	}
	
	return filename;
}
Пример #14
0
bool isWithinRtlParagraph(Cursor const & cur)
{
	return cur.innerParagraph().isRTL(cur.bv().buffer().params());
}