diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2013-03-18 11:32:12 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2013-03-18 11:32:12 +0000 |
commit | 3d6095876e7ec0bbd7b37f6f96ba8a6aa749e92d (patch) | |
tree | 7fbaad7e91128d41e4519be8aa2759b02be548a8 /examples/apps/ide/src | |
parent | be0b02c02346b9dd17f37295bc84a3693c011a9b (diff) | |
download | fpGUI-3d6095876e7ec0bbd7b37f6f96ba8a6aa749e92d.tar.xz |
ide: Adds the ability to add a new empty unit
The new unit will be based on the ${templates}/default/unit.pas file.
Diffstat (limited to 'examples/apps/ide/src')
-rw-r--r-- | examples/apps/ide/src/frm_main.pas | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/examples/apps/ide/src/frm_main.pas b/examples/apps/ide/src/frm_main.pas index 2c658fde..6ef73f50 100644 --- a/examples/apps/ide/src/frm_main.pas +++ b/examples/apps/ide/src/frm_main.pas @@ -73,6 +73,7 @@ type btnTest: TfpgButton; {$endif} pmOpenRecentMenu: TfpgPopupMenu; + miFile: TfpgMenuItem; miRecentProjects: TfpgMenuItem; FRecentFiles: TfpgMRU; FRegex: TRegExpr; @@ -86,6 +87,7 @@ type procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure btnQuitClicked(Sender: TObject); procedure btnOpenFileClicked(Sender: TObject); + procedure miFileNewUnit(Sender: TObject); procedure miFileSave(Sender: TObject); procedure miFileSaveAs(Sender: TObject); procedure miEditCutClicked(Sender: TObject); @@ -197,6 +199,34 @@ begin end; end; +procedure TMainForm.miFileNewUnit(Sender: TObject); +var + newunit: TfpgString; + sl: TStringList; + FInternalMacroList: TIDEMacroList; + i: integer; +begin + if fpgInputQuery('New Unit', 'Please give the new unit a file name', newunit) then + begin + if GProject.UnitList.FileExists(newunit) then + begin + ShowMessage(Format('The unit <%s> already exists in the project', [newunit])); + Exit; + end; + sl := TStringList.Create; + try + sl.LoadFromFile(GMacroList.ExpandMacro('${TEMPLATEDIR}default/unit.pas')); + sl.Text := StringReplace(sl.Text, '${UNITNAME}', fpgChangeFileExt(fpgExtractFileName(newunit), ''), [rfReplaceAll, rfIgnoreCase]); + sl.SaveToFile(GProject.ProjectDir + newunit); + finally + sl.Free; + end; +// AddUnitToProject(newunit); + + OpenEditorPage(newunit); + end; +end; + procedure TMainForm.miFileSave(Sender: TObject); var s: TfpgString; @@ -1506,7 +1536,7 @@ begin begin Name := 'mnuFile'; SetPosition(476, 61, 172, 20); - AddMenuItem('New...', rsKeyCtrl+'N', nil).Enabled := False; + miFile := AddMenuItem('New...', rsKeyCtrl+'N', @miFileNewUnit); AddMenuItem('-', '', nil); AddMenuItem('Open...', rsKeyCtrl+'O', @btnOpenFileClicked); AddMenuItem('Open Recent', '', nil).Enabled := False; |