src/file.cpp

changeset 383
10e60ae9ed58
parent 381
241f65769a57
child 385
b136331072a0
equal deleted inserted replaced
382:c1642530ea35 383:10e60ae9ed58
36 36
37 static bool g_loadingMainFile = false; 37 static bool g_loadingMainFile = false;
38 static const int g_MaxRecentFiles = 5; 38 static const int g_MaxRecentFiles = 5;
39 static bool g_aborted = false; 39 static bool g_aborted = false;
40 40
41 DEFINE_PROPERTY (QListWidgetItem*, LDOpenFile, listItem, setListItem)
42
41 // ============================================================================= 43 // =============================================================================
42 namespace LDPaths { 44 namespace LDPaths {
43 static str pathError; 45 static str pathError;
44 46
45 struct { 47 struct {
90 92
91 // ============================================================================= 93 // =============================================================================
92 LDOpenFile::LDOpenFile() { 94 LDOpenFile::LDOpenFile() {
93 setImplicit (true); 95 setImplicit (true);
94 setSavePos (-1); 96 setSavePos (-1);
97 setListItem (null);
95 m_history.setFile (this); 98 m_history.setFile (this);
96 } 99 }
97 100
98 // ============================================================================= 101 // =============================================================================
99 LDOpenFile::~LDOpenFile() { 102 LDOpenFile::~LDOpenFile() {
372 bool LDOpenFile::safeToClose() { 375 bool LDOpenFile::safeToClose() {
373 typedef QMessageBox msgbox; 376 typedef QMessageBox msgbox;
374 setlocale (LC_ALL, "C"); 377 setlocale (LC_ALL, "C");
375 378
376 // If we have unsaved changes, warn and give the option of saving. 379 // If we have unsaved changes, warn and give the option of saving.
377 if (!implicit() && history().pos() != savePos()) { 380 if (hasUnsavedChanges()) {
378 str message = fmt ("There are unsaved changes to %1. Should it be saved?", 381 str message = fmt ("There are unsaved changes to %1. Should it be saved?",
379 (name().length() > 0) ? name() : "<anonymous>"); 382 (name().length() > 0) ? name() : "<anonymous>");
380 383
381 int button = msgbox::question (g_win, "Unsaved Changes", message, 384 int button = msgbox::question (g_win, "Unsaved Changes", message,
382 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel); 385 (msgbox::Yes | msgbox::No | msgbox::Cancel), msgbox::Cancel);
914 m_objs << obj; 917 m_objs << obj;
915 918
916 return *this; 919 return *this;
917 } 920 }
918 921
922 bool LDOpenFile::hasUnsavedChanges() const {
923 return !implicit() && history().pos() != savePos();
924 }
925
919 // ============================================================================= 926 // =============================================================================
920 class { 927 class {
921 public: 928 public:
922 LDOpenFile* currentFile() { 929 LDOpenFile* currentFile() {
923 return m_curfile; 930 return m_curfile;
924 } 931 }
925 932
926 void setCurrentFile (LDOpenFile* f) { 933 void setCurrentFile (LDOpenFile* f) {
927 m_curfile = f; 934 m_curfile = f;
935
936 if (g_win)
937 g_win->updateFileList();
928 } 938 }
929 939
930 private: 940 private:
931 LDOpenFile* m_curfile; 941 LDOpenFile* m_curfile;
932 } g_currentFile; 942 } g_currentFile;

mercurial