diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/editorwindow.cc | 8 | ||||
-rw-r--r-- | src/editorwindow.h | 8 | ||||
-rw-r--r-- | src/mainwindow.cc | 31 | ||||
-rw-r--r-- | src/mainwindow.h | 8 | ||||
-rw-r--r-- | src/mapwidget.cc | 1 |
5 files changed, 48 insertions, 8 deletions
diff --git a/src/editorwindow.cc b/src/editorwindow.cc index 208c309..446f6d7 100644 --- a/src/editorwindow.cc +++ b/src/editorwindow.cc @@ -85,7 +85,7 @@ bool EditorWindow::loadFile(const QString &filename) } else if (ini.got_section("jumpgate")) { in_entity = true; - } else if (ini.got_section("jumpoint")) { + } else if (ini.got_section("jumppoint")) { in_entity = true; } else if (ini.got_section("navpoint")) { @@ -118,7 +118,7 @@ bool EditorWindow::loadFile(const QString &filename) entity->properties()->set_type(ini.section()); } if (entity && in_subsection) { - entity->properties()->add_subsection(ini.section()); + entity->properties()->add_subsection_header(ini.section()); } } else if(ini.got_key()) { @@ -167,9 +167,7 @@ bool EditorWindow::loadFile(const QString &filename) } QApplication::restoreOverrideCursor(); - - //setCurrentFile(fileName); - //connect(document(), SIGNAL(contentsChanged()),this, SLOT(documentWasModified())); + editorwindow_filename = QFileInfo(filename).canonicalFilePath(); return true; } diff --git a/src/editorwindow.h b/src/editorwindow.h index ddd0f57..2a1f3f6 100644 --- a/src/editorwindow.h +++ b/src/editorwindow.h @@ -29,6 +29,13 @@ class EditorWindow : public QWidget public: EditorWindow(QWidget *parent = 0); + + /** + * @brief name of the file being edited + * */ + inline const QString &filename() const { + return editorwindow_filename; + } public slots: bool loadFile(const QString &filename); @@ -38,6 +45,7 @@ protected: virtual void resizeEvent (QResizeEvent *event); private: + QString editorwindow_filename; MapWidget *editorwindow_mapwidget; SideBar *editorwindow_sidebar; QSplitter *editorwindow_splitter; 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()); + } + } } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 48e8927..b2943a5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,8 +36,14 @@ private slots: private: void init_actions(); void init_menu(); - + + /// add a new child window EditorWindow *add_child(); + + /// find an already open file + QMdiSubWindow *find_child(const QString &filename); + + /// return the active child window, NULL if none EditorWindow *active_child(); QMdiArea *mainwindow_mdiarea; diff --git a/src/mapwidget.cc b/src/mapwidget.cc index f2fe7e7..b855040 100644 --- a/src/mapwidget.cc +++ b/src/mapwidget.cc @@ -139,6 +139,7 @@ void MapWidget::dragEntity(EntityWidget *entity, int x, int y) emit propertiesChanged(entity->properties()); resizeChildren(); } + void MapWidget::select(EntityWidget *entity) { for (int i = 0; i < mapwidget_enties.size(); ++i) { |