}
}
#endif
+
+#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
+ // On Windows, allow bringing the LyX window to top
+ AllowSetForegroundWindow(ASFW_ANY);
+#endif
+
frontend::GuiApplication * guiApp = new frontend::GuiApplication(argc, argv);
// I'd rather do that in the constructor, but I do not think that
// the palette is accessible there.
return img_name;
}
-} // namespace anon
+} // namespace
QString themeIconName(QString const & action)
if (getPixmap(pixmap, fpath)) {
return pixmap;
}
-
+
QStringList exts = ext.split(",");
fpath = ":/" + path + name + ".";
for (int i = 0; i < exts.size(); ++i) {
QCoreApplication::setOrganizationName(app_name);
QCoreApplication::setOrganizationDomain("lyx.org");
QCoreApplication::setApplicationName(lyx_package);
+#if QT_VERSION >= 0x050000
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+#endif
qsrand(QDateTime::currentDateTime().toTime_t());
double GuiApplication::pixelRatio() const
{
#if QT_VERSION >= 0x050000
- return devicePixelRatio();
+ return qt_scale_factor * devicePixelRatio();
#else
return 1.0;
#endif
updateCurrentView(cmd, dr);
// the buffer may have been closed by one action
- if (theBufferList().isLoaded(buffer))
+ if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
buffer->undo().endUndoGroup();
d->dispatch_result_ = dr;
// if the current buffer is not that one, switch to it.
BufferView * doc_bv = current_view_ ?
current_view_->documentBufferView() : 0;
- // FIXME It's possible that doc_bv is null!!
- // See coverity #102061
- Cursor const old = doc_bv->cursor();
+ Cursor const * old = doc_bv ? &doc_bv->cursor() : 0;
if (!doc_bv || doc_bv->buffer().fileName() != tmp.filename) {
if (switchToBuffer) {
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
}
// moveToPosition try paragraph id first and then paragraph (pit, pos).
- if (!doc_bv->moveToPosition(
+ if (!doc_bv || !doc_bv->moveToPosition(
tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos))
return;
Cursor & cur = doc_bv->cursor();
- if (cur != old)
- notifyCursorLeavesOrEnters(old, cur);
+ if (old && cur != *old)
+ notifyCursorLeavesOrEnters(*old, cur);
// bm changed
if (idx == 0)
case LFUN_BUFFER_NEW:
validateCurrentView();
- if (d->views_.empty()
+ if (!current_view_
|| (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
createView(QString(), false); // keep hidden
current_view_->newDocument(to_utf8(cmd.argument()), false);
case LFUN_BUFFER_NEW_TEMPLATE:
validateCurrentView();
- if (d->views_.empty()
+ if (!current_view_
|| (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
createView();
current_view_->newDocument(to_utf8(cmd.argument()), true);
break;
case LFUN_FILE_OPEN: {
+ // FIXME: normally the code below is not needed, since getStatus makes sure that
+ // current_view_ is not null.
validateCurrentView();
// FIXME: create a new method shared with LFUN_HELP_OPEN.
string const fname = to_utf8(cmd.argument());
bool const is_open = FileName::isAbsolute(fname)
&& theBufferList().getBuffer(FileName(fname));
- if (d->views_.empty()
+ if (!current_view_
|| (!lyxrc.open_buffers_in_tabs
&& current_view_->documentBufferView() != 0
&& !is_open)) {
boost::crc_32_type crc;
crc = for_each(fname.begin(), fname.end(), crc);
createView(crc.checksum());
- // we know current_view_ is non-null, because createView sets it.
- // but let's make sure
- LASSERT(current_view_, break);
current_view_->openDocument(fname);
if (!current_view_->documentBufferView())
current_view_->close();
current_view_->showNormal();
}
} else {
- // we know !d->views.empty(), so this should be ok
- // but let's make sure
- LASSERT(current_view_, break);
current_view_->openDocument(fname);
if (cmd.origin() == FuncRequest::LYXSERVER) {
current_view_->raise();
current_view_->message(bformat(_("Opening help file %1$s..."),
makeDisplayPath(fname.absFileName())));
Buffer * buf = current_view_->loadDocument(fname, false);
-
-#ifndef DEVEL_VERSION
if (buf)
- buf->setReadonly(true);
-#else
- (void) buf;
-#endif
+ buf->setReadonly(!current_view_->develMode());
break;
}
// repeat command
string countstr;
string rest = split(argument, countstr, ' ');
- istringstream is(countstr);
- int count = 0;
- is >> count;
- //lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
- for (int i = 0; i < count; ++i)
- dispatch(lyxaction.lookupFunc(rest));
+ int const count = convert<int>(countstr);
+ // an arbitrary number to limit number of iterations
+ int const max_iter = 10000;
+ if (count > max_iter) {
+ dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter));
+ dr.setError(true);
+ } else {
+ for (int i = 0; i < count; ++i)
+ dispatch(lyxaction.lookupFunc(rest));
+ }
break;
}
dispatch(func);
}
// the buffer may have been closed by one action
- if (theBufferList().isLoaded(buffer))
+ if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
buffer->undo().endUndoGroup();
break;
}
if (current_view_ == 0)
createView();
}
- // fall through
}
-
+ // fall through
default:
// The LFUN must be for one of GuiView, BufferView, Buffer or Cursor;
// let's try that:
void GuiApplication::processFuncRequestQueue()
{
while (!d->func_request_queue_.empty()) {
- processFuncRequest(d->func_request_queue_.front());
+ // take the item from the stack _before_ processing the
+ // request in order to avoid race conditions from nested
+ // or parallel requests (see #10406)
+ FuncRequest const fr(d->func_request_queue_.front());
d->func_request_queue_.pop();
+ processFuncRequest(fr);
}
}
LYXERR(Debug::GUI, "About to create new window with ID " << id);
GuiView * view = new GuiView(id);
+ // `view' is the new current_view_. Tell coverity that is is not 0.
+ LATTEST(current_view_);
// register view
d->views_[id] = view;
}
+bool GuiApplication::unhide(Buffer * buf)
+{
+ if (!currentView())
+ return false;
+ currentView()->setBuffer(buf, false);
+ return true;
+}
+
+
Clipboard & GuiApplication::clipboard()
{
return d->clipboard_;
// not be added at all (help files).
for (size_t i = 0; i < lastopened.size(); ++i) {
FileName const & file_name = lastopened[i].file_name;
- if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs
+ if (!current_view_ || (!lyxrc.open_buffers_in_tabs
&& current_view_->documentBufferView() != 0)) {
boost::crc_32_type crc;
string const & fname = file_name.absFileName();
const QFontInfo fi(font);
return fi.fixedPitch();
}
-}
+} // namespace
QFont const GuiApplication::typewriterSystemFont()
#endif
// In release mode, try to exit gracefully.
this->exit(1);
-
+ // FIXME: GCC 7 thinks we can fall through here. Can we?
+ // fall through
case BufferException: {
if (!current_view_ || !current_view_->documentBufferView())
return false;