+FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
+{
+ FuncStatus flag;
+ bool enable = true;
+
+ switch(cmd.action) {
+
+ case LFUN_WINDOW_CLOSE:
+ enable = view_ids_.size() > 0;
+ break;
+
+ default:
+ if (!current_view_) {
+ enable = false;
+ break;
+ }
+ }
+
+ if (!enable)
+ flag.enabled(false);
+
+ return flag;
+}
+
+
+bool GuiApplication::dispatch(FuncRequest const & cmd)
+{
+ switch(cmd.action) {
+
+ case LFUN_WINDOW_NEW:
+ createView(toqstr(cmd.argument()));
+ break;
+
+ case LFUN_WINDOW_CLOSE:
+ // update bookmark pit of the current buffer before window close
+ for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
+ theLyXFunc().gotoBookmark(i+1, false, false);
+ current_view_->close();
+ break;
+
+ case LFUN_LYX_QUIT:
+ // quitting is triggered by the gui code
+ // (leaving the event loop).
+ current_view_->message(from_utf8(N_("Exiting.")));
+ if (closeAllViews())
+ quit();
+ break;
+
+ case LFUN_SCREEN_FONT_UPDATE: {
+ // handle the screen font changes.
+ font_loader_.update();
+ // Backup current_view_
+ GuiView * view = current_view_;
+ // Set current_view_ to zero to forbid GuiWorkArea::redraw()
+ // to skip the refresh.
+ current_view_ = 0;
+ BufferList::iterator it = theBufferList().begin();
+ BufferList::iterator const end = theBufferList().end();
+ for (; it != end; ++it)
+ (*it)->changed();
+ // Restore current_view_
+ current_view_ = view;
+ break;
+ }
+
+ case LFUN_BUFFER_NEW:
+ if (viewCount() == 0
+ || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0))
+ createView();
+ current_view_->newDocument(to_utf8(cmd.argument()), false);
+ break;
+
+ case LFUN_BUFFER_NEW_TEMPLATE:
+ if (viewCount() == 0
+ || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
+ createView();
+ current_view_->newDocument(to_utf8(cmd.argument()), true);
+ if (!current_view_->buffer())
+ current_view_->close();
+ } else
+ current_view_->newDocument(to_utf8(cmd.argument()), true);
+ break;
+
+ case LFUN_FILE_OPEN:
+ if (viewCount() == 0
+ || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
+ createView();
+ current_view_->openDocument(to_utf8(cmd.argument()));
+ if (!current_view_->buffer())
+ current_view_->close();
+ } else
+ current_view_->openDocument(to_utf8(cmd.argument()));
+ break;
+
+ default:
+ // Notify the caller that the action has not been dispatched.
+ return false;
+ }
+
+ // The action has been dispatched.
+ return true;
+}
+
+