Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 internal static void AssociateExtension()
 {
     var dlgAssociateExtension = new dlgAssociateExtension(PluginBase.GetCurrentFiles(), PluginBase.GetCurrentFileText(), PluginBase.GetOpenedFiles());
     dlgAssociateExtension.ShowDialog();
 }