private void AddSettingsButton_Click(object sender, EventArgs e)
        {
            DialogResult dr = SettingsSaveFileDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string filename = SettingsSaveFileDialog.FileName;

                Settings newSettings = new Settings();
                newSettings.Save(filename);

                ListViewItem lvi = new ListViewItem();
                lvi.Text = newSettings.ApplicationShortName;
                IconImageList.Images.Add(this.Icon);
                lvi.ImageIndex = IconImageList.Images.Count - 1;
                lvi.Tag        = filename;

                this.primaryHost.AddLaunchHistory(
                    filename,
                    newSettings.ApplicationShortName,
                    newSettings.ApplicationDescription,
                    newSettings.WindowIconPath
                    );

                AppHistoryListView.Items.Add(lvi);

                AppHistoryListView.SelectedIndices.Clear();
                AppHistoryListView.SelectedIndices.Add(AppHistoryListView.Items.Count - 1);
                AppHistoryListView.Focus();
            }
        }
Esempio n. 2
0
        private void SaveDocument(string fileName)
        {
            Program.Settings.InfoText = LayoutRichTextBox.Rtf;
            Program.Settings.SaveRelativeImagePaths = trySavingRelativePathsToolStripMenuItem.Checked;

            if (Program.Settings.SaveRelativeImagePaths)
            {
                if (Program.Settings.UseBackgroundsFolder)
                {
                    Program.Settings.BackgroundsFolder = MakePathRelative(Program.Settings.BackgroundsFolder);
                }
                foreach (ImageOverlay overlay in Program.Settings.Overlays)
                {
                    overlay.FullPath = MakePathRelative(overlay.FullPath);
                }
            }

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ProgramSettings));
                Stream        file;

                if (string.IsNullOrEmpty(fileName))
                {
                    DialogResult result = SettingsSaveFileDialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        file      = SettingsSaveFileDialog.OpenFile();
                        _fileName = SettingsSaveFileDialog.FileName;
                        serializer.Serialize(file, Program.Settings);
                        file.Close();
                    }
                }
                else
                {
                    file = new FileStream(fileName, FileMode.Create);
                    serializer.Serialize(file, Program.Settings);
                    file.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("An error has occured while attempting to save the settings file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }