void AppRegainedFocus(object sender, EventArgs e) { if (!syncing) { return; } bool isOpen = false; 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) { monitor.EndTask(); } SyncXcodeChanges(monitor); } if (!isOpen) { XC4Debug.Log("Project closed, disabling syncing"); DisableSyncing(); } }
void AppRegainedFocus(object sender, EventArgs e) { lock (xcode_lock) { if (!SyncingEnabled) { return; } XC4Debug.Log("MonoDevelop has regained focus."); using (var monitor = GetStatusMonitor(GettextCatalog.GetString("Synchronizing changes from Xcode..."))) { bool projectOpen = false; try { // Note: Both IsProjectOpen() and SaveProject() may throw TimeoutExceptions or AppleScriptExceptions if ((projectOpen = xcode.IsProjectOpen())) { xcode.SaveProject(monitor); } } catch (Exception ex) { ShowXcodeScriptError(); monitor.Log.WriteLine("Xcode failed to save pending changes to project: {0}", ex); // Note: This will cause us to disable syncing after we sync whatever we can over from Xcode... projectOpen = false; } try { SyncXcodeChanges(monitor); } finally { if (!projectOpen) { XC4Debug.Log("Xcode project for '{0}' is not open, disabling syncing.", dnp.Name); DisableSyncing(false); } } } } }