Example #1
0
        private void Backstage_PopulateRecentFiles()
        {
            List <string> paths = RecentFiles.GetFileNames();

            dpRecentFiles.Children.Clear();
            foreach (string path in paths)
            {
                try {
                    RecentFileButton button = new RecentFileButton {
                        DirPath   = Path.GetDirectoryName(path),
                        FileName  = Path.GetFileName(path),
                        IsEnabled = File.Exists(path),
                        Tag       = path,
                        ToolTip   = path
                    };
                    DockPanel.SetDock(button, Dock.Top);

                    dpRecentFiles.Children.Add(button);
                }
                catch (ArgumentException) {
                    RecentFiles.Remove(path);
                }
                catch (PathTooLongException) {
                    RecentFiles.Remove(path);
                }
            }
        }
Example #2
0
 private void Backstage_CmdRecentFileRemove_Executed(object sender, ExecutedRoutedEventArgs evt)
 {
     if (evt.Source is RecentFileButton button)
     {
         RecentFiles.Remove((string)button.Tag);
         Backstage_PopulateRecentFiles();
     }
 }
Example #3
0
 private void Backstage_CleanRecentFiles()
 {
     foreach (UIElement element in dpRecentFiles.Children)
     {
         if (element is RecentFileButton button)
         {
             if (!button.IsEnabled)
             {
                 RecentFiles.Remove((string)button.Tag);
             }
         }
     }
 }
Example #4
0
        // Event handler: Exit

        private void Exit_Handler(object sender, ExitEventArgs evt)
        {
            if (!IsPortableMode)
            {
                RecentFiles.Save();
                Settings.Default.Save();
            }

            if (RestartPending)
            {
                Process.Start(App.GetLocation());
            }
        }
Example #5
0
        private void OpenDeviceCollection(string fileName = null)
        {
            Settings settings = Settings.Default;

            if (fileName != null && string.Compare(fileName, Devices.FileName, App.defaultFileNameComparison) == 0)
            {
                return;
            }

            if (!SaveUnsavedData())
            {
                return;
            }

            if (fileName == null)
            {
                OpenFileDialog ofd = new OpenFileDialog()
                {
                    AddExtension     = false,
                    CheckFileExists  = true,
                    CheckPathExists  = true,
                    Filter           = JCstring.FilterFilesXML,
                    InitialDirectory = Directory.Exists(settings.LastDocumentDirectory) ? settings.LastDocumentDirectory : App.GetDefaultDirectory(),
                    ReadOnlyChecked  = false,
                    ShowReadOnly     = false,
                    Title            = JCstring.DialogCaptionOpen,
                    ValidateNames    = true
                };

                if (ofd.ShowDialog(this) != true)
                {
                    return;
                }
                settings.LastDocumentDirectory = Path.GetDirectoryName(ofd.FileName);

                fileName = ofd.FileName;
            }

            try {
                Devices_InitDataGrid();
                Devices.Load(fileName);
                RecentFiles.Add(fileName);
            }
            catch (Exception ex) {
                ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, JCstring.MessageTextOpenDeviceCollectionFailed.Unescape(), ex.Message));
            }
        }
        private void OpenDeviceCollection(string fileName = null)
        {
            if (fileName != null && string.Compare(fileName, Devices.FileName, true) == 0)
            {
                return;
            }

            if (!SaveUnsavedData())
            {
                return;
            }

            if (fileName == null)
            {
                OpenFileDialog ofd = new OpenFileDialog()
                {
                    AddExtension     = false,
                    CheckFileExists  = true,
                    CheckPathExists  = true,
                    Filter           = "XML files (*.xml)|*.xml",
                    InitialDirectory = Directory.Exists(AppSettings.LastDirectoryPath) ? AppSettings.LastDirectoryPath : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                    ReadOnlyChecked  = false,
                    ShowReadOnly     = false,
                    Title            = JCstring.DialogCaptionOpen,
                    ValidateNames    = true
                };

                if (ofd.ShowDialog(this) != true)
                {
                    return;
                }
                AppSettings.LastDirectoryPath = Path.GetDirectoryName(ofd.FileName);

                fileName = ofd.FileName;
            }

            try {
                Devices_InitDataGrid();
                Devices.Load(fileName);
                RecentFiles.Add(fileName);
            }
            catch (Exception ex) {
                ShowErrorMessage(string.Format(JCstring.MessageTextOpenDeviceCollectionFailed.Unescape(), ex.Message));
            }
        }
Example #7
0
        private bool SaveDeviceCollectionAs()
        {
            Settings settings = Settings.Default;

            SaveFileDialog sfd = new SaveFileDialog {
                AddExtension    = true,
                CheckFileExists = false,
                CheckPathExists = true,
                CreatePrompt    = false,
                DefaultExt      = "xml",
                Filter          = JCstring.FilterFilesXML,
                OverwritePrompt = true,
                Title           = JCstring.DialogCaptionSave,
                ValidateNames   = true
            };

            if (Devices.FileName == null)
            {
                sfd.InitialDirectory = Directory.Exists(settings.LastDocumentDirectory) ? settings.LastDocumentDirectory : App.GetDefaultDirectory();
                sfd.FileName         = string.Empty;
            }
            else
            {
                sfd.InitialDirectory = Path.GetDirectoryName(Devices.FileName);
                sfd.FileName         = Path.GetFileName(Devices.FileName);
            }

            if (sfd.ShowDialog(this) != true)
            {
                return(false);
            }
            settings.LastDocumentDirectory = Path.GetDirectoryName(sfd.FileName);

            try {
                Devices.Save(sfd.FileName);
                RecentFiles.Add(sfd.FileName);
                return(true);
            }
            catch (Exception ex) {
                ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, JCstring.MessageTextSaveDeviceCollectionFailed.Unescape(), ex.Message));
                return(false);
            }
        }
        private bool SaveDeviceCollectionAs()
        {
            SaveFileDialog sfd = new SaveFileDialog {
                AddExtension    = true,
                CheckFileExists = false,
                CheckPathExists = true,
                CreatePrompt    = false,
                DefaultExt      = "xml",
                Filter          = "XML files (*.xml)|*.xml",
                OverwritePrompt = true,
                Title           = JCstring.DialogCaptionSave,
                ValidateNames   = true
            };

            if (Devices.FileName == null)
            {
                sfd.InitialDirectory = Directory.Exists(AppSettings.LastDirectoryPath) ? AppSettings.LastDirectoryPath : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                sfd.FileName         = string.Empty;
            }
            else
            {
                sfd.InitialDirectory = Path.GetDirectoryName(Devices.FileName);
                sfd.FileName         = Path.GetFileName(Devices.FileName);
            }

            if (sfd.ShowDialog(this) != true)
            {
                return(false);
            }
            AppSettings.LastDirectoryPath = Path.GetDirectoryName(sfd.FileName);

            try {
                Devices.Save(sfd.FileName);
                RecentFiles.Add(sfd.FileName);
                return(true);
            }
            catch (Exception ex) {
                ShowErrorMessage(string.Format(JCstring.MessageTextSaveDeviceCollectionFailed.Unescape(), ex.Message));
                return(false);
            }
        }
Example #9
0
 private void Backstage_CmdRecentFilesClear_Executed(object sender, ExecutedRoutedEventArgs evt)
 {
     RecentFiles.Clear();
     Backstage_PopulateRecentFiles();
 }
Example #10
0
        // Event: Exit

        private void Exit_Handler(object sender, ExitEventArgs evt)
        {
            RecentFiles.Save();
            Settings.Default.Save();
        }