+
+void ApplicationWindow::FileNew(void)
+{
+ // Should warn the user if drawing hasn't been saved...
+ drawing->document.Clear();
+ drawing->update();
+ documentName.clear();
+ setWindowTitle("Architektonas - Untitled");
+ statusBar()->showMessage(tr("New drawing is ready."));
+}
+
+
+void ApplicationWindow::FileOpen(void)
+{
+ QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
+ "", tr("Architektonas files (*.drawing)"));
+ FILE * file = fopen(filename.toAscii().data(), "r");
+
+ if (file == 0)
+ {
+ QMessageBox msg;
+ msg.setText(QString(tr("Could not open file \"%1\" for loading!")).arg(filename));
+ msg.setIcon(QMessageBox::Critical);
+ msg.exec();
+ return;
+ }
+
+ Container container(Vector(0, 0));
+ bool successful = FileIO::LoadAtnsFile(file, &container);
+ fclose(file);
+
+ if (!successful)
+ {
+ QMessageBox msg;
+ msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
+ msg.setIcon(QMessageBox::Critical);
+ msg.exec();
+ return;
+ }
+
+printf("FileOpen: container size = %li\n", container.objects.size());
+ drawing->document = container;
+ drawing->update();
+ documentName = filename;
+ setWindowTitle(QString("Architektonas - %1").arg(documentName));
+ statusBar()->showMessage(tr("Drawing loaded."));
+}
+
+
+void ApplicationWindow::FileSave(void)
+{
+ if (documentName.isEmpty())
+ documentName = QFileDialog::getSaveFileName(this, tr("Save Drawing"),
+ "", tr("Architektonas drawings (*.drawing)"));
+
+ FILE * file = fopen(documentName.toAscii().data(), "w");
+
+ if (file == 0)
+ {
+ QMessageBox msg;
+ msg.setText(QString(tr("Could not open file \"%1\" for saving!")).arg(documentName));
+ msg.setIcon(QMessageBox::Critical);
+ msg.exec();
+ return;
+ }
+
+ bool successful = FileIO::SaveAtnsFile(file, &drawing->document);
+ fclose(file);
+
+ if (!successful)
+ {
+ QMessageBox msg;
+ msg.setText(QString(tr("Could not save file \"%1\"!")).arg(documentName));
+ msg.setIcon(QMessageBox::Critical);
+ msg.exec();
+ // In this case, we should unlink the created file, since it's not right...
+ unlink(documentName.toAscii().data());
+ return;
+ }
+
+ setWindowTitle(QString("Architektonas - %1").arg(documentName));
+ statusBar()->showMessage(tr("Drawing saved."));
+}
+
+
+void ApplicationWindow::FileSaveAs(void)
+{
+ QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
+ documentName, tr("Architektonas drawings (*.drawing)"));
+
+ if (!filename.isEmpty())
+ {
+ documentName = filename;
+ FileSave();
+ }
+}
+
+
+void ApplicationWindow::SnapToGridTool(void)
+{
+ Object::SetSnapMode(snapToGridAct->isChecked());
+}
+