From 7751c79f7f2240e528e90d1a9023635121218d8f Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 17 Jun 2014 23:48:18 +0100 Subject: textedit: SaveToFile() and LoadFromFile() now does OS Encoding calls. The AFileName parameter is of type TfpgString (thus UTF-8), and we need to ensure that it is the same encoding as the underlying file system before we can save or load files. --- examples/apps/ide/src/fpg_textedit.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/fpg_textedit.pas b/examples/apps/ide/src/fpg_textedit.pas index 013ad86b..3e88f3d1 100644 --- a/examples/apps/ide/src/fpg_textedit.pas +++ b/examples/apps/ide/src/fpg_textedit.pas @@ -2412,7 +2412,7 @@ begin BuffList[I] := SLine; end; end; - BuffList.SaveToFile(AFileName); + BuffList.SaveToFile(fpgToOSEncoding(AFileName)); finally BuffList.Free; end; @@ -2423,7 +2423,7 @@ begin if not fpgFileExists(AFileName) then Exit; //==> Clear; - FLines.LoadFromFile(AFileName); + FLines.LoadFromFile(fpgToOSEncoding(AFileName)); HandleResize(Width, Height); Invalidate; end; -- cgit v1.2.3-70-g09d2 From 8675daaef49b16116a6e49b869f0852d942f9845 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 17 Jun 2014 23:50:06 +0100 Subject: nanoedit: use the textedit's Save and Load file methods This then automatically handles cursor positions, scrollbars, invalidate etc. --- examples/apps/nanoedit/mainfrm.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/nanoedit/mainfrm.pas b/examples/apps/nanoedit/mainfrm.pas index 93f8f8a6..f652e179 100644 --- a/examples/apps/nanoedit/mainfrm.pas +++ b/examples/apps/nanoedit/mainfrm.pas @@ -80,7 +80,7 @@ begin try if dlg.RunOpenFile then begin - memEditor.Lines.LoadFromFile(dlg.FileName); + memEditor.LoadFromFile(dlg.FileName); FFileName := dlg.FileName; UpdateStatus(FFileName); end; @@ -99,7 +99,7 @@ begin dlg.FileName := FFilename; if dlg.RunSaveFile then begin - memEditor.Lines.SaveToFile(dlg.FileName); + memEditor.SaveToFile(dlg.FileName); UpdateStatus(Format('<%s> successfully saved.', [FFileName])); end; finally -- cgit v1.2.3-70-g09d2 From 664266e7d0b78bccc0b6ccd4467c9325e7533962 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sat, 9 Aug 2014 17:18:31 +0100 Subject: maximus: refactored some code, moving from main form to various classes Moved some functionality from the main form unit, into the unitlist.pas unit. --- examples/apps/ide/src/frm_main.pas | 26 +++++++++++++------------- examples/apps/ide/src/unitlist.pas | 26 ++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 15 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas index fe903c31..65985631 100644 --- a/examples/apps/ide/src/frm_main.pas +++ b/examples/apps/ide/src/frm_main.pas @@ -1,7 +1,7 @@ { fpGUI IDE - Maximus - Copyright (C) 2012 - 2013 Graeme Geldenhuys + Copyright (C) 2012 - 2014 Graeme Geldenhuys See the file COPYING.modifiedLGPL, included in this distribution, for details about redistributing fpGUI. @@ -541,18 +541,18 @@ var r: TfpgTreeNode; n: TfpgTreeNode; begin - u := TUnit.Create; - u.FileName := AUnitName; - u.Opened := True; - GProject.UnitList.Add(u); - // add reference to tabsheet - pcEditor.ActivePage.TagPointer := u; - s := fpgExtractRelativepath(GProject.ProjectDir, u.FileName); - r := GetUnitsNode; - n := r.AppendText(s); - // add reference to treenode - n.Data := u; - tvProject.Invalidate; + u := GProject.UnitList.AddFilename(AUnitName); + if Assigned(n) then + begin + // add reference to tabsheet + pcEditor.ActivePage.TagPointer := u; + s := u.GetRelativePath; + r := GetUnitsNode; + n := r.AppendText(s); + // add reference to treenode + n.Data := u; + tvProject.Invalidate; + end; end; procedure TMainForm.miProjectAddUnitToProject(Sender: TObject); diff --git a/examples/apps/ide/src/unitlist.pas b/examples/apps/ide/src/unitlist.pas index 827326e7..37e9a9cd 100644 --- a/examples/apps/ide/src/unitlist.pas +++ b/examples/apps/ide/src/unitlist.pas @@ -1,7 +1,7 @@ { fpGUI IDE - Maximus - Copyright (C) 2012 - 2013 Graeme Geldenhuys + Copyright (C) 2012 - 2014 Graeme Geldenhuys See the file COPYING.modifiedLGPL, included in this distribution, for details about redistributing fpGUI. @@ -31,6 +31,7 @@ type function GetUnitName: TfpgString; public constructor Create; + function GetRelativePath: TfpgString; property FileName: TfpgString read FFilename write FFilename; property UnitName: TfpgString read GetUnitName; property Opened: Boolean read FOpened write FOpened; @@ -48,6 +49,7 @@ type function Count: integer; function FindByName(const AUnitName: TfpgString): TUnit; function FileExists(const AFilename: TfpgString): Boolean; + function AddFileName(const AFilename: TfpgString): TUnit; procedure Add(NewUnit: TUnit); procedure Clear; procedure Delete(AIndex: integer); @@ -58,7 +60,8 @@ type implementation uses - fpg_utils; + fpg_utils, + project; { TUnitList } @@ -128,6 +131,20 @@ begin end; end; +function TUnitList.AddFileName(const AFilename: TfpgString): TUnit; +var + u: TUnit; +begin + if not FileExists(AFilename) then + begin + u := TUnit.Create; + u.FileName := AFilename; + u.Opened := True; + Add(u); + Result := u; + end; +end; + procedure TUnitList.Add(NewUnit: TUnit); var l: Integer; @@ -176,6 +193,11 @@ begin Result := fpgExtractFileName(Filename); end; +function TUnit.GetRelativePath: TfpgString; +begin + Result := fpgExtractRelativepath(GProject.ProjectDir, FileName); +end; + constructor TUnit.Create; begin inherited Create; -- cgit v1.2.3-70-g09d2 From 27f18ffb0223c1f8186e9614083b2bfcb6c4d261 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sat, 9 Aug 2014 17:59:36 +0100 Subject: maximus: New method to remove an item from the UnitList --- examples/apps/ide/src/unitlist.pas | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/unitlist.pas b/examples/apps/ide/src/unitlist.pas index 37e9a9cd..e6c09a69 100644 --- a/examples/apps/ide/src/unitlist.pas +++ b/examples/apps/ide/src/unitlist.pas @@ -50,6 +50,7 @@ type function FindByName(const AUnitName: TfpgString): TUnit; function FileExists(const AFilename: TfpgString): Boolean; function AddFileName(const AFilename: TfpgString): TUnit; + function Remove(AUnit: TUnit): integer; procedure Add(NewUnit: TUnit); procedure Clear; procedure Delete(AIndex: integer); @@ -145,6 +146,11 @@ begin end; end; +function TUnitList.Remove(AUnit: TUnit): integer; +begin + Result := FList.Remove(AUnit); +end; + procedure TUnitList.Add(NewUnit: TUnit); var l: Integer; -- cgit v1.2.3-70-g09d2 From 641f24b2cbccbb3b8c8629f89b1b9d61196ae950 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sat, 9 Aug 2014 18:01:57 +0100 Subject: maximus: Adds the ability to remove a unit from the project tree Simply select the node in the Project tree "Units" list, and press the DEL key. If you don't save the project, the unit will still be part of the project (easy undo feature). If you save the project the project file will be updated - minus that unit. --- examples/apps/ide/src/frm_main.pas | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas index 65985631..6391ceba 100644 --- a/examples/apps/ide/src/frm_main.pas +++ b/examples/apps/ide/src/frm_main.pas @@ -118,6 +118,7 @@ type procedure AddUnitToProject(const AUnitName: TfpgString); procedure miProjectAddUnitToProject(Sender: TObject); procedure tvProjectDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); + procedure tvProjectKeyPressed(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); procedure grdMessageKeyPressed(Sender: TObject; var KeyCode: Word; var ShiftState: TShiftState; var Consumed: Boolean); procedure TabSheetClosing(Sender: TObject; ATabSheet: TfpgTabSheet); procedure BuildTerminated(Sender: TObject); @@ -587,6 +588,38 @@ begin end; end; +procedure TMainForm.tvProjectKeyPressed(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); +var + r: TfpgTreeNode; + n: TfpgTreeNode; + i: integer; +begin + if keyCode = keyDelete then + begin + r := GetUnitsNode; + if r.FindSubNode(tvProject.Selection.Text, False) = tvProject.Selection then + begin + // remove from project, then from tree view + n := tvProject.Selection; + tvProject.GotoNextNodeUp; + r.Remove(n); + tvProject.Invalidate; + GProject.UnitList.Remove(TUnit(n.Data)); + + for i := 0 to pcEditor.PageCount-1 do + begin + if pcEditor.Pages[i].TagPointer = n.Data then + begin + pcEditor.Pages[i].TagPointer := nil; + break + end; + end; + TUnit(n.Data).Free; + n.Free; + end; + end; +end; + procedure TMainForm.grdMessageKeyPressed(Sender: TObject; var KeyCode: Word; var ShiftState: TShiftState; var Consumed: Boolean); var cr: TClipboardKeyType; @@ -1478,6 +1511,7 @@ begin Hint := ''; TabOrder := 20; OnDoubleClick := @tvProjectDoubleClick; + OnKeyPress := @tvProjectKeyPressed; end; tsFiles := TfpgTabSheet.Create(pnlTool); -- cgit v1.2.3-70-g09d2 From 7ee7fdc34ac81b6fa8384cbc3f6b4698d5694c73 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sat, 9 Aug 2014 18:27:19 +0100 Subject: maximus: ESC key now cancels the Project Options dialog. --- examples/apps/ide/src/frm_configureide.pas | 4 ++-- examples/apps/ide/src/frm_projectoptions.pas | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/frm_configureide.pas b/examples/apps/ide/src/frm_configureide.pas index fad0418f..51061a42 100644 --- a/examples/apps/ide/src/frm_configureide.pas +++ b/examples/apps/ide/src/frm_configureide.pas @@ -1,7 +1,7 @@ { fpGUI IDE - Maximus - Copyright (C) 2012 - 2013 Graeme Geldenhuys + Copyright (C) 2012 - 2014 Graeme Geldenhuys See the file COPYING.modifiedLGPL, included in this distribution, for details about redistributing fpGUI. @@ -229,7 +229,6 @@ constructor TConfigureIDEForm.Create(AOwner: TComponent); begin inherited Create(AOwner); FInternalMacroList := TIDEMacroList.Create; - OnKeyPress := @FormKeyPressed; end; destructor TConfigureIDEForm.Destroy; @@ -248,6 +247,7 @@ begin Hint := ''; ShowHint := True; WindowPosition := wpOneThirdDown; + OnKeyPress := @FormKeyPressed; btnCancel := TfpgButton.Create(self); with btnCancel do diff --git a/examples/apps/ide/src/frm_projectoptions.pas b/examples/apps/ide/src/frm_projectoptions.pas index 1e1c318a..a3e43d6a 100644 --- a/examples/apps/ide/src/frm_projectoptions.pas +++ b/examples/apps/ide/src/frm_projectoptions.pas @@ -1,7 +1,7 @@ { fpGUI IDE - Maximus - Copyright (C) 2012 - 2013 Graeme Geldenhuys + Copyright (C) 2012 - 2014 Graeme Geldenhuys See the file COPYING.modifiedLGPL, included in this distribution, for details about redistributing fpGUI. @@ -103,6 +103,7 @@ type procedure CleanupCompilerDirs; procedure CleanupUserMacrosGrid; procedure SaveToMacroList(AList: TIDEMacroList); + procedure FormKeyPressed(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -582,6 +583,12 @@ begin // AList.SetValue(cMacro_FPCSrcDir, edtFPCSrcDir.Directory); end; +procedure TProjectOptionsForm.FormKeyPressed(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); +begin + if KeyCode = keyEscape then + Close; +end; + constructor TProjectOptionsForm.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -603,6 +610,7 @@ begin WindowTitle := 'Project Options'; Hint := ''; ShowHint := True; + OnKeyPress := @FormKeyPressed; btnCancel := TfpgButton.Create(self); with btnCancel do -- cgit v1.2.3-70-g09d2 From 1969656ef4847ebae9dc4af326b7d047edab7ea4 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 19 Aug 2014 23:58:42 +0100 Subject: maximus: remap a keyboard shortcut to a more common one. --- examples/apps/ide/src/frm_main.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas index 6391ceba..8a8f3c12 100644 --- a/examples/apps/ide/src/frm_main.pas +++ b/examples/apps/ide/src/frm_main.pas @@ -1631,7 +1631,7 @@ begin begin Name := 'mnuProject'; SetPosition(476, 140, 172, 20); - AddMenuItem('Options...', rsKeyCtrl+rsKeyShift+'O', @miProjectOptions); + AddMenuItem('Options...', rsKeyCtrl+rsKeyShift+'F11', @miProjectOptions); AddMenuItem('-', '', nil); AddMenuItem('New (empty)...', '', @miProjectNew); AddMenuItem('New from Template...', '', @miProjectNewFromTemplate); -- cgit v1.2.3-70-g09d2 From 1abbcc014af1a0e42d6c37bbb4a9e73c2501472f Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Wed, 20 Aug 2014 23:04:22 +0100 Subject: Maximus Lazarus project file had incorrect case of unit name in project. mpaslax.pas -> mPasLex.pas --- examples/apps/ide/src/maximus.lpi | 33 ++++++++++----------------------- examples/apps/ide/src/maximus.lpr | 1 - 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'examples/apps') diff --git a/examples/apps/ide/src/maximus.lpi b/examples/apps/ide/src/maximus.lpi index accb3570..01a377d7 100644 --- a/examples/apps/ide/src/maximus.lpi +++ b/examples/apps/ide/src/maximus.lpi @@ -42,7 +42,6 @@ - @@ -52,7 +51,6 @@ - @@ -67,7 +65,6 @@ - @@ -77,7 +74,6 @@ - @@ -97,47 +93,42 @@ - - - - + - + - + - - + - + - + - - + - + - + - + @@ -162,11 +153,7 @@ - - - - diff --git a/examples/apps/ide/src/maximus.lpr b/examples/apps/ide/src/maximus.lpr index cf9c439f..13a2047e 100644 --- a/examples/apps/ide/src/maximus.lpr +++ b/examples/apps/ide/src/maximus.lpr @@ -39,7 +39,6 @@ uses ideimages, stringhelpers, frm_procedurelist, - mPasLex, filemonitor, SynRegExpr, fpg_textedit, -- cgit v1.2.3-70-g09d2