示例#1
0
        void AddColorScheme(object sender, EventArgs args)
        {
            var dialog = new SelectFileDialog(GettextCatalog.GetString("Import Color Theme"), MonoDevelop.Components.FileChooserAction.Open)
            {
                TransientFor = this.Toplevel as Gtk.Window,
            };

            dialog.AddFilter(GettextCatalog.GetString("Color themes (Visual Studio, Xamarin Studio, TextMate) "), "*.json", "*.vssettings", "*.tmTheme");
            if (!dialog.Run())
            {
                return;
            }

            var    fileName    = dialog.SelectedFile.FileName;
            var    filePath    = dialog.SelectedFile.FullPath;
            string newFilePath = SyntaxHighlightingService.SyntaxModePath.Combine(fileName);

            if (!SyntaxHighlightingService.IsValidTheme(filePath))
            {
                MessageService.ShowError(GettextCatalog.GetString("Could not import color theme."));
                return;
            }

            bool success = true;

            try {
                if (File.Exists(newFilePath))
                {
                    var answer = MessageService.AskQuestion(
                        GettextCatalog.GetString(
                            "A color theme with the name '{0}' already exists in your theme folder. Would you like to replace it?",
                            fileName
                            ),
                        AlertButton.Cancel,
                        AlertButton.Replace
                        );
                    if (answer != AlertButton.Replace)
                    {
                        return;
                    }
                    File.Delete(newFilePath);
                }
                File.Copy(filePath, newFilePath);
            } catch (Exception e) {
                success = false;
                LoggingService.LogError("Can't copy color theme file.", e);
            }
            if (success)
            {
                SyntaxHighlightingService.LoadCustomStylesAndModes();
                ShowStyles();
            }
        }