From 1e1e9f009c881014b8d0a4e6d6ac5871e5ea244d Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 23 Oct 2022 14:57:07 +0200 Subject: [PATCH] Fix for PascalABC.NET for Linux --- VisualPascalABCNETLinux/FileMonitoring.cs | 54 +++++++++++++---------- VisualPascalABCNETLinux/ReplaceForm.cs | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/VisualPascalABCNETLinux/FileMonitoring.cs b/VisualPascalABCNETLinux/FileMonitoring.cs index 43d29f1bd..3dbc57744 100644 --- a/VisualPascalABCNETLinux/FileMonitoring.cs +++ b/VisualPascalABCNETLinux/FileMonitoring.cs @@ -88,6 +88,34 @@ namespace VisualPascalABC } } + void showChangedFileMessage() + { + string mes = null; + if (!File.Exists(fileName)) + { + mes = Form1StringResources.Get("FILE_NOT_EXIST_MESSAGE"); + if (MessageBox.Show(fileName + "\n\n" + mes, Form1StringResources.Get("CHANGED_FILE"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + WorkbenchServiceFactory.FileService.SetFileAsChanged(fileName); + } + else + { + WorkbenchServiceFactory.FileService.CloseFile(fileName); + } + return; + } + + mes = Form1StringResources.Get("FILE_CHANGED_MESSAGE"); + if (MessageBox.Show(fileName + "\n\n" + mes, Form1StringResources.Get("CHANGED_FILE"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + WorkbenchServiceFactory.FileService.ReloadFile(fileName); + } + else + { + WorkbenchServiceFactory.FileService.SetFileAsChanged(fileName); + } + } + void MainForm_Activated(object sender, EventArgs e) { try @@ -96,30 +124,8 @@ namespace VisualPascalABC { wasChangedExternally = false; - string mes = null; - if (!File.Exists(fileName)) - { - mes = Form1StringResources.Get("FILE_NOT_EXIST_MESSAGE"); - if (MessageBox.Show(fileName + "\n\n" + mes, Form1StringResources.Get("CHANGED_FILE"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - WorkbenchServiceFactory.FileService.SetFileAsChanged(fileName); - } - else - { - WorkbenchServiceFactory.FileService.CloseFile(fileName); - } - return; - } - - mes = Form1StringResources.Get("FILE_CHANGED_MESSAGE"); - if (MessageBox.Show(fileName + "\n\n" + mes, Form1StringResources.Get("CHANGED_FILE"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - WorkbenchServiceFactory.FileService.ReloadFile(fileName); - } - else - { - WorkbenchServiceFactory.FileService.SetFileAsChanged(fileName); - } + WorkbenchServiceFactory.Workbench.MainForm.BeginInvoke((Action)showChangedFileMessage); + } } catch (Exception ex) diff --git a/VisualPascalABCNETLinux/ReplaceForm.cs b/VisualPascalABCNETLinux/ReplaceForm.cs index 2925658c2..8b7dcfabc 100644 --- a/VisualPascalABCNETLinux/ReplaceForm.cs +++ b/VisualPascalABCNETLinux/ReplaceForm.cs @@ -103,7 +103,7 @@ namespace VisualPascalABC return findSuccess; } if (cbSearchUp.Checked) - Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, 0, startOffset); + Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, 0, Math.Max(startOffset, 0)); else Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, startOffset);