typedef shared_ptr<Dialog> DialogPtr;
-} // namespace anon
+} // namespace
class GuiView::GuiViewPrivate
GuiView::GuiView(int id)
: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
- command_execute_(false), minibuffer_focus_(false)
+ command_execute_(false), minibuffer_focus_(false), devel_mode_(false)
{
connect(this, SIGNAL(bufferViewChanged()),
this, SLOT(onBufferViewChanged()));
// Start autosave timer
if (lyxrc.autosave) {
- d.autosave_timeout_.timeout.connect(bind(&GuiView::autoSave, this));
+ // The connection is closed when this is destroyed.
+ d.autosave_timeout_.timeout.connect([this](){ autoSave();});
d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
d.autosave_timeout_.start();
}
busyanim->start();
busylabel->hide();
- connect(&d.processing_thread_watcher_, SIGNAL(started()),
+ connect(&d.processing_thread_watcher_, SIGNAL(started()),
busylabel, SLOT(show()));
- connect(&d.processing_thread_watcher_, SIGNAL(finished()),
+ connect(&d.processing_thread_watcher_, SIGNAL(finished()),
busylabel, SLOT(hide()));
QFontMetrics const fm(statusBar()->fontMetrics());
- int const roheight = max(int(d.normalIconSize), fm.height());
- QSize const rosize(roheight, roheight);
- QPixmap readonly = QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")).pixmap(rosize);
+ int const iconheight = max(int(d.normalIconSize), fm.height());
+ QSize const iconsize(iconheight, iconheight);
+
+ QPixmap shellescape = QIcon(getPixmap("images/", "emblem-shellescape", "svgz,png")).pixmap(iconsize);
+ shell_escape_ = new QLabel(statusBar());
+ shell_escape_->setPixmap(shellescape);
+ shell_escape_->setScaledContents(true);
+ shell_escape_->setAlignment(Qt::AlignCenter);
+ shell_escape_->setContextMenuPolicy(Qt::CustomContextMenu);
+ shell_escape_->setToolTip(qt_("WARNING: LaTeX is allowed to execute "
+ "external commands for this document. "
+ "Right click to change."));
+ SEMenu * menu = new SEMenu(this);
+ connect(shell_escape_, SIGNAL(customContextMenuRequested(QPoint)),
+ menu, SLOT(showMenu(QPoint)));
+ shell_escape_->hide();
+ statusBar()->addPermanentWidget(shell_escape_);
+
+ QPixmap readonly = QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")).pixmap(iconsize);
read_only_ = new QLabel(statusBar());
read_only_->setPixmap(readonly);
read_only_->setScaledContents(true);
}
+void GuiView::disableShellEscape()
+{
+ BufferView * bv = documentBufferView();
+ if (!bv)
+ return;
+ theSession().shellescapeFiles().remove(bv->buffer().absFileName());
+ bv->buffer().params().shell_escape = false;
+ bv->processUpdateFlags(Update::Force);
+}
+
+
QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
{
QVector<GuiWorkArea*> areas;
Buffer::ExportStatus const status = watcher->result();
handleExportStatus(this, status, d.processing_format);
-
+
updateToolbars();
BufferView const * const bv = currentBufferView();
if (bv && !bv->buffer().errorList("Export").empty()) {
void GuiView::saveLayout() const
{
QSettings settings;
- settings.setValue("zoom", lyxrc.currentZoom);
+ settings.setValue("zoom_ratio", zoom_ratio_);
+ settings.setValue("devel_mode", devel_mode_);
settings.beginGroup("views");
settings.beginGroup(QString::number(id_));
#if defined(Q_WS_X11) || defined(QPA_XCB)
void GuiView::saveUISettings() const
{
+ QSettings settings;
+
// Save the toolbar private states
ToolbarMap::iterator end = d.toolbars_.end();
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
- it->second->saveSession();
+ it->second->saveSession(settings);
// Now take care of all other dialogs
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
for (; it!= d.dialogs_.end(); ++it)
- it->second->saveSession();
+ it->second->saveSession(settings);
}
bool GuiView::restoreLayout()
{
QSettings settings;
- lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt();
- lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<docstring>(lyxrc.currentZoom)));
+ zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
+ // Actual zoom value: default zoom + fractional offset
+ int zoom = lyxrc.defaultZoom * zoom_ratio_;
+ if (zoom < static_cast<int>(zoom_min_))
+ zoom = zoom_min_;
+ lyxrc.currentZoom = zoom;
+ devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
settings.beginGroup("views");
settings.beginGroup(QString::number(id_));
QString const icon_key = "icon_size";
if (!restoreState(settings.value("layout").toByteArray(), 0))
initToolbars();
-
+
// init the toolbars that have not been restored
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::iterator end = guiApp->toolbars().end();
LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
if (!GuiViewPrivate::busyBuffers.isEmpty()) {
- Alert::warning(_("Exit LyX"),
+ Alert::warning(_("Exit LyX"),
_("LyX could not be closed because documents are being processed by LyX."));
close_event->setAccepted(false);
return;
// Tell Qt whether the current document is changed
setWindowModified(!buf.isClean());
+ if (buf.params().shell_escape)
+ shell_escape_->show();
+ else
+ shell_escape_->hide();
+
if (buf.hasReadonlyFlag())
read_only_->show();
else
if (msg.isEmpty()) {
BufferView const * bv = currentBufferView();
if (bv)
- msg = toqstr(bv->cursor().currentState());
+ msg = toqstr(bv->cursor().currentState(devel_mode_));
else
msg = qt_("Welcome to LyX!");
}
return;
}
QApplication::restoreOverrideCursor();
- updateLayoutList();
+ updateLayoutList();
}
theGuiApp()->setCurrentView(this);
d.current_work_area_ = wa;
-
+
// We need to reset this now, because it will need to be
// right if the tabWorkArea gets reset in the for loop. We
// will change it back if we aren't in that case.
for (int i = 0; i != d.splitter_->count(); ++i) {
if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
- LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea()
+ LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea()
<< ", Current main wa: " << currentMainWorkArea());
return;
}
}
-
+
d.current_main_work_area_ = old_cmwa;
-
+
LYXERR(Debug::DEBUG, "This is not a tabbed wa");
on_currentWorkAreaChanged(wa);
BufferView & bv = wa->bufferView();
}
-void GuiView::setBuffer(Buffer * newBuffer)
+void GuiView::setBuffer(Buffer * newBuffer, bool switch_to)
{
LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
LASSERT(newBuffer, return);
-
+
GuiWorkArea * wa = workArea(*newBuffer);
if (wa == 0) {
setBusy(true);
}
connectBuffer(*newBuffer);
connectBufferView(wa->bufferView());
- setCurrentWorkArea(wa);
+ if (switch_to)
+ setCurrentWorkArea(wa);
}
enable = d.tabWorkAreaCount() > 1;
break;
+ case LFUN_DEVEL_MODE_TOGGLE:
+ flag.setOnOff(devel_mode_);
+ break;
+
case LFUN_TOOLBAR_TOGGLE: {
string const name = cmd.getArg(0);
if (GuiToolbar * t = toolbar(name))
case LFUN_DIALOG_TOGGLE:
flag.setOnOff(isDialogVisible(cmd.getArg(0)));
- // fall through to set "enable"
+ // to set "enable"
+ // fall through
case LFUN_DIALOG_SHOW: {
string const name = cmd.getArg(0);
if (!doc_buffer)
Buffer & buf = wa->bufferView().buffer();
if (GuiViewPrivate::busyBuffers.contains(&buf)) {
- Alert::warning(_("Close document"),
+ Alert::warning(_("Close document"),
_("Document could not be closed because it is being processed by LyX."));
return false;
}
setBuffer(&buf);
docstring file;
+ bool exists;
// FIXME: Unicode?
- if (buf.isUnnamed())
+ if (buf.isUnnamed()) {
file = from_utf8(buf.fileName().onlyFileName());
- else
- file = buf.fileName().displayName(30);
+ exists = false;
+ } else {
+ FileName filename = buf.fileName();
+ filename.refresh();
+ file = filename.displayName(30);
+ exists = filename.exists();
+ }
// Bring this window to top before asking questions.
raise();
if (ret == 1)
++ret;
} else {
- docstring const text = bformat(_("The document %1$s has unsaved changes."
- "\n\nDo you want to save the document or discard the changes?"), file);
- ret = Alert::prompt(_("Save changed document?"),
- text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
+ docstring const text = exists ?
+ bformat(_("The document %1$s has unsaved changes."
+ "\n\nDo you want to save the document or "
+ "discard the changes?"), file) :
+ bformat(_("The document %1$s has not been saved yet."
+ "\n\nDo you want to save the document or "
+ "discard it entirely?"), file);
+ docstring const title = exists ?
+ _("Save changed document?") : _("Save document?");
+ ret = Alert::prompt(title, text, 0, 2,
+ _("&Save"), _("&Discard"), _("&Cancel"));
}
switch (ret) {
{
if (!documentBufferView())
return;
-
+
if (TabWorkArea * twa = d.currentTabWorkArea()) {
Buffer * const curbuf = &documentBufferView()->buffer();
int nwa = twa->count();
bool GuiView::reloadBuffer(Buffer & buf)
{
+ currentBufferView()->cursor().reset();
Buffer::ReadStatus status = buf.reload();
return status == Buffer::ReadSuccess;
}
void GuiView::toolBarPopup(const QPoint & /*pos*/)
{
- QMenu * menu = new QMenu;
- menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
+ QMenu * menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
menu->exec(QCursor::pos());
}
if (syncFunc) {
status = (used_buffer->*syncFunc)(format, true);
} else if (previewFunc) {
- status = (used_buffer->*previewFunc)(format);
+ status = (used_buffer->*previewFunc)(format);
} else
return false;
handleExportStatus(gv_, status, format);
(void) asyncFunc;
- return (status == Buffer::ExportSuccess
+ return (status == Buffer::ExportSuccess
|| status == Buffer::PreviewSuccess);
#endif
}
dr.setMessage(_("Absolute filename expected."));
break;
}
-
+
FileName filename(fname);
if (fname.empty()) {
FileDialog dlg(qt_("Select file to insert"));
FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
QStringList(qt_("All Files (*)")));
-
+
if (result.first == FileDialog::Later || result.second.isEmpty()) {
dr.setMessage(_("Canceled."));
break;
if (!doc_buffer->isClean()) {
docstring const file =
makeDisplayPath(doc_buffer->absFileName(), 20);
- docstring text = doc_buffer->notifiesExternalModification() ?
- _("Any changes will be lost. "
+ if (doc_buffer->notifiesExternalModification()) {
+ docstring text = _("The current version will be lost. "
"Are you sure you want to load the version on disk "
- "of the document %1$s?")
- : _("Any changes will be lost. "
+ "of the document %1$s?");
+ ret = Alert::prompt(_("Reload saved document?"),
+ bformat(text, file), 1, 1,
+ _("&Reload"), _("&Cancel"));
+ } else {
+ docstring text = _("Any changes will be lost. "
"Are you sure you want to revert to the saved version "
"of the document %1$s?");
- ret = Alert::prompt(_("Revert to file on disk?"),
- bformat(text, file), 1, 1, _("&Revert"), _("&Cancel"));
+ ret = Alert::prompt(_("Revert to saved document?"),
+ bformat(text, file), 1, 1,
+ _("&Revert"), _("&Cancel"));
+ }
}
if (ret == 0) {
closeBufferAll();
break;
+ case LFUN_DEVEL_MODE_TOGGLE:
+ devel_mode_ = !devel_mode_;
+ if (devel_mode_)
+ dr.setMessage(_("Developer mode is now enabled."));
+ else
+ dr.setMessage(_("Developer mode is now disabled."));
+ break;
+
case LFUN_TOOLBAR_TOGGLE: {
string const name = cmd.getArg(0);
if (GuiToolbar * t = toolbar(name))
case LFUN_BUFFER_ZOOM_IN:
case LFUN_BUFFER_ZOOM_OUT:
case LFUN_BUFFER_ZOOM: {
- // use a signed temp to avoid overflow
- int zoom = lyxrc.currentZoom;
if (cmd.argument().empty()) {
if (cmd.action() == LFUN_BUFFER_ZOOM)
- zoom = lyxrc.zoom;
+ zoom_ratio_ = 1.0;
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
- zoom += 20;
+ zoom_ratio_ += 0.1;
else
- zoom -= 20;
+ zoom_ratio_ -= 0.1;
} else {
if (cmd.action() == LFUN_BUFFER_ZOOM)
- zoom = convert<int>(cmd.argument());
+ zoom_ratio_ = convert<int>(cmd.argument()) / double(lyxrc.defaultZoom);
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
- zoom += convert<int>(cmd.argument());
+ zoom_ratio_ += convert<int>(cmd.argument()) / 100.0;
else
- zoom -= convert<int>(cmd.argument());
+ zoom_ratio_ -= convert<int>(cmd.argument()) / 100.0;
}
+ // Actual zoom value: default zoom + fractional extra value
+ int zoom = lyxrc.defaultZoom * zoom_ratio_;
if (zoom < static_cast<int>(zoom_min_))
zoom = zoom_min_;
lyxrc.currentZoom = zoom;
- dr.setMessage(bformat(_("Zoom level is now %1$d%"), lyxrc.currentZoom));
+ dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
+ lyxrc.currentZoom, lyxrc.defaultZoom));
// The global QPixmapCache is used in GuiPainter to cache text
// painting so we must reset it.
QPixmapCache::clear();
guiApp->fontLoader().update();
- lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+ dr.screenUpdate(Update::Force | Update::FitCursor);
break;
}
doc_buffer->absFileName(),
"tex")).mangledFileName()
: doc_buffer->latexName();
- string const fulltexname =
+ string const fulltexname =
support::makeAbsPath(texname, doc_master->temppath()).absFileName();
string const mastername =
removeExtension(doc_master->latexName());
continue;
Buffer const * buffer = &(wa->bufferView().buffer());
if (inset_buffer == buffer)
- wa->scheduleRedraw();
+ wa->scheduleRedraw(true);
}
return inset_buffer;
}
-void GuiView::restartCursor()
+void GuiView::restartCaret()
{
/* When we move around, or type, it's nice to be able to see
- * the cursor immediately after the keypress.
+ * the caret immediately after the keypress.
*/
if (d.current_work_area_)
- d.current_work_area_->startBlinkingCursor();
+ d.current_work_area_->startBlinkingCaret();
// Take this occasion to update the other GUI elements.
updateDialogs();
cmpCStr(name.c_str())) != end_dialognames;
}
-} // namespace anon
+} // namespace
void GuiView::resetDialogs()
// Now update controls with current buffer.
guiApp->setCurrentView(this);
restoreLayout();
- restartCursor();
+ restartCaret();
}
}
+SEMenu::SEMenu(QWidget * parent)
+{
+ QAction * action = addAction(qt_("Disable Shell Escape"));
+ connect(action, SIGNAL(triggered()),
+ parent, SLOT(disableShellEscape()));
+}
+
+
} // namespace frontend
} // namespace lyx