public static void ShowTheDialog() { try { IntPtr hWnd = FindWindow(null, "C# Regex Tools"); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } else { var dialog = new RegExToolDialog { GetText = () => BNpp.Text, SetText = (string text) => { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { BNpp.NotepadPP.FileNew(); } BNpp.Text = text; }, SetTextInNew = (string text) => { BNpp.NotepadPP.FileNew(); BNpp.Text = text; }, GetSelectedText = () => BNpp.SelectedText, SetPosition = (int index, int length) => BNpp.SelectTextAndShow(index, index + length), SetSelection = (int index, int length) => BNpp.AddSelection(index, index + length), GetSelectionStartIndex = () => BNpp.SelectionStart, GetSelectionLength = () => BNpp.SelectionLength, SaveCurrentDocument = () => BNpp.NotepadPP.SaveCurrentFile(), TryOpen = (string fileName, bool onlyIfAlreadyOpen) => { try { bool result = false; if (BNpp.NotepadPP.CurrentFileName.ToLower().Equals(fileName.ToLower())) { result = true; } else if (BNpp.NotepadPP.GetAllOpenedDocuments.Any((string s) => s.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { BNpp.NotepadPP.ShowOpenedDocument(fileName); result = true; } else if (!onlyIfAlreadyOpen) { result = BNpp.NotepadPP.OpenFile(fileName); } else { result = false; } hWnd = FindWindow(null, "C# Regex Tool"); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } return(result); } catch { return(false); } }, GetCurrentFileName = () => BNpp.NotepadPP.CurrentFileName }; dialog.Show(); SetWindowLong(new WindowInteropHelper(dialog).Handle, (int)WindowLongFlags.GWLP_HWNDPARENT, PluginBase.nppData._nppHandle); SetLayeredWindowAttributes(new WindowInteropHelper(dialog).Handle, 0, 128, LWA_ALPHA); } } catch (Exception exception) { MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void ShowTheDialog() { try { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = @"plugins\CSharpRegexTools4Npp"; IntPtr hWnd = FindWindow(null, "C# Regex Tools - " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } else { RegExToolDialog dialog = null; RegExToolDialog.InitIsOK = () => CheckUpdates(dialog); dialog = new RegExToolDialog { GetText = () => Npp.Text, SetText = text => { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { Npp.NotepadPP.FileNew(); } Npp.Text = text; }, SetTextInNew = text => { Npp.NotepadPP.FileNew(); Npp.Text = text; }, GetSelectedText = () => Npp.SelectedText, SetPosition = (index, length) => Npp.SelectTextAndShow(index, index + length), SetSelection = (index, length) => Npp.AddSelection(index, index + length), GetSelectionStartIndex = () => Npp.SelectionStart, GetSelectionLength = () => Npp.SelectionLength, SaveCurrentDocument = () => Npp.NotepadPP.SaveCurrentFile(), SetCurrentTabInCSharpHighlighting = () => Npp.NotepadPP.SetCurrentLanguage(LangType.L_CS), TryOpen = (fileName, onlyIfAlreadyOpen) => { try { bool result = false; if (Npp.NotepadPP.CurrentFileName.Equals(fileName, StringComparison.OrdinalIgnoreCase)) { result = true; } else if (Npp.NotepadPP.GetAllOpenedDocuments.Any(s => s.Equals(fileName, StringComparison.OrdinalIgnoreCase))) { Npp.NotepadPP.ShowTab(fileName); result = true; } else if (!onlyIfAlreadyOpen) { result = Npp.NotepadPP.OpenFile(fileName); } else { result = false; } hWnd = FindWindow(null, "C# Regex Tool - " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (hWnd.ToInt64() > 0) { SetForegroundWindow(hWnd); } return(result); } catch { return(false); } }, GetCurrentFileName = () => Npp.NotepadPP.CurrentFileName }; dialog.Show(); SetWindowLong(new WindowInteropHelper(dialog).Handle, (int)WindowLongFlags.GWLP_HWNDPARENT, PluginBase.nppData._nppHandle); SetLayeredWindowAttributes(new WindowInteropHelper(dialog).Handle, 0, 128, LWA_ALPHA); } } catch (Exception exception) { MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace, "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); } }