@@ -96,13 +96,7 @@ MainWindow::MainWindow() :
96
96
// Open database
97
97
QString lastOpen = Settings::lastOpenDatabaseFile.get ();
98
98
if (!lastOpen.isEmpty () && QFile (lastOpen).exists ()) {
99
- setWindowTitleFilename (lastOpen);
100
- db.openExisting (this , lastOpen);
101
- updateFilters ();
102
- setVisible (true );
103
- initCompositeBuffers ();
104
- updateTableSize ();
105
- setUIEnabled (true );
99
+ attemptToOpenFile (lastOpen);
106
100
}
107
101
108
102
@@ -449,6 +443,26 @@ void MainWindow::updateContextMenuEditIcon()
449
443
450
444
// PROJECT SETUP
451
445
446
+ /* *
447
+ * Attempts to open the given file and only changes UI if database initialization is successful.
448
+ *
449
+ * @param filepath The file to attempt to open.
450
+ */
451
+ void MainWindow::attemptToOpenFile (const QString& filepath)
452
+ {
453
+ bool dbOpened = db.openExisting (this , filepath);
454
+
455
+ if (dbOpened) {
456
+ setWindowTitleFilename (filepath);
457
+ updateFilters ();
458
+ setVisible (true );
459
+ initCompositeBuffers ();
460
+ updateTableSize ();
461
+ setUIEnabled (true );
462
+ addToRecentFilesList (filepath);
463
+ }
464
+ }
465
+
452
466
/* *
453
467
* Prepares the composite tables and fills either all of them or only the one currently being
454
468
* shown, with a status bar progress dialog.
@@ -953,14 +967,7 @@ void MainWindow::handle_openDatabase()
953
967
954
968
handle_closeDatabase ();
955
969
956
- setWindowTitleFilename (filepath);
957
- db.openExisting (this , filepath);
958
- updateFilters ();
959
- initCompositeBuffers ();
960
- updateTableSize ();
961
- setUIEnabled (true );
962
-
963
- addToRecentFilesList (filepath);
970
+ attemptToOpenFile (filepath);
964
971
}
965
972
966
973
/* *
@@ -980,14 +987,7 @@ void MainWindow::handle_openRecentDatabase(QString filepath)
980
987
981
988
handle_closeDatabase ();
982
989
983
- setWindowTitleFilename (filepath);
984
- db.openExisting (this , filepath);
985
- updateFilters ();
986
- initCompositeBuffers ();
987
- updateTableSize ();
988
- setUIEnabled (true );
989
-
990
- addToRecentFilesList (filepath);
990
+ attemptToOpenFile (filepath);
991
991
}
992
992
993
993
/* *
0 commit comments