#include "GuiApplication.h"
#include "GuiCommandBuffer.h"
#include "GuiCompleter.h"
-#include "GuiWorkArea.h"
#include "GuiKeySymbol.h"
#include "GuiToc.h"
#include "GuiToolbar.h"
+#include "GuiWorkArea.h"
#include "LayoutBox.h"
#include "Menus.h"
#include "TocModel.h"
#include <QSplitter>
#include <QStackedWidget>
#include <QStatusBar>
+#include <QTime>
#include <QTimer>
#include <QToolBar>
#include <QUrl>
#define EXPORT_in_THREAD 1
+
// QtConcurrent was introduced in Qt 4.4
#if (QT_VERSION >= 0x040400)
#include <QFuture>
return tabWorkArea(0);
}
+#if (QT_VERSION >= 0x040400)
void setPreviewFuture(QFuture<docstring> const & f)
{
- if (preview_watcher_.isRunning())
- preview_watcher_.waitForFinished();
+ if (preview_watcher_.isRunning()) {
+ // we prefer to cancel this preview in order to keep a snappy
+ // interface.
+ return;
+ }
preview_watcher_.setFuture(f);
- connect(&preview_watcher_, SIGNAL(finished()), gv_,
- SLOT(threadFinished()));
}
+#endif
public:
GuiView * gv_;
///
QFutureWatcher<docstring> autosave_watcher_;
QFutureWatcher<docstring> preview_watcher_;
+#else
+ struct DummyWatcher { bool isRunning(){return false;} };
+ DummyWatcher preview_watcher_;
#endif
};
setAcceptDrops(true);
statusBar()->setSizeGripEnabled(true);
+ updateStatusBar();
+
+#if (QT_VERSION >= 0x040400)
+ connect(&d.autosave_watcher_, SIGNAL(finished()), this,
+ SLOT(threadFinished()));
+ connect(&d.preview_watcher_, SIGNAL(finished()), this,
+ SLOT(threadFinished()));
+#endif
+
+ connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
+ SLOT(doShowDialog(QString const &, QString const &, Inset *)));
// Forbid too small unresizable window because it can happen
// with some window manager under X11.
// clear session data if any.
QSettings settings;
settings.remove("views");
-
-#if (QT_VERSION >= 0x040400)
- connect(&d.autosave_watcher_, SIGNAL(finished()), this,
- SLOT(threadFinished()));
-#endif
-
- connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
- SLOT(doShowDialog(QString const &, QString const &, Inset *)));
}
dialog->prepareView();
if ((dialog = findOrBuild("view-source", true)))
dialog->prepareView();
+ if ((dialog = findOrBuild("progress", true)))
+ dialog->prepareView();
if (!restoreState(settings.value("layout").toByteArray(), 0))
initToolbars();
cmd = FuncRequest(LFUN_FILE_OPEN, file);
}
- // Asynchronously post the event. DropEvent usually come
+ // Asynchronously post the event. DropEvent usually comes
// from the BufferView. But reloading a file might close
// the BufferView from within its own event handler.
guiApp->dispatchDelayed(cmd);
void GuiView::clearMessage()
{
- if (!hasFocus())
- return;
+ // FIXME: This code was introduced in r19643 to fix bug #4123. However,
+ // the hasFocus function mostly returns false, even if the focus is on
+ // a workarea in this view.
+ //if (!hasFocus())
+ // return;
showMessage();
d.statusbar_timer_.stop();
}
void GuiView::updateWindowTitle(GuiWorkArea * wa)
{
- if (wa != d.current_work_area_)
+ if (wa != d.current_work_area_
+ || wa->bufferView().buffer().isInternal())
return;
setWindowTitle(qt_("LyX: ") + wa->windowTitle());
setWindowIconText(wa->windowIconText());
updateDialogs();
resetWindowTitleAndIconText();
+ updateStatusBar();
if (lyxrc.open_buffers_in_tabs)
// Nothing more to do, the window should stay open.
}
+#if (QT_VERSION >= 0x040400)
static docstring saveAndDestroyBuffer(Buffer * buffer, FileName const & fname)
{
bool failed = true;
? _("Automatic save failed!")
: _("Automatic save done.");
}
+#endif
void GuiView::autoSave()
|| name == "file" //FIXME: should be removed.
|| name == "prefs"
|| name == "texinfo"
+ || name == "progress"
|| name == "compare";
else if (name == "print")
enable = doc_buffer->isExportable("dvi")
bool GuiView::closeBuffer()
{
GuiWorkArea * wa = currentMainWorkArea();
+ setCurrentWorkArea(wa);
Buffer & buf = wa->bufferView().buffer();
return wa && closeWorkArea(wa, !buf.parent());
}
buf.removeAutosaveFile();
if (hiding)
// revert all changes
- buf.loadLyXFile(buf.fileName());
+ buf.reload();
buf.markClean();
break;
case 2:
void GuiView::reloadBuffer()
{
Buffer * buf = &documentBufferView()->buffer();
- reloadBuffer(buf);
-}
-
-
-void GuiView::reloadBuffer(Buffer * buf)
-{
- FileName filename = buf->fileName();
- Buffer const * master = buf->masterBuffer();
- bool const is_child = master != buf;
- // The user has already confirmed that the changes, if any, should
- // be discarded. So we just release the Buffer and don't call closeBuffer();
- theBufferList().release(buf);
- buf = loadDocument(filename);
- docstring const disp_fn = makeDisplayPath(filename.absFilename());
- docstring str;
- if (buf) {
- // re-allocate master if necessary
- if (is_child && theBufferList().isLoaded(master)
- && buf->masterBuffer() != master)
- buf->setParent(master);
- buf->updateLabels();
- setBuffer(buf);
- buf->errors("Parse");
- str = bformat(_("Document %1$s reloaded."), disp_fn);
- } else {
- str = bformat(_("Could not reload document %1$s"), disp_fn);
- }
- message(str);
+ buf->reload();
}
BufferList::iterator bit = theBufferList().begin();
BufferList::iterator const bend = theBufferList().end();
for (; bit != bend; ++bit) {
- if ((*bit)->isExternallyModified(Buffer::checksum_method)) {
+ if ((*bit)->fileName().exists()
+ && (*bit)->isExternallyModified(Buffer::checksum_method)) {
docstring text = bformat(_("Document \n%1$s\n has been externally modified."
" Reload now? Any local changes will be lost."),
from_utf8((*bit)->absFileName()));
int const ret = Alert::prompt(_("Reload externally changed document?"),
text, 0, 1, _("&Reload"), _("&Cancel"));
if (!ret)
- reloadBuffer(*bit);
+ (*bit)->reload();
}
}
}
void GuiView::dispatchVC(FuncRequest const & cmd)
{
+ // message for statusbar
+ string msg;
Buffer * buffer = documentBufferView()
? &(documentBufferView()->buffer()) : 0;
if (!buffer || !ensureBufferClean(buffer))
break;
if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
- message(from_utf8(buffer->lyxvc().checkIn()));
- reloadBuffer();
+ msg = buffer->lyxvc().checkIn();
+ if (!msg.empty())
+ reloadBuffer();
}
break;
if (!buffer || !ensureBufferClean(buffer))
break;
if (buffer->lyxvc().inUse()) {
- message(from_utf8(buffer->lyxvc().checkOut()));
+ msg = buffer->lyxvc().checkOut();
reloadBuffer();
}
break;
frontend::Alert::error(_("Revision control error."),
_("Error when setting the locking property."));
} else {
- message(from_utf8(res));
+ msg = res;
reloadBuffer();
}
}
case LFUN_VC_REPO_UPDATE:
LASSERT(buffer, return);
if (ensureBufferClean(buffer)) {
- string res = buffer->lyxvc().repoUpdate();
- message(from_utf8(res));
+ msg = buffer->lyxvc().repoUpdate();
checkExternallyModifiedBuffers();
}
break;
default:
break;
}
+
+ if (!msg.empty())
+ message(from_utf8(msg));
}
{
string file_name;
int row;
- istringstream is(argument);
- is >> file_name >> row;
- file_name = os::internal_path(file_name);
+ size_t i = argument.find_last_of(' ');
+ if (i != string::npos) {
+ file_name = os::internal_path(trim(argument.substr(0, i)));
+ istringstream is(argument.substr(i + 1));
+ is >> row;
+ if (is.fail())
+ i = string::npos;
+ }
+ if (i == string::npos) {
+ LYXERR0("Wrong argument: " << argument);
+ return false;
+ }
Buffer * buf = 0;
string const abstmp = package().temp_dir().absFilename();
string const realtmp = package().temp_dir().realPath();
}
+#if (QT_VERSION >= 0x040400)
static docstring exportAndDestroy(Buffer * buffer, string const & format)
{
bool const success = buffer->doExport(format, true);
? bformat(_("Successful preview of format: %1$s"), from_utf8(format))
: bformat(_("Error previewing format: %1$s"), from_utf8(format));
}
+#endif
bool GuiView::dispatch(FuncRequest const & cmd)
if (argument.empty())
format = doc_buffer->getDefaultOutputFormat();
#if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
- ProgressInterface::instance()->clearMessages();
- QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate);
- ProgressInterface::instance()->appendMessage(time + ": Exporting ...\n");
+ d.progress_->clearMessages();
+ message(_("Exporting ..."));
QFuture<docstring> f = QtConcurrent::run(exportAndDestroy,
doc_buffer->clone(), format);
d.setPreviewFuture(f);
if (argument.empty())
format = doc_buffer->getDefaultOutputFormat();
#if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
- ProgressInterface::instance()->clearMessages();
- QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate);
- ProgressInterface::instance()->appendMessage(time + ": Previewing ...\n");
+ d.progress_->clearMessages();
+ message(_("Previewing ..."));
QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
doc_buffer->clone(), format);
d.setPreviewFuture(f);
"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
-"toc", "view-source", "vspace", "wrap"};
+"toc", "view-source", "vspace", "wrap", "progress"};
char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *));
Dialog * createGuiVSpace(GuiView & lv);
Dialog * createGuiViewSource(GuiView & lv);
Dialog * createGuiWrap(GuiView & lv);
+Dialog * createGuiProgressView(GuiView & lv);
return createGuiVSpace(*this);
if (name == "wrap")
return createGuiWrap(*this);
+ if (name == "progress")
+ return createGuiProgressView(*this);
return 0;
}