From a3d952661bbcbec928d34dae30e4ae30f864250b Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Wed, 13 Jun 2018 10:44:03 +0100 Subject: [PATCH] [Git] Reload files when they are reverted Add back original code that reloaded reverted files that were open in the text editor. Without this change if the file is dirty then the file will not be reloaded and instead the text editor will show a message about the file being changed outside the IDE. Since the user explicitly asked to revert the file then the file should be reloaded automatically even if there are unsaved changes. --- .../MonoDevelop.VersionControl.Git/GitRepository.cs | 5 +++++ .../MonoDevelop.VersionControl/RevertCommand.cs | 8 ++++++++ .../MonoDevelop.VersionControl/RevertRevisionsCommands.cs | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs index 884ac2566a6..fca16f751b1 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs @@ -154,6 +154,11 @@ bool RefreshFile (string path, CheckoutNotifyFlags flags) { FilePath fp = RootRepository.FromGitPath (path); Gtk.Application.Invoke ((o, args) => { + if (IdeApp.IsInitialized) { + MonoDevelop.Ide.Gui.Document doc = IdeApp.Workbench.GetDocument (fp); + if (doc != null) + doc.Reload (); + } VersionControlService.NotifyFileStatusChanged (new FileUpdateEventArgs (this, fp, false)); }); return true; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertCommand.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertCommand.cs index daf640f788d..d9962272f43 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertCommand.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertCommand.cs @@ -60,6 +60,14 @@ protected override void Run () list[0].Repository.Revert (list.Paths, true, Monitor); Gtk.Application.Invoke ((o, args) => { + foreach (VersionControlItem item in items) { + if (!item.IsDirectory) { + // Reload reverted files + Document doc = IdeApp.Workbench.GetDocument (item.Path); + if (doc != null && System.IO.File.Exists (item.Path)) + doc.Reload (); + } + } VersionControlService.NotifyFileStatusChanged (items); }); Monitor.ReportSuccess (GettextCatalog.GetString ("Revert operation completed.")); diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertRevisionsCommands.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertRevisionsCommands.cs index bb2889b8f65..5e0065fb64a 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertRevisionsCommands.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/RevertRevisionsCommands.cs @@ -117,6 +117,10 @@ protected override void Run () Gtk.Application.Invoke ((o, args) => { if (!isDir) { + // Reload reverted files + Document doc = IdeApp.Workbench.GetDocument (path); + if (doc != null) + doc.Reload (); VersionControlService.NotifyFileStatusChanged (new FileUpdateEventArgs (vc, path, false)); } else { VersionControlService.NotifyFileStatusChanged (new FileUpdateEventArgs (vc, path, true));