From 180bd906b79e89db7241425168dcf8801306a2fb Mon Sep 17 00:00:00 2001 From: Oskar Linde Date: Sat, 3 May 2014 18:20:37 +0200 Subject: [PATCH] Avoid leaving the first empty document window when opening a file in MDI mode --- src/mainwin.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mainwin.cc b/src/mainwin.cc index 356ea97d..85def2eb 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -518,6 +518,18 @@ void MainWindow::report_func(const class AbstractNode*, void *vp, int mark) #ifdef ENABLE_MDI void MainWindow::requestOpenFile(const QString &filename) { + // if we have an empty open window, use that one + QSetIterator i(*MainWindow::windows); + while (i.hasNext()) { + MainWindow *w = i.next(); + + if (w->editor->toPlainText().isEmpty()) { + w->openFile(filename); + return; + } + } + + // otherwise, create a new one new MainWindow(filename); } #else @@ -962,7 +974,7 @@ void MainWindow::actionOpen() } #ifdef ENABLE_MDI if (!new_filename.isEmpty()) { - new MainWindow(new_filename); + openFile(new_filename); } #else if (!new_filename.isEmpty()) { @@ -981,7 +993,7 @@ void MainWindow::actionOpenRecent() QAction *action = qobject_cast(sender()); #ifdef ENABLE_MDI - new MainWindow(action->data().toString()); + openFile(action->data().toString()); #else if (!maybeSave()) return;