Exemple #1
0
 internal static void DetectLanguage()
 {
     if (Settings.ShowDetectLanguageDialog)
     {
         var dlgDetectLanguage = new dlgDetectLanguage(PluginBase.GetFullCurrentFileName(), PluginBase.GetCurrentFileText());
         dlgDetectLanguage.ShowDialog();
     }
 }
        internal static void FileModified()
        {
            int length = Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETLENGTH, 0, 0).ToInt32();
            if (_prevLength == 0 && length > MinTextLength)
            {
                _prevLength = length;

                if (Utils.IsFileNew(PluginBase.GetFullCurrentFileName()))
                {
                    if (Main.Settings.DetectLanguageAutomatically)
                    {
                        var text = PluginBase.GetCurrentFileText(length);
                        if (Main.Settings.ShowDetectLanguageDialog)
                        {
                            var detectLangDialog = new dlgDetectLanguage(PluginBase.GetFullCurrentFileName(), text);
                            detectLangDialog.ShowDialog();
                        }
                        else
                        {
                            // TODO: autodetection
                        }
                    }
                }
            }
            else
                _prevLength = length;
        }
        static void ProcessOpenedFiles()
        {
            while (_openedFiles.Count > 0)
            {
                var openedFile = _openedFiles.Dequeue();

                string extension = Utils.GetExtensionWithoutDot(openedFile.Path);
                if (extension == "")
                {
                    if (!Main.PrevSessionFiles.Contains(openedFile.Path))
                    {
                        Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, openedFile.View, openedFile.Index);
                        if (Main.Settings.CheckEmptyExtensionFiles)
                        {
                            var text = PluginBase.GetCurrentFileText();
                            if (Main.Settings.ShowDetectLanguageDialog)
                            {
                                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, openedFile.View, openedFile.Index);
                                var detectLangDialog = new dlgDetectLanguage(openedFile.Path, text);
                                detectLangDialog.ShowDialog(Control.FromHandle(PluginBase.nppData._nppHandle));
                            }
                            else
                            {
                                // TODO: autodetection
                            }
                        }
                    }
                }
                else
                {
                    if (!Main.LangDetector.ContainsExtension(extension))
                    {
                        Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, openedFile.View, openedFile.Index);
                        var associateExtDialog = new dlgAssociateExtension(openedFile, PluginBase.GetCurrentFileText(), PluginBase.GetOpenedFiles());
                        var dlgResult = associateExtDialog.ShowDialog(Control.FromHandle(PluginBase.nppData._nppHandle));
                        if (associateExtDialog.SelectedLanguage != null && !_newlyAddedExtensions.ContainsKey(extension))
                            _newlyAddedExtensions.Add(extension, associateExtDialog.SelectedLanguage);
                    }
                    else if (_newlyAddedExtensions.ContainsKey(extension))
                    {
                        Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, openedFile.View, openedFile.Index);
                        Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_SETCURRENTLANGTYPE, 0, (int)_newlyAddedExtensions[extension].LangType);
                    }
                }
            }
            _fileRecentlyOpened = false;
        }