#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/FileName.h"
+#include "support/filetools.h"
#include "support/foreach.h"
#include "support/ForkedCalls.h"
#include "support/gettext.h"
}
+LyXView * GuiApplication::currentWindow()
+{
+#ifdef Q_WS_MACX
+ /* In LyX/Mac, when a dialog is open, the menus of the
+ application can still be accessed without giving focus to
+ the main window. In this case, we want to disable the menu
+ entries that are buffer or view-related.
+ */
+ if (current_view_ && activeWindow() != current_view_)
+ return 0;
+#endif
+ return current_view_;
+}
+
bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
{
case LFUN_BUFFER_NEW:
case LFUN_BUFFER_NEW_TEMPLATE:
case LFUN_FILE_OPEN:
+ case LFUN_HELP_OPEN:
case LFUN_SCREEN_FONT_UPDATE:
case LFUN_SET_COLOR:
case LFUN_WINDOW_NEW:
break;
case LFUN_FILE_OPEN:
+ // FIXME: create a new method shared with LFUN_HELP_OPEN.
if (d->views_.empty()
|| (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
string const fname = to_utf8(cmd.argument());
current_view_->openDocument(to_utf8(cmd.argument()));
break;
+ case LFUN_HELP_OPEN: {
+ // FIXME: create a new method shared with LFUN_FILE_OPEN.
+ if (current_view_ == 0)
+ createView();
+ string const arg = to_utf8(cmd.argument());
+ if (arg.empty()) {
+ current_view_->message(_("Missing argument"));
+ break;
+ }
+ FileName fname = i18nLibFileSearch("doc", arg, "lyx");
+ if (fname.empty())
+ fname = i18nLibFileSearch("examples", arg, "lyx");
+
+ if (fname.empty()) {
+ lyxerr << "LyX: unable to find documentation file `"
+ << arg << "'. Bad installation?" << endl;
+ break;
+ }
+ current_view_->message(bformat(_("Opening help file %1$s..."),
+ makeDisplayPath(fname.absFilename())));
+ Buffer * buf = current_view_->loadDocument(fname, false);
+ if (buf) {
+ current_view_->setBuffer(buf);
+ buf->updateLabels();
+ buf->errors("Parse");
+ }
+ break;
+ }
+
case LFUN_SET_COLOR: {
string lyx_name;
string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' ');
QHash<int, GuiView *>::iterator it;
for (it = d->views_.begin(); it != d->views_.end(); ++it) {
GuiView * gv = *it;
+ setCurrentView(gv);
gv->setLayoutDirection(layoutDirection());
gv->resetDialogs();
}
// create new view
int id = view_id;
- if (id == 0) {
- while (d->views_.find(id) != d->views_.end())
- id++;
- }
+ while (d->views_.find(id) != d->views_.end())
+ id++;
+
LYXERR(Debug::GUI, "About to create new window with ID " << id);
GuiView * view = new GuiView(id);
// register view
this->exit(1);
case BufferException: {
- if (current_view_->documentBufferView())
+ if (!current_view_->documentBufferView())
return false;
Buffer * buf = ¤t_view_->documentBufferView()->buffer();
docstring details = e.details_ + '\n';
{
LASSERT(d->views_[gv->id()] == gv, /**/);
d->views_.remove(gv->id());
- if (current_view_ == gv) {
+ if (current_view_ == gv)
current_view_ = 0;
- theLyXFunc().setLyXView(0);
- }
}
if (xev->xselectionrequest.selection != XA_PRIMARY)
break;
LYXERR(Debug::SELECTION, "X requested selection.");
- BufferView * bv = current_view_->view();
+ BufferView * bv = current_view_->currentBufferView();
if (bv) {
docstring const sel = bv->requestSelection();
if (!sel.empty())
if (xev->xselectionclear.selection != XA_PRIMARY)
break;
LYXERR(Debug::SELECTION, "Lost selection.");
- BufferView * bv = current_view_->view();
+ BufferView * bv = current_view_->currentBufferView();
if (bv)
bv->clearSelection();
break;