MaskEdit property editor: fix issue #40696.

- load and save which sample file was loaded
- add ability to unload a sample file
This commit is contained in:
Bart 2024-01-22 18:59:19 +01:00
parent 9776c68b28
commit c819e0ed2a
27 changed files with 361 additions and 20 deletions

View File

@ -328,6 +328,10 @@
<AddToUsesPkgSection Value="False"/>
<UnitName Value="PagesPropEditDlg"/>
</Item>
<Item>
<Filename Value="propeditconfig.pp"/>
<UnitName Value="PropEditConfig"/>
</Item>
</Files>
<LazDoc Paths="docs"/>
<i18n>

View File

@ -21,7 +21,7 @@ uses
PropEdits, PropEditUtils, SrcEditorIntf, StatusBarPropEdit,
StringsPropEditDlg, TextTools, ToolBarIntf, TreeViewPropEdit, UnitResources,
bufdatasetdsgn, selectdatasetdlg, SelEdits, IdeIntfStrConsts,
LazarusPackageIntf;
PropEditConfig, LazarusPackageIntf;
implementation

View File

@ -1330,6 +1330,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Desconegut"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr ""

View File

@ -1294,6 +1294,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Neznámý"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Nevybrat nic"

View File

@ -1292,6 +1292,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Unbekannt"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "Alles abwählen"

View File

@ -1295,6 +1295,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Desconocido"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "Deseleccionar todo"

View File

@ -1286,6 +1286,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Tuntematon"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Poista valinta kaikista"

View File

@ -1290,6 +1290,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Inconnu"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Tout désélectionner"

View File

@ -1336,6 +1336,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "לא ידוע "
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "בטל את כל הבחירות"

View File

@ -1293,6 +1293,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Ismeretlen"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "Kijelölések megszüntetése"

View File

@ -1334,6 +1334,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Tidak dikenal"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr ""

View File

@ -1296,6 +1296,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Sconosciuto"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Deseleziona tutto"

View File

@ -1301,6 +1301,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "不明"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "すべての選択を解除(&U)"

View File

@ -1294,6 +1294,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Nežinoma"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Naikinti visą žymėjimą"

View File

@ -1321,6 +1321,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Onbekend"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr ""

View File

@ -1288,6 +1288,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Nieznany"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "Odznacz wszystko"

View File

@ -1280,6 +1280,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr ""
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr ""

View File

@ -1289,6 +1289,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Desconhecido"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Desmarcar tudo"

View File

@ -1289,6 +1289,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Неизвестный"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Снять выделение"

View File

@ -1303,6 +1303,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Neznámy"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Odznačiť všetko"

View File

@ -1289,6 +1289,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Bilinmeyen"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Tüm seçimleri kaldır"

View File

@ -1292,6 +1292,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "Невідомий"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "&Зняти вибір з всіх"

View File

@ -1290,6 +1290,14 @@ msgctxt "objinspstrconsts.oisunknown"
msgid "Unknown"
msgstr "未知"
#: objinspstrconsts.oisunload
msgid "Unload"
msgstr ""
#: objinspstrconsts.oisunloadhint
msgid "Unloads the current sample file"
msgstr ""
#: objinspstrconsts.oisunselectall
msgid "&Unselect all"
msgstr "不选择所有(&U)"

View File

@ -84,7 +84,7 @@ object MaskEditorForm: TMaskEditorForm
Constraints.MinWidth = 300
ItemHeight = 0
Style = lbOwnerDrawFixed
TabOrder = 6
TabOrder = 7
OnClick = SampleMasksListBoxClick
OnDrawItem = SampleMasksListBoxDrawItem
end
@ -199,7 +199,7 @@ object MaskEditorForm: TMaskEditorForm
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 7
TabOrder = 8
ShowButtons = [pbOK, pbCancel, pbHelp]
end
object EnableSetsCheckBox: TCheckBox
@ -219,6 +219,21 @@ object MaskEditorForm: TMaskEditorForm
TabOrder = 3
OnClick = EnableSetsCheckBoxClick
end
object UnloadSampleMasksButton: TButton
AnchorSideLeft.Control = LoadSampleMasksButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = LoadSampleMasksButton
Left = 87
Height = 25
Top = 222
Width = 75
BorderSpacing.Left = 6
Caption = 'Unload'
ParentShowHint = False
ShowHint = True
TabOrder = 6
OnClick = UnloadSampleMasksButtonClick
end
object OpenDialog1: TOpenDialog
Title = 'Open mask file (*.dem)'
DefaultExt = '.dem'

View File

@ -24,7 +24,7 @@ uses
// LazUtils
LazUTF8, LazFileUtils,
// IdeIntf
LazIDEIntf, PropEdits, ComponentEditors, ObjInspStrConsts, IDEWindowIntf;
LazIDEIntf, PropEdits, ComponentEditors, ObjInspStrConsts, IDEWindowIntf, PropEditConfig;
type
@ -41,6 +41,7 @@ type
ButtonPanel1: TButtonPanel;
EnableSetsCheckBox: TCheckBox;
LoadSampleMasksButton: TButton;
UnloadSampleMasksButton: TButton;
SaveLiteralCheckBox: TCheckBox;
InputMaskEdit: TEdit;
CharactersForBlanksEdit: TEdit;
@ -55,6 +56,7 @@ type
procedure EnableSetsCheckBoxClick(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure LoadSampleMasksButtonClick(Sender: TObject);
procedure UnloadSampleMasksButtonClick(Sender: TObject);
procedure SampleMasksListBoxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; {%H-}State: TOwnerDrawState);
procedure SaveLiteralCheckBoxClick(Sender: TObject);
@ -65,13 +67,13 @@ type
private
FEnableSets: Boolean;
ParsedSamples: TParsedSamples;
FSampleEditMaskFilename: String;
function ConstructEditmask: String;
function GetEditMask: string;
function MaskDoFormatText(const EditMask: string; const Value: string; EnableSets: Boolean): String;
function ParseMaskLineDelphi(Line: String; EnableSets: Boolean; out aCaption, aExample, aFormattedExample, aMask: String): Boolean;
function ParseMaskLineLazarus(Line: String; EnableSets: Boolean; out aCaption, aExample, aFormattedExample, aMask: String): Boolean;
procedure LoadAndCleanSampleFile(Fn: String; EnableSets: Boolean; List: TStrings; out AParsedSamples: TParsedSamples); //out list of record?
procedure LoadDEMFile(AFileName: string);
procedure ReConstructEditmask;
procedure SetEditMask(AValue: string);
procedure SetEnableSets(AValue: Boolean);
@ -102,6 +104,8 @@ type
function MaskEdit: TCustomMaskEditAccess; virtual;
end;
implementation
{$R *.lfm}
@ -110,11 +114,11 @@ implementation
{ TMaskEditorForm }
procedure TMaskEditorForm.MaskEditorFormCreate(Sender: TObject);
var
aDemFile: string;
begin
Caption := oisInputMaskEditor;
LoadSampleMasksButton.Caption := oisMasks;
UnloadSampleMasksButton.Caption := oisUnload;
UnloadSampleMasksButton.Hint := oisUnloadHint; // alternatively have a longer caption?
SaveLiteralCheckBox.Caption := oisSaveLiteralCharacters;
InputMaskLabel.Caption := oisInputMask;
SampleMasksLabel.Caption := oisSampleMasks;
@ -125,21 +129,30 @@ begin
OpenDialog1.Filter := oisMaskSampleFilter;
OpenDialog1.Title := oisSelectInputMaskSample;
if LazarusIDE<>nil then
aDemFile:=LazarusIDE.GetPrimaryConfigPath
else
aDemFile:=ExtractFileDir(ParamStrUTF8(0));
aDemFile:=CleanAndExpandDirectory(aDemFile)+'maskeditmasks.txt';
if FileExistsUTF8(aDemFile) then
LoadDEMFile(aDemFile);
if not Assigned(PropEditConfigs) then
PropEditConfigs := TPropEditConfigs.Create;
PropEditConfigs.Load;
FSampleEditMaskFilename := PropEditConfigs.SampleEditMaskFilename;
FSampleEditMaskFilename := CleanAndExpandFilename(FSampleEditMaskFilename);
if (FSampleEditMaskFilename <> '') and FileExistsUTF8(FSampleEditMaskFilename) then
LoadAndCleanSampleFile(FSampleEditMaskFilename, FEnableSets, SampleMasksListBox.Items, ParsedSamples);
IDEDialogLayoutList.ApplyLayout(Self);
end;
procedure TMaskEditorForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
PropEditConfigs.SampleEditMaskFilename := FSampleEditMaskFilename;
PropEditConfigs.Save;
IDEDialogLayoutList.SaveLayout(Self);
end;
procedure TMaskEditorForm.UnloadSampleMasksButtonClick(Sender: TObject);
begin
SampleMasksListBox.Clear;
ParsedSamples := nil;
FSampleEditMaskFilename := '';
end;
procedure TMaskEditorForm.EnableSetsCheckBoxClick(Sender: TObject);
begin
SetEnableSets(EnableSetsCheckBox.Checked);
@ -147,9 +160,9 @@ end;
procedure TMaskEditorForm.LoadSampleMasksButtonClick(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFileDir(ParamStrUTF8(0));
OpenDialog1.InitialDir:=ExtractFileDir(FSampleEditMaskFilename);
if OpenDialog1.Execute then
LoadDEMFile(OpenDialog1.FileName);
LoadAndCleanSampleFile(OpenDialog1.Filename, FEnableSets, SampleMasksListBox.Items, ParsedSamples);
end;
procedure TMaskEditorForm.SampleMasksListBoxDrawItem(Control: TWinControl;
@ -374,6 +387,7 @@ var
SL: TStringList;
ParseFunc: TParseFunc;
begin
FSampleEditMaskFilename := '';
AParsedSamples := nil;
if (CompareText(ExtractFileExt(Fn),'.dem') = 0) then
ParseFunc := @ParseMaskLineDelphi
@ -403,11 +417,13 @@ begin
end;
end;
SetLength(AParsedSamples, Index);
FSampleEditMaskFilename := Fn;
except
on ESTreamError do
begin
List.Clear;
AParsedSamples := nil;
FSampleEditMaskFilename := '';
MessageDlg(Format(oisErrorReadingSampleFile,[Fn]), mtError, [mbOk], 0);
end;
end;
@ -417,10 +433,6 @@ begin
end;
end;
procedure TMaskEditorForm.LoadDEMFile(AFileName: string);
begin
LoadAndCleanSampleFile(AFilename, FEnableSets, SampleMasksListBox.Items, ParsedSamples);
end;
procedure TMaskEditorForm.SetEditMask(AValue: string);

View File

@ -257,6 +257,8 @@ resourcestring
// Mask Editor
sccsMaskEditor = 'Edit Mask Editor ...';
oisMasks = 'Masks ...';
oisUnload = 'Unload';
oisUnloadHint = 'Unloads the current sample file';
oisInputMaskEditor = 'Input Mask Editor';
oisSaveLiteralCharacters = 'Save Literal Characters';
oisInputMask = 'Input Mask:';

View File

@ -0,0 +1,140 @@
{
/***************************************************************************
propeditconfig.pp
-----------------
***************************************************************************/
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
Author: Bart Broersma
Abstract:
Miscellaneous config settings for property editors.
Currently just for MaskEdit property editor.
}
unit PropEditConfig;
{$mode objfpc}{$H+}
interface
uses
// RTL + LCL
Classes, SysUtils,
// LazUtils
LazFileUtils, LazLoggerBase, LazUTF8, Laz2_XMLCfg,
// IdeIntf
LazIDEIntf;
const
DefaultFilename = 'propeditconfig.xml';
PropEditConfigVersion = 0;
pSampleMaskEditFile = 'MaskEdit/SampleEditMaskFile';
type
{ TPropEditConfigs }
TPropEditConfigs = class
private
FFilename: String;
FSampleEditMaskFilename: String;
protected
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
public
constructor Create;
procedure Load;
procedure Save;
property Filename: String read FFilename;
property SampleEditMaskFilename: string read FSampleEditMaskFilename write FSampleEditMaskFilename;
end;
var
PropEditConfigs: TPropEditConfigs = nil; // do NOT free yourself, it'll be auto-destroyed at finalization
implementation
{ TPropEditConfigs }
procedure TPropEditConfigs.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
FSampleEditMaskFilename := XMLConfig.GetValue(Path + pSampleMaskEditFile,'');
end;
procedure TPropEditConfigs.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
XMLConfig.SetValue(Path + pSampleMaskEditFile,FSampleEditMaskFilename);
end;
constructor TPropEditConfigs.Create;
begin
if Assigned(LazarusIDE) then
FFilename := AppendPathDelim(LazarusIDE.GetPrimaryConfigPath) + DefaultFilename;
//if IDE does not exist, FFilename will be empty string, in effect making Load and Save silently fail
end;
procedure TPropEditConfigs.Load;
var
XMLConfig: TXMLConfig;
begin
try
XMLConfig := TXMLConfig.Create(FFileName);
LoadFromXMLConfig(XMLConfig,'PropEditConfig/');
XMLConfig.Free;
except
on E: Exception do
begin
DebugLn('[TPropEditConfigs.Load] error reading "',FFilename,'" ',E.Message);
end;
end;
end;
procedure TPropEditConfigs.Save;
var
XMLConfig: TXMLConfig;
begin
try
InvalidateFileStateCache;
XMLConfig:=TXMLConfig.CreateClean(FFileName);
XMLConfig.SetDeleteValue('PropEditConfig/PropEditConfigVersion/',PropEditConfigVersion,0);
SaveToXMLConfig(XMLConfig,'PropEditConfig/');
XMLConfig.Flush;
XMLConfig.Free;
except
on E: Exception do
begin
DebugLn('[TInputHistories.Save] error writing "',FFilename,'" ',E.Message);
end;
end;
end;
finalization
if Assigned(PropEditConfigs) then
FreeandNil(PropEditConfigs);
end.