diff options
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r-- | src/mainwindow.cc | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc index d1069d7..a92fb8b 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -80,6 +80,21 @@ EditorWindow *MainWindow::active_child() return 0; } +QMdiSubWindow *MainWindow::find_child(const QString &filename) +{ + + QString canonical = QFileInfo(filename).canonicalFilePath(); + + foreach (QMdiSubWindow *subwindow, mainwindow_mdiarea->subWindowList()) { + EditorWindow *editorwindow = qobject_cast<EditorWindow *>(subwindow->widget()); + + if (editorwindow->filename() == canonical) + return subwindow; + } + return 0; + +} + EditorWindow *MainWindow::add_child() { // create a child widget @@ -90,6 +105,7 @@ EditorWindow *MainWindow::add_child() QMdiSubWindow *subwindow = mainwindow_mdiarea->addSubWindow(child_widget); child_widget->show(); + mainwindow_mdiarea->setActiveSubWindow(subwindow); // FIXME check if maximized subwindow->resize(768, 512); @@ -107,8 +123,19 @@ void MainWindow::slot_open() QString filename = QFileDialog::getOpenFileName(this, tr("Open file")); if (!filename.isEmpty()) { - EditorWindow *editorwindow = add_child(); - editorwindow->loadFile(filename); + QMdiSubWindow *subwindow = find_child(filename); + + if (subwindow) { + mainwindow_mdiarea->setActiveSubWindow(subwindow); + } else { + EditorWindow *editorwindow = add_child(); + editorwindow->loadFile(filename); + + subwindow = find_child(filename); + if (subwindow) { + subwindow->setWindowTitle(editorwindow->filename()); + } + } } } |