diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2013-03-18 11:32:12 +0000 |
---|---|---|
committer | David Laurence Emerson <dle3ab@angelbase.com> | 2013-05-28 00:42:48 -0700 |
commit | 2ef3523c98abd0f4114c173f19ce6cf00bb89d21 (patch) | |
tree | ffcce119091b5c230200f24706cdae451bbe2fd3 /examples/apps | |
parent | d10aa1f27cfde7341335812428df9a6907edc62a (diff) | |
download | fpGUI-2ef3523c98abd0f4114c173f19ce6cf00bb89d21.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')
-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; |