diff --git a/Projects/SAMufasaGUI/colourhistory.lrs b/Projects/SAMufasaGUI/colourhistory.lrs index 4c419fb..f407234 100644 --- a/Projects/SAMufasaGUI/colourhistory.lrs +++ b/Projects/SAMufasaGUI/colourhistory.lrs @@ -1,3 +1,5 @@ +{ This is an automatically generated lazarus resource file } + LazarusResources.Add('TColourHistoryForm','FORMDATA',[ 'TPF0'#18'TColourHistoryForm'#17'ColourHistoryForm'#4'Left'#3'v'#1#6'Height'#3 +#4#1#3'Top'#3'O'#1#5'Width'#3#243#1#13'ActiveControl'#7#13'SelectionName'#7 @@ -40,4 +42,4 @@ LazarusResources.Add('TColourHistoryForm','FORMDATA',[ +'HAboutClick'#0#0#0#0#11'TSaveDialog'#12'CHSaveDialog'#10'DefaultExt'#6#4'.x' +'ml'#4'left'#3#136#1#3'top'#3#160#0#0#0#11'TOpenDialog'#12'CHOpenDialog'#10 +'DefaultExt'#6#4'.xml'#4'left'#3#200#1#3'top'#3#160#0#0#0#0 -]); +]); \ No newline at end of file diff --git a/Projects/SAMufasaGUI/colourhistory.pas b/Projects/SAMufasaGUI/colourhistory.pas index 89291bf..9fd49c9 100644 --- a/Projects/SAMufasaGUI/colourhistory.pas +++ b/Projects/SAMufasaGUI/colourhistory.pas @@ -138,7 +138,8 @@ var begin bmp:=TBitmap.Create; bmp.SetSize(16,16); - bmp.Canvas.Brush.Color:=TColourPickerObject(n.Data).Colour; + if(Assigned(n.Data)) then + bmp.Canvas.Brush.Color:=TColourPickerObject(n.Data).Colour; bmp.Canvas.Rectangle(0,0,16,16); n.ImageIndex:=CHImages.Add(bmp, nil); @@ -172,7 +173,13 @@ begin If Assigned(N.Data) then TColourPickerObject(N.Data).Free; WriteLn('Deleting ImageIndex: ' + IntToStr(n.ImageIndex) + '; Text: ' + N.Text); - Img.Delete(n.ImageIndex); + + // yeah.... + try + if n.ImageIndex <> -1 Then + Img.Delete(n.ImageIndex); + except end; + WalkDeleteTree(n, img); n := n.GetNextSibling; end; @@ -192,7 +199,8 @@ begin WalkDeleteTree(ColourTree.Selected, CHImages); WriteLn('Deleting ImageIndex: ' + IntToStr(ColourTree.Selected.ImageIndex) + '; Text: ' + ColourTree.Selected.Text); - CHImages.Delete(ColourTree.Selected.ImageIndex); + if ColourTree.Selected.ImageIndex <> -1 then + CHImages.Delete(ColourTree.Selected.ImageIndex); ColourTree.Selected.Delete; TreeChanged := True; diff --git a/Projects/SAMufasaGUI/project1.lpi b/Projects/SAMufasaGUI/project1.lpi index 643fbdb..f8d471a 100644 --- a/Projects/SAMufasaGUI/project1.lpi +++ b/Projects/SAMufasaGUI/project1.lpi @@ -10,7 +10,7 @@ <UseXPManifest Value="True"/> - <ActiveEditorIndexAtStart Value="6"/> + <ActiveEditorIndexAtStart Value="9"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -36,16 +36,14 @@ <PackageName Value="LCL"/> </Item2> </RequiredPackages> - <Units Count="294"> + <Units Count="297"> <Unit0> <Filename Value="project1.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="project1"/> <CursorPos X="1" Y="49"/> - <TopLine Value="24"/> - <EditorIndex Value="7"/> + <TopLine Value="12"/> <UsageCount Value="205"/> - <Loaded Value="True"/> </Unit0> <Unit1> <Filename Value="unit1.pas"/> @@ -139,8 +137,8 @@ <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="TestUnit"/> - <CursorPos X="68" Y="425"/> - <TopLine Value="411"/> + <CursorPos X="55" Y="41"/> + <TopLine Value="23"/> <EditorIndex Value="0"/> <UsageCount Value="202"/> <Loaded Value="True"/> @@ -206,7 +204,7 @@ <UnitName Value="MufasaTypes"/> <CursorPos X="58" Y="108"/> <TopLine Value="92"/> - <EditorIndex Value="9"/> + <EditorIndex Value="11"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit22> @@ -229,9 +227,11 @@ <Filename Value="../../Units/MMLCore/window.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="Window"/> - <CursorPos X="49" Y="297"/> - <TopLine Value="287"/> + <CursorPos X="39" Y="52"/> + <TopLine Value="34"/> + <EditorIndex Value="6"/> <UsageCount Value="201"/> + <Loaded Value="True"/> </Unit25> <Unit26> <Filename Value="../../../cogat/Units/CogatUnits/comptypes.pas"/> @@ -260,7 +260,7 @@ <UnitName Value="finder"/> <CursorPos X="1" Y="1832"/> <TopLine Value="1819"/> - <EditorIndex Value="2"/> + <EditorIndex Value="3"/> <UsageCount Value="201"/> <Loaded Value="True"/> </Unit29> @@ -282,8 +282,8 @@ <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="mmlpsthread"/> - <CursorPos X="25" Y="451"/> - <TopLine Value="434"/> + <CursorPos X="52" Y="310"/> + <TopLine Value="291"/> <EditorIndex Value="4"/> <UsageCount Value="202"/> <Loaded Value="True"/> @@ -346,8 +346,8 @@ <Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/> <CursorPos X="104" Y="36"/> <TopLine Value="22"/> - <EditorIndex Value="1"/> - <UsageCount Value="97"/> + <EditorIndex Value="2"/> + <UsageCount Value="98"/> <Loaded Value="True"/> </Unit41> <Unit42> @@ -563,11 +563,9 @@ <Unit74> <Filename Value="../../Units/PascalScript/uPSRuntime.pas"/> <UnitName Value="uPSRuntime"/> - <CursorPos X="74" Y="1853"/> - <TopLine Value="1840"/> - <EditorIndex Value="3"/> + <CursorPos X="89" Y="10"/> + <TopLine Value="1"/> <UsageCount Value="10"/> - <Loaded Value="True"/> </Unit74> <Unit75> <Filename Value="../../Units/MMLAddon/plugins.pas"/> @@ -646,7 +644,7 @@ <Filename Value="../../Units/MMLCore/dtm.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="dtm"/> - <CursorPos X="64" Y="234"/> + <CursorPos X="114" Y="245"/> <TopLine Value="226"/> <EditorIndex Value="8"/> <UsageCount Value="200"/> @@ -663,9 +661,11 @@ <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="colourpicker"/> - <CursorPos X="76" Y="115"/> - <TopLine Value="101"/> + <CursorPos X="22" Y="228"/> + <TopLine Value="1"/> + <EditorIndex Value="1"/> <UsageCount Value="201"/> + <Loaded Value="True"/> </Unit88> <Unit89> <Filename Value="../../../cogat/Units/CogatUnits/compdragger.pas"/> @@ -722,9 +722,9 @@ <Filename Value="../../Units/MMLCore/dtmutil.pas"/> <IsPartOfProject Value="True"/> <UnitName Value="dtmutil"/> - <CursorPos X="74" Y="154"/> + <CursorPos X="63" Y="154"/> <TopLine Value="139"/> - <EditorIndex Value="6"/> + <EditorIndex Value="7"/> <UsageCount Value="206"/> <Loaded Value="True"/> </Unit96> @@ -871,8 +871,8 @@ </Unit117> <Unit118> <Filename Value="../../Units/MMLAddon/PSInc/Wrappers/window.inc"/> - <CursorPos X="35" Y="29"/> - <TopLine Value="18"/> + <CursorPos X="52" Y="52"/> + <TopLine Value="22"/> <UsageCount Value="12"/> </Unit118> <Unit119> @@ -1437,9 +1437,11 @@ <ComponentName Value="ColourHistoryForm"/> <ResourceBaseClass Value="Form"/> <UnitName Value="colourhistory"/> - <CursorPos X="1" Y="129"/> - <TopLine Value="114"/> + <CursorPos X="16" Y="177"/> + <TopLine Value="159"/> + <EditorIndex Value="5"/> <UsageCount Value="200"/> + <Loaded Value="True"/> </Unit198> <Unit199> <Filename Value="../../../Documents/lazarus/lcl/comctrls.pp"/> @@ -1703,7 +1705,7 @@ <UnitName Value="internets"/> <CursorPos X="5" Y="14"/> <TopLine Value="1"/> - <UsageCount Value="195"/> + <UsageCount Value="196"/> </Unit237> <Unit238> <Filename Value="debugimageform.pas"/> @@ -1712,7 +1714,7 @@ <UnitName Value="debugimageform"/> <CursorPos X="20" Y="1"/> <TopLine Value="1"/> - <UsageCount Value="182"/> + <UsageCount Value="183"/> </Unit238> <Unit239> <Filename Value="debugimage.pas"/> @@ -1722,7 +1724,7 @@ <UnitName Value="debugimage"/> <CursorPos X="66" Y="17"/> <TopLine Value="1"/> - <UsageCount Value="181"/> + <UsageCount Value="182"/> </Unit239> <Unit240> <Filename Value="debugimage.lrs"/> @@ -1844,7 +1846,7 @@ <UnitName Value="framefunctionlist"/> <CursorPos X="117" Y="5"/> <TopLine Value="1"/> - <UsageCount Value="102"/> + <UsageCount Value="103"/> </Unit257> <Unit258> <Filename Value="../../../usr/local/share/lazarus/lcl/comctrls.pp"/> @@ -1899,7 +1901,7 @@ <UnitName Value="simpleanalyzer"/> <CursorPos X="52" Y="104"/> <TopLine Value="193"/> - <UsageCount Value="89"/> + <UsageCount Value="90"/> </Unit265> <Unit266> <Filename Value="../../Units/Misc/mPasLex.pas"/> @@ -1959,9 +1961,7 @@ <Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/> <CursorPos X="90" Y="34"/> <TopLine Value="18"/> - <EditorIndex Value="5"/> <UsageCount Value="20"/> - <Loaded Value="True"/> </Unit274> <Unit275> <Filename Value="../../Units/Synapse/synautil.pas"/> @@ -1976,7 +1976,7 @@ <UnitName Value="updater"/> <CursorPos X="10" Y="201"/> <TopLine Value="190"/> - <UsageCount Value="62"/> + <UsageCount Value="63"/> </Unit276> <Unit277> <Filename Value="updateform.pas"/> @@ -1986,7 +1986,7 @@ <UnitName Value="updateform"/> <CursorPos X="77" Y="74"/> <TopLine Value="47"/> - <UsageCount Value="57"/> + <UsageCount Value="58"/> </Unit277> <Unit278> <Filename Value="../../../Documents/lazarus/lcl/fileutil.pas"/> @@ -2093,127 +2093,154 @@ <TopLine Value="130"/> <UsageCount Value="9"/> </Unit293> + <Unit294> + <Filename Value="../../../../Documents/lazarus/lcl/include/imglist.inc"/> + <CursorPos X="1" Y="312"/> + <TopLine Value="294"/> + <UsageCount Value="10"/> + </Unit294> + <Unit295> + <Filename Value="simbasettings.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="SettingsForm"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="simbasettings"/> + <CursorPos X="40" Y="67"/> + <TopLine Value="31"/> + <EditorIndex Value="9"/> + <UsageCount Value="21"/> + <Loaded Value="True"/> + </Unit295> + <Unit296> + <Filename Value="../../Units/MMLAddon/settings.pas"/> + <UnitName Value="settings"/> + <CursorPos X="105" Y="7"/> + <TopLine Value="1"/> + <EditorIndex Value="10"/> + <UsageCount Value="10"/> + <Loaded Value="True"/> + </Unit296> </Units> <JumpHistory Count="30" HistoryIndex="29"> <Position1> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="184" Column="27" TopLine="168"/> + <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> + <Caret Line="451" Column="25" TopLine="434"/> </Position1> <Position2> <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="79" Column="17" TopLine="66"/> + <Caret Line="34" Column="20" TopLine="21"/> </Position2> <Position3> <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="91" Column="268" TopLine="76"/> + <Caret Line="127" Column="22" TopLine="108"/> </Position3> <Position4> - <Filename Value="../../Units/MMLCore/dtm.pas"/> - <Caret Line="187" Column="23" TopLine="180"/> + <Filename Value="../../Units/MMLCore/dtmutil.pas"/> + <Caret Line="36" Column="22" TopLine="22"/> </Position4> <Position5> - <Filename Value="../../Units/MMLCore/dtm.pas"/> - <Caret Line="198" Column="23" TopLine="185"/> + <Filename Value="../../Units/MMLCore/dtmutil.pas"/> + <Caret Line="87" Column="7" TopLine="74"/> </Position5> <Position6> - <Filename Value="../../Units/MMLCore/finder.pas"/> - <Caret Line="1908" Column="67" TopLine="1887"/> + <Filename Value="../../Units/MMLCore/dtmutil.pas"/> + <Caret Line="87" Column="7" TopLine="74"/> </Position6> <Position7> - <Filename Value="../../Units/MMLCore/finder.pas"/> - <Caret Line="1845" Column="36" TopLine="1832"/> + <Filename Value="../../Units/MMLCore/dtmutil.pas"/> + <Caret Line="123" Column="7" TopLine="100"/> </Position7> <Position8> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="89" Column="1" TopLine="79"/> + <Filename Value="testunit.pas"/> + <Caret Line="425" Column="68" TopLine="411"/> </Position8> <Position9> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="79" Column="21" TopLine="66"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="115" Column="76" TopLine="101"/> </Position9> <Position10> - <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="219" Column="24" TopLine="206"/> + <Filename Value="../../Units/MMLAddon/colourpicker.pas"/> + <Caret Line="102" Column="18" TopLine="84"/> </Position10> <Position11> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="213" Column="10" TopLine="200"/> + <Caret Line="451" Column="25" TopLine="434"/> </Position11> <Position12> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="227" Column="22" TopLine="206"/> + <Caret Line="82" Column="47" TopLine="63"/> </Position12> <Position13> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="268" Column="17" TopLine="257"/> + <Caret Line="316" Column="1" TopLine="299"/> </Position13> <Position14> - <Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/> - <Caret Line="39" Column="134" TopLine="16"/> + <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> + <Caret Line="79" Column="51" TopLine="61"/> </Position14> <Position15> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="227" Column="22" TopLine="209"/> + <Caret Line="68" Column="52" TopLine="50"/> </Position15> <Position16> - <Filename Value="../../Units/MMLCore/dtm.pas"/> - <Caret Line="41" Column="28" TopLine="28"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="297" Column="49" TopLine="287"/> </Position16> <Position17> - <Filename Value="project1.lpr"/> - <Caret Line="35" Column="85" TopLine="1"/> + <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> + <Caret Line="219" Column="24" TopLine="215"/> </Position17> <Position18> - <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="217" Column="22" TopLine="209"/> + <Filename Value="../../Units/MMLCore/window.pas"/> + <Caret Line="52" Column="39" TopLine="33"/> </Position18> <Position19> <Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/> - <Caret Line="451" Column="25" TopLine="434"/> + <Caret Line="310" Column="52" TopLine="291"/> </Position19> <Position20> - <Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/> - <Caret Line="1" Column="1" TopLine="1"/> + <Filename Value="colourhistory.pas"/> + <Caret Line="142" Column="3" TopLine="123"/> </Position20> <Position21> - <Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/> - <Caret Line="31" Column="20" TopLine="18"/> + <Filename Value="colourhistory.pas"/> + <Caret Line="141" Column="22" TopLine="123"/> </Position21> <Position22> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="34" Column="20" TopLine="21"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="20" Column="33" TopLine="1"/> </Position22> <Position23> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="127" Column="22" TopLine="108"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="43" Column="8" TopLine="7"/> </Position23> <Position24> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="36" Column="22" TopLine="22"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="42" Column="36" TopLine="13"/> </Position24> <Position25> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="87" Column="7" TopLine="74"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="3" Column="16" TopLine="1"/> </Position25> <Position26> - <Filename Value="../../Units/PascalScript/uPSRuntime.pas"/> - <Caret Line="1853" Column="1" TopLine="1840"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="4" Column="27" TopLine="1"/> </Position26> <Position27> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="87" Column="7" TopLine="74"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="27" Column="119" TopLine="1"/> </Position27> <Position28> - <Filename Value="../../Units/MMLCore/dtmutil.pas"/> - <Caret Line="123" Column="7" TopLine="100"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="3" Column="19" TopLine="1"/> </Position28> <Position29> - <Filename Value="project1.lpr"/> - <Caret Line="30" Column="94" TopLine="23"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="9" Column="18" TopLine="1"/> </Position29> <Position30> - <Filename Value="project1.lpr"/> - <Caret Line="49" Column="1" TopLine="24"/> + <Filename Value="simbasettings.pas"/> + <Caret Line="41" Column="3" TopLine="9"/> </Position30> </JumpHistory> </ProjectOptions> diff --git a/Projects/SAMufasaGUI/project1.lpr b/Projects/SAMufasaGUI/project1.lpr index 212d01d..d035027 100644 --- a/Projects/SAMufasaGUI/project1.lpr +++ b/Projects/SAMufasaGUI/project1.lpr @@ -32,7 +32,7 @@ uses Interfaces, // this includes the LCL widgetset LResources , Forms, testunit, colourhistory, About, internets, debugimage, - framefunctionlist, simpleanalyzer, updater, updateform; + framefunctionlist, simpleanalyzer, updater, updateform, simbasettings; {$IFDEF WINDOWS}{$R project1.rc}{$ENDIF} begin @@ -45,6 +45,7 @@ begin Application.CreateForm(TAboutForm, AboutForm); Application.CreateForm(TDebugImgForm, DebugImgForm); Application.CreateForm(TSimbaUpdateForm, SimbaUpdateForm); + Application.CreateForm(TSettingsForm, SettingsForm); Application.Run; end. diff --git a/Projects/SAMufasaGUI/simbasettings.lfm b/Projects/SAMufasaGUI/simbasettings.lfm new file mode 100644 index 0000000..e32a8c7 --- /dev/null +++ b/Projects/SAMufasaGUI/simbasettings.lfm @@ -0,0 +1,21 @@ +object SettingsForm: TSettingsForm + Left = 747 + Height = 438 + Top = 283 + Width = 333 + Caption = 'Simba Settings' + ClientHeight = 438 + ClientWidth = 333 + OnCreate = FormCreate + OnDestroy = FormDestroy + LCLVersion = '0.9.29' + object SettingsTreeView: TTreeView + Left = 16 + Height = 401 + Top = 16 + Width = 297 + DefaultItemHeight = 19 + ScrollBars = ssAutoBoth + TabOrder = 0 + end +end diff --git a/Projects/SAMufasaGUI/simbasettings.lrs b/Projects/SAMufasaGUI/simbasettings.lrs new file mode 100644 index 0000000..ad44462 --- /dev/null +++ b/Projects/SAMufasaGUI/simbasettings.lrs @@ -0,0 +1,10 @@ +{ This is an automatically generated lazarus resource file } + +LazarusResources.Add('TSettingsForm','FORMDATA',[ + 'TPF0'#13'TSettingsForm'#12'SettingsForm'#4'Left'#3#235#2#6'Height'#3#182#1#3 + +'Top'#3#27#1#5'Width'#3'M'#1#7'Caption'#6#14'Simba Settings'#12'ClientHeight' + +#3#182#1#11'ClientWidth'#3'M'#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7 + +#11'FormDestroy'#10'LCLVersion'#6#6'0.9.29'#0#9'TTreeView'#16'SettingsTreeVi' + +'ew'#4'Left'#2#16#6'Height'#3#145#1#3'Top'#2#16#5'Width'#3')'#1#17'DefaultIt' + +'emHeight'#2#19#10'ScrollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#0#0#0#0 +]); diff --git a/Projects/SAMufasaGUI/simbasettings.pas b/Projects/SAMufasaGUI/simbasettings.pas new file mode 100644 index 0000000..ca3d3ad --- /dev/null +++ b/Projects/SAMufasaGUI/simbasettings.pas @@ -0,0 +1,74 @@ +unit simbasettings; + +{$mode objfpc} {$M+} + +interface + +uses + Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + ComCtrls, settings; + +type + + { TSettingsForm } + + TSettingsForm = class(TForm) + SettingsTreeView: TTreeView; + Settings: TMMLSettings; + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + { private declarations } + public + procedure SaveCurrent; + procedure Reload; + { public declarations } + end; + +var + SettingsForm: TSettingsForm; + +implementation + +{ TSettingsForm } + +procedure TSettingsForm.FormCreate(Sender: TObject); + +begin + Settings := TMMLSettings.Create(SettingsTreeView.Items); + if not FileExists('settings.xml') then + begin + SettingsTreeView.Items.Clear; + Settings.SaveToXML('settings.xml'); + end; + + SettingsTreeView.Items.Clear; + Settings.LoadFromXML('settings.xml'); +end; + +procedure TSettingsForm.FormDestroy(Sender: TObject); +begin + Settings.Free; +end; + +procedure TSettingsForm.SaveCurrent; +begin + Settings.SaveToXML('settings.xml'); +end; + +procedure TSettingsForm.Reload; +begin + if not FileExists('settings.xml') then + begin + SettingsTreeView.Items.Clear; + Settings.SaveToXML('settings.xml'); + end; + + SettingsTreeView.Items.Clear; + Settings.LoadFromXML('settings.xml'); +end; + +initialization + {$I simbasettings.lrs} + +end. + diff --git a/Projects/settings/settings.pas b/Projects/settings/settings.pas index 7ea14eb..23a8019 100644 --- a/Projects/settings/settings.pas +++ b/Projects/settings/settings.pas @@ -32,7 +32,6 @@ type Nodes: TTreeNodes; function KeyNameToKeys(KeyName: String): TStringArray; function WalkToNode(KeyName: String): TTreeNode; - function GetNodePath(Node: TTreeNode): String; procedure InternalLoadFromXML(XMLDoc: TXMLDocument); procedure WriteXMLData(n: TTreeNode; @@ -42,6 +41,7 @@ type var C: Integer); public + function GetNodePath(Node: TTreeNode): String; function ListKeys(KeyName: String): TStringArray; function KeyExists(KeyName: String): Boolean; function IsKey(KeyName: String): Boolean; diff --git a/Units/MMLAddon/colourpicker.pas b/Units/MMLAddon/colourpicker.pas index cf2642d..f32b9b8 100644 --- a/Units/MMLAddon/colourpicker.pas +++ b/Units/MMLAddon/colourpicker.pas @@ -100,7 +100,6 @@ var procedure TMColorPicker.Pick(Out C, X, Y: Integer); var w, h: integer; - box : TBox; SS : TShiftState; p : TPoint; @@ -227,7 +226,6 @@ procedure TMColorPicker.ImageMainMouseMove(Sender: TObject; Shift: TShiftState; Y: Integer); var TempPoint : TPoint; - Data : TRetData; R : TRect; px, py : Integer; MouseX, MouseY: Integer; diff --git a/Units/MMLAddon/mmlpsthread.pas b/Units/MMLAddon/mmlpsthread.pas index 337c167..76c4c9e 100644 --- a/Units/MMLAddon/mmlpsthread.pas +++ b/Units/MMLAddon/mmlpsthread.pas @@ -313,8 +313,7 @@ begin end; procedure SIRegister_Mufasa(cl: TPSPascalCompiler); -var - Ptr : PtrUInt; + begin; with cl.AddClassN(cl.FindClass('TObject'),'TMufasaBitmap') do begin; diff --git a/Units/MMLAddon/settings.pas b/Units/MMLAddon/settings.pas new file mode 100644 index 0000000..f4f0d18 --- /dev/null +++ b/Units/MMLAddon/settings.pas @@ -0,0 +1,489 @@ +unit settings; + +{$mode objfpc}{$M+} + +interface + +uses + Classes, SysUtils, ComCtrls, xmlread, xmlwrite, DOM; + + + +type + // remove later + TStringArray = Array Of String; + + TSettingData = class(TObject) + public + Val: String; + + constructor Create; + destructor Destroy; override; + + end; + + TMMLSettings = class(TObject) + + public + constructor Create(aNodes: TTreeNodes); + destructor Destroy; override; + + private + Nodes: TTreeNodes; + function KeyNameToKeys(KeyName: String): TStringArray; + function WalkToNode(KeyName: String): TTreeNode; + + procedure InternalLoadFromXML(XMLDoc: TXMLDocument); + procedure WriteXMLData(n: TTreeNode; + XMLNode: TDOMNode; XMLDoc: TXMLDocument; + var XMLChild: TDOMNode; var C: Integer); + procedure WalkTree(Node: TTreeNode; XMLNode: TDOMNode; XMLDoc: TXMLDocument; + var C: Integer); + + public + function GetNodePath(Node: TTreeNode): String; + function ListKeys(KeyName: String): TStringArray; + function KeyExists(KeyName: String): Boolean; + function IsKey(KeyName: String): Boolean; + function IsDirectory(KeyName: String): Boolean; + procedure SetKeyValue(KeyName: String; KeyValue: String); + function CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean; + function GetKeyValue(KeyName: String): String; + function GetSetDefaultKeyValue(KeyName, defVal: String): String; + + public + procedure LoadFromXML(fileName: String); + procedure SaveToXML(fileName: String); + + end; + +implementation +uses + strutils; + +constructor TSettingData.Create; +begin + inherited; + Val := ''; +end; + +destructor TSettingData.Destroy; +begin + Val := ''; + inherited; +end; + + +constructor TMMLSettings.Create(aNodes: TTreeNodes); +begin + Self.Nodes := aNodes; +end; + +destructor TMMLSettings.Destroy; +begin + Nodes := nil; + + inherited; +end; + +procedure TMMLSettings.InternalLoadFromXML(XMLDoc: TXMLDocument); +var + iNode: TDOMNode; + + procedure ProcessNode(Node: TDOMNode; TreeNode: TTreeNode); + var + cNode: TDOMNode; + s: string; + d: TSettingData; + + begin + if Node = nil then Exit; // Stops if reached a leaf + + // Adds a node to the tree + if (Node.NodeType = 3) then + s := 'Data' + else + s := Node.NodeName; + + TreeNode := Nodes.AddChild(TreeNode, s); + if (Node.NodeType = 3) then + begin + d := TSettingData.Create; + D.Val := Node.NodeValue; + TreeNode.Data := D; + + TreeNode.Text := 'Value'; + end; + // Goes to the child node + cNode := Node.FirstChild; + + // Processes all child nodes + while cNode <> nil do + begin + ProcessNode(cNode, TreeNode); + cNode := cNode.NextSibling; + end; + end; + +begin + iNode := XMLDoc.DocumentElement; + while iNode <> nil do + begin + ProcessNode(iNode, nil); // Recursive + iNode := iNode.NextSibling; + end; +end; + +function TMMLSettings.KeyNameToKeys(KeyName: String): TStringArray; + // yay for SRL! + function srl_Explode(str, del: string): TStringArray; + var + i, l, dL: Integer; + begin + i := 0; + l := -1; + SetLength(Result, 0); + if (str = '') then + Exit; + dL := Length(del) - 1; + repeat + Inc(l); + SetLength(Result, l + 1); + i := Pos(del, str); + if i <= 0 then + Break; + Result[l] := Copy(str, 1, i - 1); + Delete(str, 1, i + dL); + until false; + Result[l] := Copy(str, 1, Length(str)); + end; +begin + Result := srl_Explode(KeyName, '/'); +end; + +function TMMLSettings.WalkToNode(KeyName: String): TTreeNode; +var + N: TTreeNode; + i: Integer; + S: TStringArray; +begin + Result := nil; + + if KeyName[length(KeyName)]='/' then setlength(KeyName,length(KeyName)-1); + S := KeyNameToKeys(KeyName); + + if not assigned(s) then + Exit(nil); + + N := Nodes.GetFirstNode; + i := 0; + + while N <> nil do + begin + if N.Text = s[i] then + begin + inc(i); + if i = length(s) then + break; + N := N.GetFirstChild; + end else + N := N.GetNextSibling; + end; + + Result := N; +end; + +function TMMLSettings.GetNodePath(Node: TTreeNode): String; +var + N: TTreeNode; + s: TStringArray; + i: Integer; +begin + if Node = nil then + Exit(''); + + N := Node; + setlength(s, 0); + while N <> nil do + begin + setlength(s,length(s) + 1); + s[high(s)] := N.Text; + N := N.Parent; + end; + + result := ''; + for i := high(s) downto 0 do + result := result + s[i] + '/'; +end; + +function TMMLSettings.ListKeys(KeyName: String): TStringArray; +var + N: TTreeNode; + i: Integer; + S: TStringArray; +begin + SetLength(Result, 0); + N := WalkToNode(KeyName); + if N <> nil then + N := N.GetFirstChild; + + while N <> nil do + begin + setlength(result,length(result)+1); + result[high(result)] := N.Text; + N := N.GetNextSibling; + end; +end; + +function TMMLSettings.KeyExists(KeyName: String): Boolean; + +begin + Result := WalkToNode(KeyName) <> nil; +end; + +function TMMLSettings.IsKey(KeyName: String): Boolean; +var + N: TTreeNode; + i: Integer; +begin + N := WalkToNode(KeyName); + if N = nil then + Exit(False); + + i := 0; + + N := N.GetNextSibling; + while N <> nil do + begin + if N.Text <> 'Value' then + inc(i); + N := N.GetNextSibling; + end; + + Exit(i = 0); +end; + +function TMMLSettings.IsDirectory(KeyName: String): Boolean; +var + N: TTreeNode; +begin + N := WalkToNode(KeyName); + if N <> nil then + Exit(N.HasChildren); + Exit(False); +end; + +function TMMLSettings.GetKeyValue(KeyName: String): String; +var + N: TTreeNode; +begin + if not KeyExists(KeyName) then + Exit(''); + N := WalkToNode(KeyName); + if N <> nil then + N := N.GetFirstChild; + while N <> nil do + begin + if N.Text = 'Value' then + if assigned(n.Data) then + Exit(TSettingData(n.Data).Val); + N := N.GetNextSibling; + end; + Exit(''); +end; + +function TMMLSettings.GetSetDefaultKeyValue(KeyName, defVal: String): String; +var + Res: String; +begin + if not IsKey(KeyName) then + begin + CreateKey(KeyName, True); + SetKeyValue(KeyName, defVal); + exit(defVal); + end; + Res := GetKeyValue(KeyName); + if Res = '' then + begin + SetKeyValue(KeyName, defVal); + exit(defVal); + end; + Exit(Res); +end; + +function TMMLSettings.CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean; +var + N, newN, nParent: TTreeNode; + Path: TStringArray; + NewPath: String; + i: Integer; + +begin + if KeyExists(KeyName) then + begin + Exit(False); + end; + NewPath := ''; + N := nil; + nParent := Nodes.GetFirstNode; + + Path := KeyNameToKeys(KeyName); + if length(path) < 2 then + begin + writeln('Path too short!'); + exit(false); + end; + + if path[0] <> nParent.Text then + begin + writeln('First key doesn''t match. First key should always match'); + exit(false); + end; + for i := 0 to length(Path) - 2 do + begin + if Path[i] = '' then + begin + writeln('Invalid Key Path / Name'); + exit(false); + end; + NewPath := NewPath + Path[i] + '/'; + N := WalkToNode(NewPath); + + if (N = nil) and (not CreatePath) then + begin + writeln('(N = nil) and (not CreatePath)'); + exit(false); + end; + + if (N = nil) and CreatePath then + begin + newN := TTreeNode.Create(Nodes); + newN.Text := Path[i]; + if (nParent = nil) then + begin + writeln('This shouldn''t happen...'); + newN.MoveTo(Nodes.GetFirstNode, naAddChild); + nParent := newN; + end + else + begin + newN.MoveTo(nParent, naAddChild); + nParent := newN; + end; + end; + + if N <> nil then + nParent := N; + end; + + if nParent = nil then + exit(false); + + newN := TTreeNode.Create(Nodes); + newN.Text := Path[High(Path)]; + newN.MoveTo(nParent, naAddChild); +end; + +procedure TMMLSettings.SetKeyValue(KeyName: String; KeyValue: String); +var + N, NN: TTreeNode; +begin + if not KeyExists(KeyName) then + Exit; + if not IsKey(KeyName) then + Exit; + + N := WalkToNode(KeyName); + + if not N.HasChildren then + begin + NN := TTreeNode.Create(Nodes); + NN.Text := 'Value'; + NN.MoveTo(N, naAddChild); + end; + + if n <> nil then + N := N.GetFirstChild; + while N <> nil do + begin + if N.Text = 'Value' then + begin + if Assigned(N.Data) then + TSettingData(N.Data).Free; + N.Data := TSettingData.Create; + TSettingData(N.Data).Val := KeyValue; + end; + N := N.GetNextSibling; + end; +end; + +procedure TMMLSettings.LoadFromXML(fileName: String); +var + Doc: TXMLDocument; +begin + ReadXMLFile(Doc, fileName); + InternalLoadFromXML(Doc); + Doc.Free; +end; + +procedure TMMLSettings.WriteXMLData(n: TTreeNode; + XMLNode: TDOMNode; XMLDoc: TXMLDocument; + var XMLChild: TDOMNode; var C: Integer); + +var + DDataNode, DataNode: TDOMNode; + +begin + if n.Text = 'Value' then + begin + XMLChild := XMLDoc.CreateTextNode(TSettingData(N.Data).Val); + end else + begin + XMLChild := XMLDoc.CreateElement(n.Text); + end; + Inc(C); + XMLNode.AppendChild(XMLChild); +end; + +procedure TMMLSettings.WalkTree(Node: TTreeNode; XMLNode: TDOMNode; XMLDoc: TXMLDocument; + var C: Integer); +var + N: TTreeNode; + XMLChild: TDOMNode; + +begin + N := Node.GetFirstChild; + + while assigned(n) do + begin + WriteXMLData(n, XMLNode, XMLDoc, XMLChild, C); + + WalkTree(n, XMLChild, XMLDoc, C); + n := n.GetNextSibling; + end; +end; + +procedure TMMLSettings.SaveToXML(fileName: String); +var + XMLDoc: TXMLDocument; + RootNode: TDOMNode; + C: Integer; +begin + XMLDoc := TXMLDocument.Create; + + RootNode := XMLDoc.CreateElement('Settings'); + XMLDoc.AppendChild(RootNode); + + RootNode := XMLDoc.DocumentElement; + + C := 0; + if Nodes.GetFirstNode <> nil then + WalkTree(Nodes.GetFirstNode, RootNode, XMLDoc, C); + + WriteXMLFile(XMLDoc, fileName); + + XMLDoc.Free; +end; + +end. +