private void AssociateOpenedFiles(NppLanguage lang)
        {
            SelectedLanguage = lang;

            Main.LangDetector.AddOrUpdateExtension(lang.Name, tbExtension.Text);
            Main.SaveLangs();

            //TODO: save and restore current active view and index
            string extWithDot = Utils.AppendDotToExtension(tbExtension.Text);
            var langType = (int)lang.LangType;
            foreach (var file in _openedFiles)
            {
                if (!Utils.IsFileNew(file.Path) && Path.GetExtension(file.Path) == extWithDot)
                {
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, file.View, file.Index);
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_SETCURRENTLANGTYPE, 0, langType);
                }
            }
        }
        public dlgAssociateExtension(List<FilePathViewIndex> files, string fileText, List<FilePathViewIndex> openedFiles)
        {
            InitializeComponent();

            _currentFiles = files;
            string shortFileName = Path.GetFileName(files.First().Path);
            Text = string.Format("Associate Extension of file \"{0}\"", shortFileName);
            tbExtension.Text = Utils.GetExtensionWithoutDot(shortFileName);
            _currentFileText = fileText;
            _openedFiles = openedFiles;
            _selectedItem = null;
            foreach (var lang in Main.LangDetector.Languages)
            {
                if (_selectedItem == null && lang.Value.Extensions.Contains(tbExtension.Text))
                    _selectedItem = lang.Value;
                cmbLanguage.Items.Add(lang.Value);
            }
            // TODO: Add lang autodetection
            _defaultLanguage = _selectedItem == null ? Main.LangDetector.Languages.First().Value : _selectedItem;
            cmbLanguage.SelectedItem = _defaultLanguage;
            SelectedLanguage = null;

            btnYes.Select();
        }
Beispiel #3
0
        private static Dictionary<string, NppLanguage> XmlToNppLangs(NotepadPlusLanguages xmlLangs, NotepadPlusStylers xmlStylers)
        {
            var result = new Dictionary<string, NppLanguage>(xmlLangs.Languages.Length);
            var splitChars = new char[] { ' ' };
            foreach (var xmlLang in xmlLangs.Languages)
            {
                var lang = new NppLanguage
                {
                    Name = xmlLang.Name,
                    Extensions = xmlLang.Extension.Split(splitChars, StringSplitOptions.RemoveEmptyEntries).ToList(),
                    CommentLine = xmlLang.CommentLine,
                    CommentStart = xmlLang.CommentStart,
                    CommentEnd = xmlLang.CommentEnd,
                };

                var lexerType = xmlStylers.LexerStyles.FirstOrDefault(style => style.Name == xmlLang.Name);
                if (lexerType != null)
                    lang.Description = lexerType.Description;
                else
                {
                    if (lang.Name == "normal")
                        lang.Description = "Normal Text";
                    else
                        lang.Description = lang.Name;
                }

                LangType langType;
                if (Enum.TryParse("L_" + lang.Name.ToUpperInvariant(), out langType))
                    lang.LangType = langType;
                else
                {
                    switch (lang.Name)
                    {
                        case "actionscript":
                            lang.LangType = LangType.L_FLASH;
                            break;
                        case "autoit":
                            lang.LangType = LangType.L_AU3;
                            break;
                        case "coffeescript":
                            lang.LangType = LangType.L_EXTERNAL;
                            break;
                        case "javascript":
                            lang.LangType = LangType.L_JS;
                            break;
                        case "nfo":
                            lang.LangType = LangType.L_ASCII;
                            break;
                        case "normal":
                            lang.LangType = LangType.L_TEXT;
                            break;
                        case "postscript":
                            lang.LangType = LangType.L_PS;
                            break;
                    }
                }

                lang.Keywords = new Dictionary<string, List<string>>();
                if (xmlLang.Keywords != null)
                    foreach (var keyword in xmlLang.Keywords)
                        lang.Keywords.Add(keyword.Name, keyword.Value == null ?
                            new List<string>() : keyword.Value.Split(' ').ToList());

                result.Add(lang.Name, lang);
            }

            result.Add(UserDefined, new NppLanguage
            {
                Name = UserDefined,
                LangType = LangType.L_USER,
                Extensions = new List<string>(),
                Keywords = new Dictionary<string,List<string>>(),
                Description = "User-Defined"
            });

            return result;
        }