void operator=(GuiViewPrivate const &);
public:
GuiViewPrivate(GuiView * gv)
- : gv_(gv), current_work_area_(0), current_main_work_area_(0),
- layout_(0), autosave_timeout_(5000),
+ : gv_(gv), current_work_area_(nullptr), current_main_work_area_(nullptr),
+ layout_(nullptr), autosave_timeout_(5000),
in_show_(false)
{
// hardcode here the platform specific icon size
return icon_size;
}
+ static Buffer::ExportStatus previewAndDestroy(Buffer const * orig,
+ Buffer * buffer, string const & format);
+ static Buffer::ExportStatus exportAndDestroy(Buffer const * orig,
+ Buffer * buffer, string const & format);
+ static Buffer::ExportStatus compileAndDestroy(Buffer const * orig,
+ Buffer * buffer, string const & format);
+ static docstring autosaveAndDestroy(Buffer const * orig, Buffer * buffer);
+
+ template<class T>
+ static Buffer::ExportStatus runAndDestroy(const T& func,
+ Buffer const * orig, Buffer * buffer, string const & format);
+
+ // TODO syncFunc/previewFunc: use bind
+ bool asyncBufferProcessing(string const & argument,
+ Buffer const * used_buffer,
+ docstring const & msg,
+ Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
+ Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
+ Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
+ bool allow_async);
+
+ QVector<GuiWorkArea*> guiWorkAreas();
+
public:
GuiView * gv_;
GuiWorkArea * current_work_area_;
///
map<string, DialogPtr> dialogs_;
- unsigned int smallIconSize;
- unsigned int normalIconSize;
- unsigned int bigIconSize;
- unsigned int hugeIconSize;
- unsigned int giantIconSize;
///
QTimer statusbar_timer_;
/// auto-saving of buffers
Timeout autosave_timeout_;
- /// flag against a race condition due to multiclicks, see bug #1119
- bool in_show_;
///
TocModels toc_models_;
string processing_format;
static QSet<Buffer const *> busyBuffers;
- static Buffer::ExportStatus previewAndDestroy(Buffer const * orig,
- Buffer * buffer, string const & format);
- static Buffer::ExportStatus exportAndDestroy(Buffer const * orig,
- Buffer * buffer, string const & format);
- static Buffer::ExportStatus compileAndDestroy(Buffer const * orig,
- Buffer * buffer, string const & format);
- static docstring autosaveAndDestroy(Buffer const * orig, Buffer * buffer);
- template<class T>
- static Buffer::ExportStatus runAndDestroy(const T& func,
- Buffer const * orig, Buffer * buffer, string const & format);
-
- // TODO syncFunc/previewFunc: use bind
- bool asyncBufferProcessing(string const & argument,
- Buffer const * used_buffer,
- docstring const & msg,
- Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
- Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
- Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
- bool allow_async);
+ unsigned int smallIconSize;
+ unsigned int normalIconSize;
+ unsigned int bigIconSize;
+ unsigned int hugeIconSize;
+ unsigned int giantIconSize;
- QVector<GuiWorkArea*> guiWorkAreas();
+ /// flag against a race condition due to multiclicks, see bug #1119
+ bool in_show_;
};
QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
QSettings settings;
zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
// Actual zoom value: default zoom + fractional offset
- int zoom = lyxrc.defaultZoom * zoom_ratio_;
+ int zoom = (int)(lyxrc.defaultZoom * zoom_ratio_);
if (zoom < static_cast<int>(zoom_min_))
zoom = zoom_min_;
lyxrc.currentZoom = zoom;
return it->second;
LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
- return 0;
+ return nullptr;
}
{
if (d.current_work_area_)
// disconnect the current work area from all slots
- QObject::disconnect(d.current_work_area_, 0, this, 0);
+ QObject::disconnect(d.current_work_area_, nullptr, this, nullptr);
disconnectBuffer();
disconnectBufferView();
connectBufferView(wa->bufferView());
if (TabWorkArea * twa = d.currentTabWorkArea())
if (index < twa->count())
return twa->workArea(index);
- return 0;
+ return nullptr;
}
return currentWorkArea();
if (TabWorkArea * twa = d.currentTabWorkArea())
return twa->workArea(buffer);
- return 0;
+ return nullptr;
}
GuiWorkArea const * GuiView::currentMainWorkArea() const
{
if (!d.currentTabWorkArea())
- return 0;
+ return nullptr;
return d.currentTabWorkArea()->currentWorkArea();
}
GuiWorkArea * GuiView::currentMainWorkArea()
{
if (!d.currentTabWorkArea())
- return 0;
+ return nullptr;
return d.currentTabWorkArea()->currentWorkArea();
}
{
LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
if (!wa) {
- d.current_work_area_ = 0;
+ d.current_work_area_ = nullptr;
d.setBackground();
Q_EMIT bufferViewChanged();
return;
if (wa == d.current_work_area_) {
disconnectBuffer();
disconnectBufferView();
- d.current_work_area_ = 0;
- d.current_main_work_area_ = 0;
+ d.current_work_area_ = nullptr;
+ d.current_main_work_area_ = nullptr;
}
bool found_twa = false;
// Found in this tab group, and deleted the GuiWorkArea.
found_twa = true;
if (twa->count() != 0) {
- if (d.current_work_area_ == 0)
+ if (d.current_work_area_ == nullptr)
// This means that we are closing the current GuiWorkArea, so
// switch to the next GuiWorkArea in the found TabWorkArea.
setCurrentWorkArea(twa->currentWorkArea());
// should be deleted by other means.
LASSERT(found_twa, return);
- if (d.current_work_area_ == 0) {
+ if (d.current_work_area_ == nullptr) {
if (d.splitter_->count() != 0) {
TabWorkArea * twa = d.currentTabWorkArea();
setCurrentWorkArea(twa->currentWorkArea());
} else {
// No more work areas, switch to the background widget.
- setCurrentWorkArea(0);
+ setCurrentWorkArea(nullptr);
}
}
}
LASSERT(newBuffer, return);
GuiWorkArea * wa = workArea(*newBuffer);
- if (wa == 0) {
+ if (wa == nullptr) {
setBusy(true);
newBuffer->masterBuffer()->updateBuffer();
setBusy(false);
void GuiView::disconnectBuffer()
{
if (d.current_work_area_)
- d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
+ d.current_work_area_->bufferView().buffer().setGuiDelegate(nullptr);
}
void GuiView::disconnectBufferView()
{
if (d.current_work_area_)
- d.current_work_area_->bufferView().setGuiDelegate(0);
+ d.current_work_area_->bufferView().setGuiDelegate(nullptr);
}
{
return currentMainWorkArea()
? ¤tMainWorkArea()->bufferView()
- : 0;
+ : nullptr;
}
{
return currentMainWorkArea()
? ¤tMainWorkArea()->bufferView()
- : 0;
+ : nullptr;
}
BufferView * GuiView::currentBufferView()
{
- return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
+ return d.current_work_area_ ? &d.current_work_area_->bufferView() : nullptr;
}
BufferView const * GuiView::currentBufferView() const
{
- return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
+ return d.current_work_area_ ? &d.current_work_area_->bufferView() : nullptr;
}
LYXERR(Debug::INFO, "Running autoSave()");
Buffer * buffer = documentBufferView()
- ? &documentBufferView()->buffer() : 0;
+ ? &documentBufferView()->buffer() : nullptr;
if (!buffer) {
resetAutosaveTimers();
return;
{
bool enable = true;
Buffer * buf = currentBufferView()
- ? ¤tBufferView()->buffer() : 0;
+ ? ¤tBufferView()->buffer() : nullptr;
Buffer * doc_buffer = documentBufferView()
- ? &(documentBufferView()->buffer()) : 0;
+ ? &(documentBufferView()->buffer()) : nullptr;
#ifdef Q_OS_MAC
/* In LyX/Mac, when a dialog is open, the menus of the
case LFUN_MASTER_BUFFER_EXPORT:
enable = doc_buffer
- && (doc_buffer->parent() != 0
+ && (doc_buffer->parent() != nullptr
|| doc_buffer->hasChildren())
&& !d.processing_thread_watcher_.isRunning()
// this launches a dialog, which would be in the wrong Buffer
case LFUN_MASTER_BUFFER_UPDATE:
case LFUN_MASTER_BUFFER_VIEW:
enable = doc_buffer
- && (doc_buffer->parent() != 0
+ && (doc_buffer->parent() != nullptr
|| doc_buffer->hasChildren())
&& !d.processing_thread_watcher_.isRunning();
break;
break;
case LFUN_BUFFER_RESET_EXPORT:
- enable = doc_buffer != 0;
+ enable = doc_buffer != nullptr;
break;
case LFUN_BUFFER_CHILD_OPEN:
- enable = doc_buffer != 0;
+ enable = doc_buffer != nullptr;
+ break;
+
+ case LFUN_MASTER_BUFFER_FORALL: {
+ if (doc_buffer == nullptr) {
+ flag.message(from_utf8(N_("Command not allowed without a buffer open")));
+ enable = false;
+ break;
+ }
+ FuncRequest const cmdToPass = lyxaction.lookupFunc(cmd.getLongArg(0));
+ if (cmdToPass.action() == LFUN_UNKNOWN_ACTION) {
+ flag.message(from_utf8(N_("Invalid argument of master-buffer-forall")));
+ enable = false;
+ break;
+ }
+ enable = false;
+ for (Buffer * buf : doc_buffer->allRelatives()) {
+ GuiWorkArea * wa = workArea(*buf);
+ if (!wa)
+ continue;
+ if (wa->bufferView().getStatus(cmdToPass, flag)) {
+ enable = flag.enabled();
+ break;
+ }
+ }
break;
+ }
case LFUN_BUFFER_WRITE:
enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
// fall through
case LFUN_BUFFER_WRITE_AS:
case LFUN_BUFFER_WRITE_AS_TEMPLATE:
- enable = doc_buffer != 0;
+ enable = doc_buffer != nullptr;
break;
case LFUN_EXPORT_CANCEL:
case LFUN_BUFFER_CLOSE:
case LFUN_VIEW_CLOSE:
- enable = doc_buffer != 0;
+ enable = doc_buffer != nullptr;
break;
case LFUN_BUFFER_CLOSE_ALL:
break;
case LFUN_DROP_LAYOUTS_CHOICE:
- enable = buf != 0;
+ enable = buf != nullptr;
break;
case LFUN_UI_TOGGLE:
{
setBusy(true);
- Buffer * newBuffer = 0;
+ Buffer * newBuffer = nullptr;
try {
newBuffer = checkAndLoadLyXFile(filename);
} catch (ExceptionMessage const & e) {
if (!newBuffer) {
message(_("Document not loaded."));
- return 0;
+ return nullptr;
}
setBuffer(newBuffer);
string const tofile =
support::changeExtension(filename.absFileName(),
theFormats().extension(*it));
- if (theConverters().convert(0, filename, FileName(tofile),
+ if (theConverters().convert(nullptr, filename, FileName(tofile),
filename, format, *it, errorList) != Converters::SUCCESS)
return false;
loader_format = *it;
for (; it != bend; ++it) {
Buffer * child_buf = *it;
if (theBufferList().isOthersChild(&buf, child_buf)) {
- child_buf->setParent(0);
+ child_buf->setParent(nullptr);
continue;
}
void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
{
Buffer * buffer = documentBufferView()
- ? &(documentBufferView()->buffer()) : 0;
+ ? &(documentBufferView()->buffer()) : nullptr;
switch (cmd.action()) {
case LFUN_VC_REGISTER:
break;
case LFUN_VC_LOCKING_TOGGLE:
- LASSERT(buffer, return);
- if (!ensureBufferClean(buffer) || buffer->hasReadonlyFlag())
+ if (!buffer || !ensureBufferClean(buffer) || buffer->hasReadonlyFlag())
break;
if (buffer->lyxvc().inUse()) {
string res = buffer->lyxvc().lockingToggle();
break;
case LFUN_VC_REVERT:
- LASSERT(buffer, return);
+ if (!buffer)
+ break;
if (buffer->lyxvc().revert()) {
reloadBuffer(*buffer);
dr.clearMessageUpdate();
break;
case LFUN_VC_UNDO_LAST:
- LASSERT(buffer, return);
+ if (!buffer)
+ break;
buffer->lyxvc().undoLast();
reloadBuffer(*buffer);
dr.clearMessageUpdate();
break;
case LFUN_VC_REPO_UPDATE:
- LASSERT(buffer, return);
+ if (!buffer)
+ break;
if (ensureBufferClean(buffer)) {
dr.setMessage(buffer->lyxvc().repoUpdate());
checkExternallyModifiedBuffers();
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "comparehistory"));
break;
}
+ if (!buffer)
+ break;
string rev1 = cmd.getArg(0);
string f1, f2;
- LATTEST(buffer)
// f1
if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
Buffer & buffer = documentBufferView()->buffer();
FileName const filename = support::makeAbsPath(fname, buffer.filePath());
documentBufferView()->saveBookmark(false);
- Buffer * child = 0;
+ Buffer * child = nullptr;
if (theBufferList().exists(filename)) {
child = theBufferList().getBuffer(filename);
setBuffer(child);
int row = -1;
size_t i = argument.find_last_of(' ');
if (i != string::npos) {
- file_name = os::internal_path(trim(argument.substr(0, i)));
+ file_name = os::internal_path(FileName(trim(argument.substr(0, i))).realPath());
istringstream is(argument.substr(i + 1));
is >> row;
if (is.fail())
LYXERR0("Wrong argument: " << argument);
return false;
}
- Buffer * buf = 0;
- string const abstmp = package().temp_dir().absFileName();
+ Buffer * buf = nullptr;
string const realtmp = package().temp_dir().realPath();
// We have to use os::path_prefix_is() here, instead of
// simply prefixIs(), because the file name comes from
// an external application and may need case adjustment.
- if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
- || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
- // Needed by inverse dvi search. If it is a file
- // in tmpdir, call the apropriated function.
- // If tmpdir is a symlink, we may have the real
- // path passed back, so we correct for that.
- if (!prefixIs(file_name, abstmp))
- file_name = subst(file_name, realtmp, abstmp);
- buf = theBufferList().getBufferFromTmp(file_name);
+ if (os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
+ buf = theBufferList().getBufferFromTmp(file_name, true);
+ LYXERR(Debug::FILES, "goToFileRow: buffer lookup for " << file_name
+ << (buf ? " success" : " failed"));
} else {
// Must replace extension of the file to be .lyx
// and get full path
dr.dispatched(true);
Buffer * doc_buffer = documentBufferView()
- ? &(documentBufferView()->buffer()) : 0;
+ ? &(documentBufferView()->buffer()) : nullptr;
if (cmd.origin() == FuncRequest::TOC) {
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
_("Exporting ..."),
&GuiViewPrivate::exportAndDestroy,
&Buffer::doExport,
- 0, cmd.allowAsync());
+ nullptr, cmd.allowAsync());
// TODO Inform user about success
break;
}
_("Exporting ..."),
&GuiViewPrivate::compileAndDestroy,
&Buffer::doExport,
- 0, cmd.allowAsync());
+ nullptr, cmd.allowAsync());
break;
}
case LFUN_BUFFER_VIEW: {
doc_buffer,
_("Previewing ..."),
&GuiViewPrivate::previewAndDestroy,
- 0,
+ nullptr,
&Buffer::preview, cmd.allowAsync());
break;
}
case LFUN_MASTER_BUFFER_UPDATE: {
d.asyncBufferProcessing(argument,
- (doc_buffer ? doc_buffer->masterBuffer() : 0),
+ (doc_buffer ? doc_buffer->masterBuffer() : nullptr),
docstring(),
&GuiViewPrivate::compileAndDestroy,
&Buffer::doExport,
- 0, cmd.allowAsync());
+ nullptr, cmd.allowAsync());
break;
}
case LFUN_MASTER_BUFFER_VIEW: {
d.asyncBufferProcessing(argument,
- (doc_buffer ? doc_buffer->masterBuffer() : 0),
+ (doc_buffer ? doc_buffer->masterBuffer() : nullptr),
docstring(),
&GuiViewPrivate::previewAndDestroy,
- 0, &Buffer::preview, cmd.allowAsync());
+ nullptr, &Buffer::preview, cmd.allowAsync());
break;
}
case LFUN_EXPORT_CANCEL: {
break;
}
+ case LFUN_MASTER_BUFFER_FORALL: {
+ if (!doc_buffer)
+ break;
+
+ FuncRequest funcToRun = lyxaction.lookupFunc(cmd.getLongArg(0));
+ funcToRun.allowAsync(false);
+
+ for (Buffer const * buf : doc_buffer->allRelatives()) {
+ // Switch to other buffer view and resend cmd
+ lyx::dispatch(FuncRequest(
+ LFUN_BUFFER_SWITCH, buf->absFileName()));
+ lyx::dispatch(funcToRun);
+ }
+ // switch back
+ lyx::dispatch(FuncRequest(
+ LFUN_BUFFER_SWITCH, doc_buffer->absFileName()));
+ break;
+ }
+
case LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR:
LASSERT(doc_buffer, break);
doc_buffer->clearExternalModification();
break;
case LFUN_DIALOG_HIDE: {
- guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
+ guiApp->hideDialogs(to_utf8(cmd.argument()), nullptr);
break;
}
string sdata = trim(to_utf8(cmd.argument()).substr(name.size()));
if (name == "latexlog") {
- // gettatus checks that
- LATTEST(doc_buffer);
+ // getStatus checks that
+ LASSERT(doc_buffer, break);
Buffer::LogType type;
string const logfile = doc_buffer->logName(&type);
switch (type) {
showDialog("log", sdata);
} else if (name == "vclog") {
// getStatus checks that
- LATTEST(doc_buffer);
+ LASSERT(doc_buffer, break);
string const sdata2 = "vc " +
Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
showDialog("log", sdata2);
case LFUN_TAB_GROUP_CLOSE:
if (TabWorkArea * twa = d.currentTabWorkArea()) {
closeTabWorkArea(twa);
- d.current_work_area_ = 0;
+ d.current_work_area_ = nullptr;
twa = d.currentTabWorkArea();
// Switch to the next GuiWorkArea in the found TabWorkArea.
if (twa) {
// Make sure the work area is up to date.
setCurrentWorkArea(twa->currentWorkArea());
} else {
- setCurrentWorkArea(0);
+ setCurrentWorkArea(nullptr);
}
}
break;
case LFUN_VIEW_CLOSE:
if (TabWorkArea * twa = d.currentTabWorkArea()) {
closeWorkArea(twa->currentWorkArea());
- d.current_work_area_ = 0;
+ d.current_work_area_ = nullptr;
twa = d.currentTabWorkArea();
// Switch to the next GuiWorkArea in the found TabWorkArea.
if (twa) {
// Make sure the work area is up to date.
setCurrentWorkArea(twa->currentWorkArea());
} else {
- setCurrentWorkArea(0);
+ setCurrentWorkArea(nullptr);
}
}
break;
}
// Actual zoom value: default zoom + fractional extra value
- int zoom = lyxrc.defaultZoom * zoom_ratio_;
+ int zoom = (int)(lyxrc.defaultZoom * zoom_ratio_);
if (zoom < static_cast<int>(zoom_min_))
zoom = zoom_min_;
case LFUN_FORWARD_SEARCH: {
// it seems safe to assume we have a document buffer, since
// getStatus wants one.
- LATTEST(doc_buffer);
+ LASSERT(doc_buffer, break);
Buffer const * doc_master = doc_buffer->masterBuffer();
FileName const path(doc_master->temppath());
string const texname = doc_master->isChild(doc_buffer)
statusBar()->show();
} else {
// bug 5274
- hideDialogs("prefs", 0);
+ hideDialogs("prefs", nullptr);
for (int i = 0; i != d.splitter_->count(); ++i)
d.tabWorkArea(i)->setFullScreen(true);
setContentsMargins(-2, -2, -2, -2);
Buffer const * GuiView::updateInset(Inset const * inset)
{
if (!inset)
- return 0;
+ return nullptr;
Buffer const * inset_buffer = &(inset->buffer());
bool isValidName(string const & name)
{
return find_if(dialognames, end_dialognames,
- cmpCStr(name.c_str())) != end_dialognames;
+ cmpCStr(name.c_str())) != end_dialognames;
}
} // namespace
void GuiView::resetDialogs()
{
// Make sure that no LFUN uses any GuiView.
- guiApp->setCurrentView(0);
+ guiApp->setCurrentView(nullptr);
saveLayout();
saveUISettings();
menuBar()->clear();
Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
{
if (!isValidName(name))
- return 0;
+ return nullptr;
map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
if (dialog->isVisibleView())
dialog->hideView();
if (currentBufferView())
- currentBufferView()->editInset(name, 0);
+ currentBufferView()->editInset(name, nullptr);
}
if (!isValidName(name))
return;
if (currentBufferView())
- currentBufferView()->editInset(name, 0);
+ currentBufferView()->editInset(name, nullptr);
}
Dialog * dialog = it->second.get();
if (dialog) {
if (dialog->needBufferOpen() && !documentBufferView())
- hideDialog(fromqstr(dialog->name()), 0);
+ hideDialog(fromqstr(dialog->name()), nullptr);
else if (dialog->isVisibleView())
dialog->checkStatus();
}
Dialog * GuiView::build(string const & name)
{
- LASSERT(isValidName(name), return 0);
+ LASSERT(isValidName(name), return nullptr);
Dialog * dialog = createDialog(*this, name);
if (dialog)
if (name == "progress")
return createGuiProgressView(*this);
- return 0;
+ return nullptr;
}