private void OnFillSvgInputChecked() { if (_svgPage == null) { tabSvgInput.Visibility = _optionSettings.ShowInputFile ? Visibility.Visible : Visibility.Collapsed; return; } Cursor saveCursor = this.Cursor; try { if (_optionSettings.ShowInputFile) { this.Cursor = Cursors.Wait; this.ForceCursor = true; if (File.Exists(_svgFilePath)) { _svgPage.LoadDocument(_svgFilePath); } else { _svgPage.UnloadDocument(); } } else { _svgPage.UnloadDocument(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), AppErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error); } finally { this.Cursor = saveCursor; this.ForceCursor = false; tabSvgInput.Visibility = _optionSettings.ShowInputFile ? Visibility.Visible : Visibility.Collapsed; } }
private void LoadFile(string fileName) { string fileExt = IoPath.GetExtension(fileName); if (String.IsNullOrEmpty(fileExt)) { return; } if (_fileWatcher != null) { _fileWatcher.EnableRaisingEvents = false; } bool generateXaml = (fillXamlOutput.IsChecked != null && fillXamlOutput.IsChecked.Value); if (String.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase) || String.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase)) { txtSvgFile.Text = fileName; txtSvgFileLabel.Text = "Selected SVG File:"; _svgFilePath = fileName; if (_svgPage != null && (fillSvgInput.IsChecked != null && fillSvgInput.IsChecked.Value)) { _svgPage.LoadDocument(fileName); } if (_drawingPage == null) { return; } _drawingPage.SaveXaml = generateXaml; try { if (_drawingPage.LoadDocument(fileName)) { this.Title = _titleBase + " - " + IoPath.GetFileName(fileName); if (_xamlPage != null && !String.IsNullOrEmpty(_drawingDir)) { string xamlFilePath = IoPath.Combine(_drawingDir, IoPath.GetFileNameWithoutExtension(fileName) + ".xaml"); _xamlFilePath = xamlFilePath; _canDeleteXaml = true; if (File.Exists(xamlFilePath) && (fillXamlOutput.IsChecked != null && fillXamlOutput.IsChecked.Value)) { _xamlPage.LoadDocument(xamlFilePath); // Delete the file after loading it... File.Delete(xamlFilePath); } } if (_fileWatcher == null) { // Create a new FileSystemWatcher and set its properties. _fileWatcher = new FileSystemWatcher(); // Watch for changes in LastAccess and LastWrite times _fileWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite; _fileWatcher.IncludeSubdirectories = false; // Add event handlers. _fileWatcher.Changed += new FileSystemEventHandler(OnFileChanged); _fileWatcher.Created += new FileSystemEventHandler(OnFileChanged); _fileWatcher.Deleted += new FileSystemEventHandler(OnFileChanged); _fileWatcher.Renamed += new RenamedEventHandler(OnFileRenamed); } _fileWatcher.Path = IoPath.GetDirectoryName(fileName); // Only watch current file _fileWatcher.Filter = IoPath.GetFileName(fileName); // Begin watching. _fileWatcher.EnableRaisingEvents = true; } } catch { // Try loading the XAML, if generated but the rendering failed... if (_xamlPage != null && !String.IsNullOrEmpty(_drawingDir)) { string xamlFilePath = IoPath.Combine(_drawingDir, IoPath.GetFileNameWithoutExtension(fileName) + ".xaml"); _xamlFilePath = xamlFilePath; _canDeleteXaml = true; if (File.Exists(xamlFilePath) && (fillXamlOutput.IsChecked != null && fillXamlOutput.IsChecked.Value)) { _xamlPage.LoadDocument(xamlFilePath); // Delete the file after loading it... File.Delete(xamlFilePath); } } throw; } } else if (String.Equals(fileExt, ".xaml", StringComparison.OrdinalIgnoreCase) || String.Equals(fileExt, ".zaml", StringComparison.OrdinalIgnoreCase)) { txtSvgFile.Text = fileName; txtSvgFileLabel.Text = "Selected XAML File:"; if (_svgPage != null) { _svgPage.UnloadDocument(); _svgFilePath = null; } try { if (_drawingPage.LoadDocument(fileName)) { this.Title = _titleBase + " - " + IoPath.GetFileName(fileName); _xamlFilePath = fileName; _canDeleteXaml = false; if (_xamlPage != null) { _xamlPage.LoadDocument(fileName); } } } catch { if (_xamlPage != null) { _xamlFilePath = fileName; _canDeleteXaml = false; _xamlPage.LoadDocument(fileName); } throw; } } }