diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-08-24 23:14:15 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-08-24 23:14:15 +0400 |
commit | 3efd07b6bd0c0bd86676b7e4dc8fe8e7c07645f2 (patch) | |
tree | cb2e3cf8217c42294b38ecfbc7891423814506c4 /main | |
parent | 2bbbb756c2deef2c36eab23c6330c2b99e8076e2 (diff) |
[MacDev] Use progress monitors for Xcode sync
Diffstat (limited to 'main')
3 files changed, 138 insertions, 70 deletions
diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs index 3f17135685..2c9ce32b1a 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeMonitor.cs @@ -70,14 +70,14 @@ namespace MonoDevelop.MacDev.XcodeSyncing return Directory.Exists (xcproj); } - public void UpdateProject (List<XcodeSyncedItem> allItems, XcodeProject emptyProject) + public void UpdateProject (IProgressMonitor monitor, List<XcodeSyncedItem> allItems, XcodeProject emptyProject) { items = allItems; - int workItem = 1; - Ide.IdeApp.Workbench.StatusBar.BeginProgress (GettextCatalog.GetString ("Updating synchronized project...")); + monitor.BeginTask (GettextCatalog.GetString ("Updating Xcode project..."), items.Count); + monitor.Log.WriteLine ("Updating synced project with {0} items", items.Count); XC4Debug.Log ("Updating synced project with {0} items", items.Count); - + var ctx = new XcodeSyncContext (projectDir, syncTimeCache); var toRemove = new HashSet<string> (itemMap.Keys); @@ -106,7 +106,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing bool removedOldProject = false; if (updateProject) { if (pendingProjectWrite == null && ProjectExists ()) { - XC4Debug.Log ("Project file needs to be updated, closing and removing old project"); + monitor.Log.WriteLine ("Project file needs to be updated, closing and removing old project"); CloseProject (); DeleteProjectArtifacts (); removedOldProject = true; @@ -134,19 +134,17 @@ namespace MonoDevelop.MacDev.XcodeSyncing } foreach (var item in syncList) { - XC4Debug.Log ("Syncing item {0}", item.GetTargetRelativeFileNames ()[0]); + monitor.Log.WriteLine ("Syncing item {0}", item.GetTargetRelativeFileNames ()[0]); item.SyncOut (ctx); - Ide.IdeApp.Workbench.StatusBar.SetProgressFraction (workItem / syncList.Count); - workItem++; + monitor.Step (1); } if (updateProject) { - XC4Debug.Log ("Queuing Xcode project {0} to write when opened", projectDir); + monitor.Log.WriteLine ("Queuing Xcode project {0} to write when opened", projectDir); pendingProjectWrite = emptyProject; } - - Ide.IdeApp.Workbench.StatusBar.EndProgress (); - Ide.IdeApp.Workbench.StatusBar.ShowMessage (GettextCatalog.GetString ("Synchronized project updated.")); + monitor.EndTask (); + monitor.ReportSuccess (GettextCatalog.GetString ("Xcode project updated.")); } // Xcode keeps some kind of internal lock on project files while it's running and @@ -206,7 +204,6 @@ namespace MonoDevelop.MacDev.XcodeSyncing public void SaveProject () { - XC4Debug.Log ("Saving Xcode project"); AppleScript.Run (XCODE_SAVE_IN_PATH, AppleSdkSettings.XcodePath, projectDir); } diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs index 1de8362a59..14964ad744 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeProjectTracker.cs @@ -117,41 +117,56 @@ namespace MonoDevelop.MacDev.XcodeSyncing return; bool isOpen = false; - try { - isOpen = xcode != null && xcode.IsProjectOpen (); + using (var monitor = GetStatusMonitor (GettextCatalog.GetString ("Synchronizing changes from Xcode"))) { + try { + isOpen = xcode != null && xcode.IsProjectOpen (); + if (isOpen) { + monitor.BeginTask (GettextCatalog.GetString ("Saving Xcode project"), 0); + xcode.SaveProject (); + } + } catch (Exception ex) { + MonoDevelop.Ide.MessageService.ShowError ( + GettextCatalog.GetString ("MonoDevelop could not communicate with XCode"), + GettextCatalog.GetString ( + "If XCode is still running, please ensure that all changes have been saved and " + + "XCode has been exited before continuing, otherwise any new changes may be lost.")); + monitor.Log.WriteLine ("XCode could not be made save pending changes: {0}", ex); + } if (isOpen) { - XC4Debug.Log ("Project open, ensuring files are saved"); - xcode.SaveProject (); + monitor.EndTask (); } - } catch (Exception ex) { - XC4Debug.Log ("XCode could not be made save pending changes: {0}", ex); - MonoDevelop.Ide.MessageService.ShowError ( - "MonoDevelop could not communicate with XCode", - "If XCode is still running, please ensure that all changes have been saved and XCode has been exited " + - "before continuing, otherwise any new changes may be lost."); + + SyncXcodeChanges (monitor); } - DetectXcodeChanges (); - if (!isOpen) { XC4Debug.Log ("Project closed, disabling syncing"); DisableSyncing (); } } - void OpenXcodeProject () + bool OpenXcodeProject () { - //FIXME: show a UI and progress while we do the initial sync - XC4Debug.Log ("Syncing to Xcode"); - EnableSyncing (); - UpdateTypes (true); - UpdateXcodeProject (); - xcode.OpenProject (); + using (var monitor = GetStatusMonitor (GettextCatalog.GetString ("Syncing to Xcode..."))) { + try { + EnableSyncing (); + if (!UpdateTypes (monitor, true) || monitor.IsCancelRequested) + return false; + if (!UpdateXcodeProject (monitor) || monitor.IsCancelRequested) + return false; + xcode.OpenProject (); + return true; + } catch (Exception ex) { + monitor.ReportError (GettextCatalog.GetString ("Could not open Xcode project"), ex); + } + } + return false; } public void OpenDocument (string file) { - OpenXcodeProject (); + if (!OpenXcodeProject ()) + return; XC4Debug.Log ("Opening file {0}", file); var xibFile = dnp.Files.GetFile (file); @@ -223,47 +238,82 @@ namespace MonoDevelop.MacDev.XcodeSyncing return; XC4Debug.Log ("Checking for changed files"); - bool updateTypes = false, update = false; + bool updateTypes = false, updateProject = false; foreach (ProjectFileEventInfo finf in e) { if (finf.Project != dnp) continue; if (finf.ProjectFile.BuildAction == BuildAction.Compile) { - updateTypes = update = true; + updateTypes = true; break; } else if (IncludeInSyncedProject (finf.ProjectFile)) { - update = true; + updateProject = true; + } + } + + if (updateTypes) { + using (var monitor = GetStatusMonitor (GettextCatalog.GetString ("Syncing to Xcode..."))) { + //FIXME: make this async (and safely async) + //FIXME: only update the project if obj-c types change + updateProject = UpdateTypes (monitor, true); } } - //FIXME: make this async - if (updateTypes) - UpdateTypes (true); - if (update) - UpdateXcodeProject (); + if (updateProject) { + using (var monitor = GetStatusMonitor (GettextCatalog.GetString ("Syncing to Xcode..."))) { + //FIXME: make this async (and safely async) + UpdateXcodeProject (monitor); + } + } + } + + #endregion + + #region Progress monitors + + //FIXME: should be use a modal monitor to prevent the user doing unexpected things? + IProgressMonitor GetStatusMonitor (string title) + { + IProgressMonitor monitor = MonoDevelop.Ide.IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor ( + title, null, true); + + monitor = new MonoDevelop.Core.ProgressMonitoring.AggregatedProgressMonitor ( + monitor, XC4Debug.GetLoggingMonitor ()); + + return monitor; } #endregion #region Outbound syncing - void UpdateTypes (bool force) + bool UpdateTypes (IProgressMonitor monitor, bool force) { - XC4Debug.Log ("Updating CLI type information"); - var pinfo = infoService.GetProjectInfo (dnp); - if (pinfo == null) { - Console.WriteLine ("Did not get project info"); - return; + monitor.BeginTask (GettextCatalog.GetString ("Updating Objective-C type information"), 0); + try { + var pinfo = infoService.GetProjectInfo (dnp); + if (pinfo == null) + throw new Exception ("Did not get project info"); + //FIXME: report progress + pinfo.Update (force); + userTypes = pinfo.GetTypes ().Where (t => t.IsUserType).ToList (); + return true; + } catch (Exception ex) { + monitor.ReportError (GettextCatalog.GetString ("Error updating Objective-C type information"), ex); + return false; } - pinfo.Update (force); - userTypes = pinfo.GetTypes ().Where (t => t.IsUserType).ToList (); } protected abstract XcodeProject CreateProject (string name); - //FIXME: report errors - void UpdateXcodeProject () + bool UpdateXcodeProject (IProgressMonitor monitor) { - xcode.UpdateProject (CreateSyncList (), CreateProject (dnp.Name)); + try { + xcode.UpdateProject (monitor, CreateSyncList (), CreateProject (dnp.Name)); + return true; + } catch (Exception ex) { + monitor.ReportError (GettextCatalog.GetString ("Error updating Xcode project"), ex); + return false; + } } List<XcodeSyncedItem> CreateSyncList () @@ -284,21 +334,30 @@ namespace MonoDevelop.MacDev.XcodeSyncing #region Inbound syncing - //FIXME: make this async so it doesn't block the UI - void DetectXcodeChanges () + bool SyncXcodeChanges (IProgressMonitor monitor) { - XC4Debug.Log ("Detecting changes in synced files"); - var changeCtx = xcode.GetChanges (infoService, dnp); - updatingProjectFiles = true; - UpdateCliTypes (changeCtx); - CopyFilesToMD (changeCtx); - updatingProjectFiles = false; + try { + monitor.BeginTask (GettextCatalog.GetString ("Detecting changed files in Xcode"), 0); + var changeCtx = xcode.GetChanges (infoService, dnp); + monitor.EndTask (); + updatingProjectFiles = true; + UpdateCliTypes (monitor, changeCtx); + CopyFilesToMD (monitor, changeCtx); + return true; + } catch (Exception ex) { + monitor.ReportError (GettextCatalog.GetString ("Error synchronizing changes from Xcode"), ex); + return false; + } finally { + updatingProjectFiles = false; + } } - void CopyFilesToMD (XcodeSyncBackContext context) + void CopyFilesToMD (IProgressMonitor monitor, XcodeSyncBackContext context) { + if (context.FileSyncJobs.Count == 0) + return; foreach (var file in context.FileSyncJobs) { - XC4Debug.Log ("Copying changed file from Xcode: {0}", file.SyncedRelative); + monitor.Log.WriteLine ("Copying changed file from Xcode: {0}", file.SyncedRelative); var tempFile = file.Original.ParentDirectory.Combine (".#" + file.Original.ParentDirectory.FileName); File.Copy (context.ProjectDir.Combine (file.SyncedRelative), tempFile); FileService.SystemRename (tempFile, file.Original); @@ -307,26 +366,31 @@ namespace MonoDevelop.MacDev.XcodeSyncing Gtk.Application.Invoke (delegate { FileService.NotifyFilesChanged (context.FileSyncJobs.Select (f => f.Original)); }); + monitor.EndTask (); } - //FIXME: error handling - void UpdateCliTypes (XcodeSyncBackContext context) + void UpdateCliTypes (IProgressMonitor monitor, XcodeSyncBackContext context) { + var provider = dnp.LanguageBinding.GetCodeDomProvider (); var options = new System.CodeDom.Compiler.CodeGeneratorOptions (); var writer = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject ( new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor (), dnp); + monitor.BeginTask (GettextCatalog.GetString ("Detecting changed types from Xcode"), 0); Dictionary<string,ProjectFile> newFiles; - XC4Debug.Log ("Getting changed types from Xcode"); var updates = context.GetTypeUpdates (out newFiles); if (updates == null || updates.Count == 0) { - XC4Debug.Log ("No changed types from Xcode found"); + monitor.Log.WriteLine ("No changed types found"); + monitor.EndTask (); return; } + monitor.Log.WriteLine ("Found {0} changed types", updates.Count); + monitor.EndTask (); + monitor.BeginTask (GettextCatalog.GetString ("Updating types in MonoDevelop"), updates.Count); foreach (var df in updates) { - XC4Debug.Log ("Syncing {0} types from Xcode to file {1}", df.Value.Count, df.Key); + monitor.Log.WriteLine ("Syncing {0} types from Xcode to file '{1}'", df.Value.Count, df.Key); if (provider is Microsoft.CSharp.CSharpCodeProvider) { var cs = new CSharpCodeCodebehind () { Types = df.Value, @@ -338,6 +402,7 @@ namespace MonoDevelop.MacDev.XcodeSyncing var ccu = GenerateCompileUnit (provider, options, df.Key, df.Value); writer.WriteFile (df.Key, ccu); } + monitor.Step (1); } writer.WriteOpenFiles (); @@ -354,11 +419,13 @@ namespace MonoDevelop.MacDev.XcodeSyncing if (newFiles != null) { foreach (var f in newFiles) { - XC4Debug.Log ("Added new designer files {0}", f.Key); + monitor.Log.WriteLine ("Added new designer file {0}", f.Key); dnp.AddFile (f.Value); } + monitor.Log.WriteLine ("Saving project '{0}'", dnp.Name); Ide.IdeApp.ProjectOperations.Save (dnp); } + monitor.EndTask (); } System.CodeDom.CodeCompileUnit GenerateCompileUnit (System.CodeDom.Compiler.CodeDomProvider provider, @@ -421,5 +488,10 @@ namespace MonoDevelop.MacDev.XcodeSyncing return; writer.WriteLine (messageFormat, values); } + + public static IProgressMonitor GetLoggingMonitor () + { + return new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor (writer); + } } -}
\ No newline at end of file +} diff --git a/main/src/core/MonoDevelop.Ide/gtk-gui/MonoDevelop.Ide.Gui.Dialogs.TipOfTheDayWindow.cs b/main/src/core/MonoDevelop.Ide/gtk-gui/MonoDevelop.Ide.Gui.Dialogs.TipOfTheDayWindow.cs index 890fbc07a9..5bc366d997 100644 --- a/main/src/core/MonoDevelop.Ide/gtk-gui/MonoDevelop.Ide.Gui.Dialogs.TipOfTheDayWindow.cs +++ b/main/src/core/MonoDevelop.Ide/gtk-gui/MonoDevelop.Ide.Gui.Dialogs.TipOfTheDayWindow.cs @@ -100,7 +100,6 @@ namespace MonoDevelop.Ide.Gui.Dialogs w7.Fill = false; // Container child hbox5.Gtk.Box+BoxChild this.hbuttonbox1 = new global::Gtk.HButtonBox (); - this.hbuttonbox1.Name = "hbuttonbox1"; this.hbuttonbox1.Spacing = 10; this.hbuttonbox1.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); // Container child hbuttonbox1.Gtk.ButtonBox+ButtonBoxChild |