/// <summary> /// Performs custom actions when FileChanged event occurs. /// Updates current document if necessary.</summary> /// <param name="sender">Event sender</param> /// <param name="e">FileSystemEventArgs containing event data</param> void fileWatcherService_FileChanged(object sender, FileSystemEventArgs e) { if (m_mainForm == null || m_reloading) { return; } // First test if this document is a "master" document var uri = new Uri(e.FullPath); var doc = m_documentRegistry.GetDocument(uri) as TimelineDocument; if (doc == null || doc.TimelineControl == null) { // It's not a master document. Check if it's already loaded. Since sub-documents are read-only, // we don't need to ask the user if they want to reload. Just do it. doc = s_repository.GetDocument(uri) as TimelineDocument; if (doc != null) { s_repository.Remove(doc); WinFormsUtil.InvokeIfRequired(m_mainForm, delegate { LoadOrCreateDocument(uri, false); InvalidateTimelineControls(); }); } return; } // This is a master document. Query the user and if it's OK, then close it and reopen it, and this // will update other open master documents that might reference this one as a sub-document. WinFormsUtil.InvokeIfRequired(m_mainForm, delegate { DialogResult result = MessageBox.Show( m_mainForm, doc.Uri.LocalPath + Environment.NewLine + Environment.NewLine + "The file above was changed outside the editor.".Localize() + Environment.NewLine + "Reload, and lose all changes made in the editor?".Localize(), "File Changed, Reload?".Localize(), MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { // Reload the document m_reloading = true; doc.Dirty = false; Close(doc.TimelineControl); Open(doc.Uri); m_reloading = false; InvalidateTimelineControls(); } }); }
/// <summary> /// Performs custom actions on CommandLineChanged events. /// This is also called whenever another instance of this application launches.</summary> /// <param name="sender">Event sender</param> /// <param name="e">EventArgs containing event data</param> void m_singleInstanceService_CommandLineChanged(object sender, EventArgs e) { // attempt to load a document whose path is on the command line var msg = new StringBuilder( "Another instance of StatechartEditorSample was launched. The command line changed to: ".Localize()); string documentPath = null; for (int i = 0; i < m_singleInstanceService.CommandLine.Length; i++) { string line = m_singleInstanceService.CommandLine[i]; // assume the last parameter is the filename if (i > 0 && i == m_singleInstanceService.CommandLine.Length - 1) { documentPath = line; } msg.AppendLine(line); } Outputs.WriteLine(OutputMessageType.Info, msg.ToString()); // we should bring our app to the forefront if (m_mainForm != null) { WinFormsUtil.InvokeIfRequired(m_mainForm, () => { m_mainForm.BringToFront(); //needs to be called on GUI thread if (documentPath != null) { Uri uri = new Uri(documentPath); if (CanOpen(uri)) { Open(uri); //needs to be called on GUI thread } } }); } }
private void ShutDownTimer_Elapsed(object sender, ElapsedEventArgs e) { WinFormsUtil.InvokeIfRequired(m_maiForm, () => m_maiForm.Close()); }