File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,17 @@ class FileManager : public QObject
52
52
static OperationResult duplicatePath (const QFileInfo &pathInfo);
53
53
static OperationResult deletePath (const QFileInfo &pathInfo);
54
54
55
+ int buildUnsavedChangesMessage () const ;
56
+ bool hasUnsavedChanges ();
57
+
55
58
public slots:
56
59
void newFile ();
57
60
void saveFile ();
58
61
void saveFileAs ();
59
62
void openFile ();
60
63
void loadFileInEditor (const QString &filePath);
61
- bool isChanged (QString currentFileName);
64
+
65
+ bool promptUnsavedChanges ();
62
66
63
67
QString getDirectoryPath () const ;
64
68
@@ -70,4 +74,5 @@ public slots:
70
74
MainWindow *m_mainWindow;
71
75
QSyntaxHighlighter *m_currentHighlighter = nullptr ;
72
76
QString m_currentFileName;
77
+ bool m_isDirty = false ;
73
78
};
Original file line number Diff line number Diff line change @@ -165,6 +165,15 @@ void FileManager::saveFile()
165
165
}
166
166
file.close ();
167
167
168
+ if (m_mainWindow)
169
+ {
170
+ m_mainWindow->setWindowTitle (" CodeAstra ~ " + QFileInfo (m_currentFileName).fileName ());
171
+ }
172
+ else
173
+ {
174
+ qWarning () << " MainWindow is not initialized in FileManager." ;
175
+ }
176
+
168
177
m_isDirty = false ;
169
178
emit m_editor->statusMessageChanged (" File saved successfully." );
170
179
}
Original file line number Diff line number Diff line change @@ -67,13 +67,16 @@ void Tree::openFile(const QModelIndex &index)
67
67
return ;
68
68
}
69
69
70
- QString current_file = FileManager::getInstance ().getCurrentFileName ();
71
- bool isFileSaved = FileManager::getInstance ().isChanged (current_file);
72
-
73
- if (isFileSaved || current_file.isEmpty ())
70
+ FileManager &fm = FileManager::getInstance ();
71
+ if (fm.getCurrentFileName () != filePath)
74
72
{
75
- FileManager::getInstance ().setCurrentFileName (filePath);
76
- FileManager::getInstance ().loadFileInEditor (filePath);
73
+ if (!fm.promptUnsavedChanges ())
74
+ {
75
+ return ; // if user has cancelled
76
+ }
77
+
78
+ fm.setCurrentFileName (filePath);
79
+ fm.loadFileInEditor (filePath);
77
80
}
78
81
}
79
82
You can’t perform that action at this time.
0 commit comments