diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index b206882f..3beffae9 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -320,6 +320,7 @@ namespace IDE public Point mLastRelMousePos; public int32 mMouseStillTicks; public Widget mLastMouseWidget;*/ + public bool mAppHasFocus; public int32 mCloseDelay; public FileChangedDialog mFileChangedDialog; public FindAndReplaceDialog mFindAndReplaceDialog; @@ -2867,6 +2868,8 @@ namespace IDE } else { + mWorkspace.mProjectFileEnties.Add(new .(workspaceFileName)); + if (mVerb == .New) { OutputErrorLine("Workspace '{0}' already exists, but '-new' argument was specified.", workspaceFileName); @@ -2945,6 +2948,20 @@ namespace IDE MarkDirty(); } + protected void ReloadWorkspace() + { + SaveWorkspaceUserData(false); + + String workspaceDir = scope .(mWorkspace.mDir); + String workspaceName = scope .(mWorkspace.mName); + + CloseWorkspace(); + mWorkspace.mDir = new String(workspaceDir); + mWorkspace.mName = new String(workspaceName); + LoadWorkspace(.Open); + FinishShowingNewWorkspace(); + } + public void GetRelaunchCmd(bool safeMode, String outRelaunchCmd) { if (mWorkspace.mDir != null) @@ -5175,6 +5192,12 @@ namespace IDE mSettings.Apply(); } + public void CheckReloadSettings() + { + if (mSettings.WantsReload()) + ReloadSettings(); + } + [IDECommand] public void ResetUI() { @@ -13843,6 +13866,44 @@ namespace IDE for (var window in mWindows) appHasFocus |= window.mHasFocus; + if ((appHasFocus) && (!mAppHasFocus)) + { + CheckReloadSettings(); + + bool hadChange = false; + for (var entry in mWorkspace.mProjectFileEnties) + { + if (entry.HasFileChanged()) + { + if (!hadChange) + { + String text = scope .(); + + if (entry.mProjectName != null) + text.AppendF($"The '{entry.mProjectName}' project file has been modified externally."); + else + text.Append("The workspace file has been modified externally."); + + text.Append("\n\nDo you want to reload the workspace?"); + + var dialog = ThemeFactory.mDefault.CreateDialog("Reload Workspace?", + text); + dialog.AddYesNoButtons(new (dlg) => + { + ReloadWorkspace(); + }, + new (dlg) => + { + + }); + dialog.PopupWindow(GetActiveWindow()); + hadChange = true; + } + } + } + } + mAppHasFocus = appHasFocus; + if (mRunningTestScript) appHasFocus = true; diff --git a/IDE/src/Project.bf b/IDE/src/Project.bf index f7a630c7..0e8d4b72 100644 --- a/IDE/src/Project.bf +++ b/IDE/src/Project.bf @@ -1534,6 +1534,11 @@ namespace IDE Save(); }*/ + if (mProjectName != null) + { + gApp.mWorkspace.mProjectFileEnties.Add(new .(path, mProjectName)); + } + return true; } diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index 40d5c598..1bd1d217 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -1091,6 +1091,8 @@ namespace IDE } public bool mLoadedSettings; + public String mSettingFileText ~ delete _; + public DateTime mSettingFileDateTime; public UISettings mUISettings = new .() ~ delete _; public EditorSettings mEditorSettings = new .() ~ delete _; @@ -1177,7 +1179,29 @@ namespace IDE String dataStr = scope String(); sd.ToTOML(dataStr); - gApp.SafeWriteTextFile(path, dataStr); + + if ((mSettingFileText == null) || (mSettingFileText != dataStr)) + { + String.NewOrSet!(mSettingFileText, dataStr); + gApp.SafeWriteTextFile(path, dataStr); + + if (File.GetLastWriteTime(path) case .Ok(let dt)) + mSettingFileDateTime = dt; + } + } + + public bool WantsReload() + { + String path = scope .(); + GetSettingsPath(path); + + if (File.GetLastWriteTime(path) case .Ok(let dt)) + { + if (dt != mSettingFileDateTime) + return true; + } + + return false; } public void Load() @@ -1189,6 +1213,13 @@ namespace IDE if (sd.Load(path) case .Err) return; + if (File.GetLastWriteTime(path) case .Ok(let dt)) + mSettingFileDateTime = dt; + + String.NewOrSet!(mSettingFileText, sd.[Friend]mSource); + mSettingFileText.Replace("\r\n", "\n"); + mSettingFileText.Replace('\r', '\n'); + mLoadedSettings = true; using (sd.Open("UI")) mUISettings.Deserialize(sd); diff --git a/IDE/src/Workspace.bf b/IDE/src/Workspace.bf index 671d04fe..04808000 100644 --- a/IDE/src/Workspace.bf +++ b/IDE/src/Workspace.bf @@ -49,6 +49,37 @@ namespace IDE [Reflect(.StaticFields | .NonStaticFields | .ApplyToInnerTypes)] public class Workspace { + public class ProjectFileEntry + { + public String mPath = new .() ~ delete _; + public DateTime mLastWriteTime; + public String mProjectName ~ delete _; + + public this(StringView path, StringView projectName = null) + { + mPath.Set(path); + if (projectName != default) + mProjectName = new .(projectName); + if (File.GetLastWriteTime(mPath) case .Ok(var dt)) + mLastWriteTime = dt; + } + + public bool HasFileChanged() + { + if (mLastWriteTime == default) + return false; + if (File.GetLastWriteTime(mPath) case .Ok(var dt)) + { + if (dt != mLastWriteTime) + { + mLastWriteTime = dt; + return true; + } + } + return false; + } + } + public enum IntermediateType { Object, @@ -459,6 +490,7 @@ namespace IDE public List mWorkspaceFolders = new List() ~ DeleteContainerAndItems!(_); public List mProjects = new List() ~ DeleteContainerAndItems!(_); public List mProjectSpecs = new .() ~ DeleteContainerAndItems!(_); + public List mProjectFileEnties = new .() ~ DeleteContainerAndItems!(_); public Dictionary mProjectNameMap = new .() ~ DeleteDictionaryAndKeys!(_); public Dictionary mProjectLockMap = new .() ~ DeleteDictionaryAndKeysAndValues!(_); public Project mStartupProject;