mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 11:39:27 +02:00
IDE bugfixes and viewunit/forms functionality
git-svn-id: trunk@213 -
This commit is contained in:
parent
45af56fc7b
commit
7553c2f49b
@ -1,12 +1,9 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
/***************************************************************************
|
||||
Lazarus.pp - Main application unit
|
||||
Lazarus.pp
|
||||
-------------------
|
||||
This unit does nothing more than launch the
|
||||
TConfig Object which is responsible for the
|
||||
creation of everything else.
|
||||
|
||||
This is the lazarus editor program.
|
||||
|
||||
Initial Revision : Sun Mar 28 23:15:32 CST 1999
|
||||
|
||||
@ -25,47 +22,47 @@
|
||||
|
||||
program lazarus;
|
||||
|
||||
{$mode objfpc}
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
forms,
|
||||
splash,
|
||||
main,
|
||||
dlgMessage,
|
||||
viewunit_dlg, //dialog used to list the units in a project
|
||||
viewform_dlg, //dialog to display the forms in the project
|
||||
Forms,
|
||||
Splash,
|
||||
Main,
|
||||
DlgMessage,
|
||||
FindReplaceDialog;
|
||||
|
||||
var
|
||||
SplashForm: TSplashForm;
|
||||
|
||||
begin
|
||||
Application.Initialize; { calls InitProcedure which starts up GTK }
|
||||
Application.Initialize;
|
||||
// calls InitProcedure which starts up the interface (e.g. GTK)
|
||||
|
||||
//Show splashform
|
||||
SplashForm := TSplashForm.Create(nil);
|
||||
with SplashForm do
|
||||
begin
|
||||
Show;
|
||||
Paint;
|
||||
end;
|
||||
// Show splashform
|
||||
SplashForm := TSplashForm.Create(nil);
|
||||
with SplashForm do
|
||||
begin
|
||||
Show;
|
||||
Paint;
|
||||
end;
|
||||
|
||||
Application.CreateForm(TMainIDE, MainIDE);
|
||||
Application.CreateForm(TMessageDlg, MessageDlg);
|
||||
Application.CreateForm(TViewUnits1, ViewUnits1);
|
||||
Application.CreateForm(TViewForms1, ViewForms1);
|
||||
Application.CreateForm(TLazFindReplaceDialog, FindReplaceDlg);
|
||||
SplashForm.StartTimer;
|
||||
Application.Run;
|
||||
Application.CreateForm(TMainIDE, MainIDE);
|
||||
Application.CreateForm(TMessageDlg, MessageDlg);
|
||||
Application.CreateForm(TLazFindReplaceDialog, FindReplaceDlg);
|
||||
SplashForm.StartTimer;
|
||||
Application.Run;
|
||||
|
||||
// workaround till lcl closes clean
|
||||
Application.Free;
|
||||
Application:=nil;
|
||||
// workaround till lcl closes clean
|
||||
Application.Free;
|
||||
Application:=nil;
|
||||
end.
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.16 2001/03/08 15:59:06 lazarus
|
||||
IDE bugfixes and viewunit/forms functionality
|
||||
|
||||
Revision 1.15 2001/02/22 17:04:57 lazarus
|
||||
added environment options + killed ide unit circles
|
||||
|
||||
|
192
ide/main.pp
192
ide/main.pp
@ -182,7 +182,6 @@ type
|
||||
fProject: TProject;
|
||||
|
||||
Function CreateSeperator : TMenuItem;
|
||||
Procedure UpdateViewDialogs;
|
||||
Procedure SetDefaultsForForm(aForm : TCustomForm);
|
||||
|
||||
protected
|
||||
@ -203,6 +202,8 @@ type
|
||||
function DoOpenEditorFile(AFileName:string; ProjectLoading:boolean):TModalResult;
|
||||
function DoOpenFileAtCursor(Sender: TObject):TModalResult;
|
||||
function DoSaveAll: TModalResult;
|
||||
function DoOpenMainUnit(ProjectLoading: boolean): TModalResult;
|
||||
function DoViewUnitsAndForms(OnlyForms: boolean): TModalResult;
|
||||
|
||||
// project(s)
|
||||
function DoNewProject(NewProjectType:TProjectType):TModalResult;
|
||||
@ -975,40 +976,6 @@ end;
|
||||
|
||||
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{Fills the View Units dialog and the View Forms dialog}
|
||||
{------------------------------------------------------------------------------}
|
||||
|
||||
Procedure TMainIDE.UpdateViewDialogs;
|
||||
var a,ProgramNameStart,ProgramNameEnd:integer;
|
||||
s,SrcTxt:string;
|
||||
Begin
|
||||
ViewUnits1.Listbox1.Items.BeginUpdate;
|
||||
ViewUnits1.Listbox1.Items.Clear;
|
||||
// ViewForms1.Listbox1.Items.BeginUpdate;
|
||||
// ViewForms1.Listbox1.Items.Clear;
|
||||
for a:=0 to Project.UnitCount-1 do begin
|
||||
if Project.Units[a].IsPartOfProject then begin
|
||||
if (Project.Units[a].Unitname<>'') then begin
|
||||
ViewUnits1.Listbox1.Items.Add(Project.Units[a].Unitname);
|
||||
// if Project.Units[a].FormName<>'' then
|
||||
// ViewForms1.Listbox1.Items.Add(Project.Units[a].Unitname);
|
||||
end else if (Project.MainUnit=a)
|
||||
and (Project.ProjectType in [ptProgram,ptApplication]) then begin
|
||||
s:=ExtractFilename(Project.Units[a].Filename);
|
||||
if s='' then begin
|
||||
SrcTxt:=Project.Units[a].Source.Text;
|
||||
s:=FindProgramNameInSource(SrcTxt,ProgramNameStart,ProgramnameEnd);
|
||||
end;
|
||||
if s<>'' then
|
||||
ViewUnits1.Listbox1.Items.Add(s);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
ViewUnits1.Listbox1.Items.EndUpdate;
|
||||
// ViewForms1.Listbox1.Items.EndUpdate;
|
||||
End;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{------------------------------------------------------------------------------}
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -1024,13 +991,11 @@ Begin
|
||||
SourceNotebook.DisplayCodeforControl(FControlLastActivated);
|
||||
end;
|
||||
|
||||
Procedure TMainIDE.CodeorFormActivated(Sender : TObject);
|
||||
Procedure TMainIDE.CodeOrFormActivated(Sender : TObject);
|
||||
Begin
|
||||
FCodeLastActivated := (TForm(Sender) = TForm(SourceNotebook));
|
||||
if FCodeLastActivated then Writeln('TRUE') else Writeln('False');
|
||||
|
||||
FControlLastActivated := Sender;
|
||||
|
||||
end;
|
||||
|
||||
Procedure TMainIDE.SetDesigning(Control : TComponent; Value : Boolean);
|
||||
@ -1339,19 +1304,13 @@ end;
|
||||
{------------------------------------------------------------------------------}
|
||||
|
||||
Procedure TMainIDE.mnuViewUnitsClicked(Sender : TObject);
|
||||
Begin
|
||||
Writeln('View Units Clicked');
|
||||
UpdateViewDialogs;
|
||||
ViewUnits1.ShowModal;
|
||||
Writeln('Done with ViewUnits Clicked');
|
||||
begin
|
||||
DoViewUnitsAndForms(false);
|
||||
end;
|
||||
|
||||
Procedure TMainIDE.mnuViewFormsClicked(Sender : TObject);
|
||||
Begin
|
||||
Writeln('View Forms Clicked');
|
||||
UpdateViewDialogs;
|
||||
ViewForms1.ShowModal;
|
||||
Writeln('Done with ViewForms Clicked');
|
||||
DoViewUnitsAndForms(true);
|
||||
end;
|
||||
|
||||
Procedure TMainIDE.mnuViewCodeExplorerClick(Sender : TObject);
|
||||
@ -1611,6 +1570,7 @@ writeln('TMainIDE.DoNewEditorUnit 6');
|
||||
PropertyEditorHook1.LookupRoot := TForm(CInterface.Control);
|
||||
FormEditor1.AddSelected(TComponent(CInterface.Control));
|
||||
end;
|
||||
UpdateMainUnitSrcEdit;
|
||||
|
||||
writeln('TMainIDE.DoNewUnit end');
|
||||
|
||||
@ -1643,6 +1603,15 @@ writeln('TMainIDE.DoSaveCurUnit 1');
|
||||
ActiveUnitInfo.Modified:=true;
|
||||
end;
|
||||
|
||||
if ActiveUnitInfo.Filename='' then begin
|
||||
if (Project.MainUnit>=0)
|
||||
and (Project.Units[Project.MainUnit]=ActiveUnitInfo) then begin
|
||||
// new project has no name yet -> save project
|
||||
Result:=DoSaveProject(true);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
// load old resource file
|
||||
ResourceFileName:=Project.SearchResourceFilename(ActiveUnitInfo);
|
||||
if (ActiveUnitInfo.Filename<>'') and (FileExists(ResourceFileName)) then begin
|
||||
@ -1669,7 +1638,6 @@ writeln('TMainIDE.DoSaveCurUnit 1');
|
||||
|
||||
|
||||
writeln('TMainIDE.DoSaveCurUnit 2');
|
||||
// ToDo: only save if modified
|
||||
SaveAllParts:=false;
|
||||
if ActiveUnitInfo.Filename='' then SaveAs:=true;
|
||||
if SaveAs then begin
|
||||
@ -1910,7 +1878,7 @@ writeln('TMainIDE.DoOpenEditorFile');
|
||||
Result:=mrCancel;
|
||||
if AFileName='' then exit;
|
||||
Ext:=lowercase(ExtractFileExt(AFilename));
|
||||
if (not ProjectLoading) and (Ext='.lpi') then begin
|
||||
if (not ProjectLoading) and ((Ext='.lpi') or (Ext='.lpr')) then begin
|
||||
// load program file and project info file
|
||||
Result:=DoOpenProjectFile(AFilename);
|
||||
exit;
|
||||
@ -1998,6 +1966,110 @@ writeln('TMainIDE.DoOpenEditorFile');
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
function TMainIDE.DoOpenMainUnit(ProjectLoading: boolean): TModalResult;
|
||||
var MainUnitInfo: TUnitInfo;
|
||||
NewPageName, SrcTxt: string;
|
||||
NewSrcEdit: TSourceEditor;
|
||||
ProgramNameStart,ProgramNameEnd: integer;
|
||||
begin
|
||||
writeln('TMainIDE.DoOpenMainUnit 1');
|
||||
Result:=mrCancel;
|
||||
if Project.MainUnit<0 then exit;
|
||||
MainUnitInfo:=Project.Units[Project.MainUnit];
|
||||
if MainUnitInfo.Loaded then begin
|
||||
// already loaded switch to source editor
|
||||
SourceNotebook.NoteBook.PageIndex:=MainUnitInfo.EditorIndex;
|
||||
Result:=mrOk;
|
||||
exit;
|
||||
end;
|
||||
writeln('TMainIDE.DoOpenMainUnit 2');
|
||||
// MainUnit not loaded -> create source editor
|
||||
NewPageName:=MainUnitInfo.Unitname;
|
||||
if NewPageName='' then begin
|
||||
NewPageName:=ExtractFileName(MainUnitInfo.Filename);
|
||||
NewPageName:=copy(NewPageName,1,
|
||||
length(NewPageName)-length(ExtractFileExt(NewPageName)));
|
||||
end;
|
||||
if NewpageName='' then begin
|
||||
SrcTxt:=MainUnitInfo.Source.Text;
|
||||
NewPageName:=FindProgramNameInSource(SrcTxt,ProgramNameStart,ProgramNameEnd);
|
||||
end;
|
||||
if NewpageName='' then begin
|
||||
NewPageName:='mainunit';
|
||||
end;
|
||||
writeln('TMainIDE.DoOpenMainUnit 3');
|
||||
SourceNotebook.NewFile(NewPageName,MainUnitInfo.Source);
|
||||
if not ProjectLoading then
|
||||
Project.InsertEditorIndex(SourceNotebook.NoteBook.PageIndex);
|
||||
MainUnitInfo.EditorIndex:=SourceNotebook.NoteBook.PageIndex;
|
||||
MainUnitInfo.Loaded:=true;
|
||||
NewSrcEdit:=SourceNotebook.GetActiveSE;
|
||||
NewSrcEdit.SyntaxHighlighterType:=MainUnitInfo.SyntaxHighlighter;
|
||||
NewSrcEdit.EditorComponent.CaretXY:=MainUnitInfo.CursorPos;
|
||||
NewSrcEdit.EditorComponent.TopLine:=MainUnitInfo.TopLine;
|
||||
|
||||
Result:=mrOk;
|
||||
writeln('TMainIDE.DoOpenMainUnit end');
|
||||
end;
|
||||
|
||||
function TMainIDE.DoViewUnitsAndForms(OnlyForms: boolean): TModalResult;
|
||||
var UnitList: TList;
|
||||
i, ProgramNameStart, ProgramNameEnd:integer;
|
||||
MainUnitName: string;
|
||||
MainUnitInfo, AnUnitInfo: TUnitInfo;
|
||||
Begin
|
||||
UnitList:= TList.Create;
|
||||
try
|
||||
writeln('TMainIDE.mnuViewUnitsClicked 1');
|
||||
for i:=0 to Project.UnitCount-1 do begin
|
||||
if Project.Units[i].IsPartOfProject then begin
|
||||
if OnlyForms then begin
|
||||
if Project.Units[i].FormName<>'' then
|
||||
UnitList.Add(TViewUnitsEntry.Create(
|
||||
Project.Units[i].FormName,i,false));
|
||||
end else begin
|
||||
if Project.Units[i].UnitName<>'' then begin
|
||||
UnitList.Add(TViewUnitsEntry.Create(
|
||||
Project.Units[i].UnitName,i,false));
|
||||
end else if Project.MainUnit=i then begin
|
||||
MainUnitInfo:=Project.Units[Project.MainUnit];
|
||||
if Project.ProjectType in [ptProgram,ptApplication,ptCustomProgram]
|
||||
then begin
|
||||
if (MainUnitInfo.Loaded) then
|
||||
MainUnitName:=SourceNoteBook.NoteBook.Pages[
|
||||
MainUnitInfo.EditorIndex];
|
||||
if MainUnitName='' then begin
|
||||
MainUnitName:=FindProgramNameInSource(MainUnitInfo.Source.Text
|
||||
,ProgramNameStart,ProgramNameEnd);
|
||||
end;
|
||||
if MainUnitName<>'' then
|
||||
UnitList.Add(TViewUnitsEntry.Create(
|
||||
MainUnitName,i,false));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
writeln('TMainIDE.mnuViewUnitsClicked 2');
|
||||
if ShowViewUnitsDlg(UnitList,true)=mrOk then begin
|
||||
for i:=0 to UnitList.Count-1 do begin
|
||||
if TViewUnitsEntry(UnitList[i]).Selected then begin
|
||||
AnUnitInfo:=Project.Units[TViewUnitsEntry(UnitList[i]).ID];
|
||||
if AnUnitInfo.Loaded then
|
||||
SourceNoteBook.NoteBook.PageIndex:=AnUnitInfo.EditorIndex
|
||||
else begin
|
||||
if DoOpenEditorFile(AnUnitInfo.Filename,false)=mrAbort then exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
writeln('TMainIDE.mnuViewUnitsClicked 3');
|
||||
finally
|
||||
UnitList.Free;
|
||||
end;
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
function TMainIDE.DoOpenFileAtCursor(Sender: TObject):TModalResult;
|
||||
begin
|
||||
writeln('TMainIDE.DoOpenFileAtCursor');
|
||||
@ -2007,12 +2079,14 @@ writeln('TMainIDE.DoOpenFileAtCursor');
|
||||
end;
|
||||
|
||||
function TMainIDE.DoNewProject(NewProjectType:TProjectType):TModalResult;
|
||||
var i:integer;
|
||||
Begin
|
||||
writeln('TMainIDE.DoNewProject 1');
|
||||
Result:=mrCancel;
|
||||
|
||||
If Project<>nil then begin
|
||||
//save and close the project
|
||||
|
||||
if DoSaveProject(false)=mrAbort then begin
|
||||
Result:=mrAbort;
|
||||
exit;
|
||||
@ -2037,14 +2111,19 @@ writeln('TMainIDE.DoNewProject 4');
|
||||
// create a first form unit
|
||||
DoNewEditorUnit(nuForm);
|
||||
end;
|
||||
else
|
||||
// ptProgram
|
||||
ptProgram,ptCustomProgram:
|
||||
begin
|
||||
// create a first unit
|
||||
DoNewEditorUnit(nuUnit);
|
||||
// show program unit
|
||||
DoOpenMainUnit(false);
|
||||
end;
|
||||
end;
|
||||
|
||||
// set all modified to false
|
||||
Project.Modified:=false;
|
||||
for i:=0 to Project.UnitCount-1 do begin
|
||||
Project.Units[i].Modified:=false;
|
||||
end;
|
||||
|
||||
writeln('TMainIDE.DoNewProject end');
|
||||
UpdateCaption;
|
||||
Result:=mrOk;
|
||||
@ -2061,7 +2140,8 @@ begin
|
||||
writeln('TMainIDE.DoSaveProject 1');
|
||||
// check that all new units are saved first
|
||||
for i:=0 to Project.UnitCount-1 do begin
|
||||
if (Project.Units[i].Loaded) and (Project.Units[i].Filename='') then begin
|
||||
if (Project.Units[i].Loaded) and (Project.Units[i].Filename='')
|
||||
and (Project.MainUnit<>i) then begin
|
||||
Result:=DoSaveEditorUnit(Project.Units[i].EditorIndex,false);
|
||||
if (Result=mrAbort) or (Result=mrCancel) then exit;
|
||||
end;
|
||||
@ -2446,8 +2526,8 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.69 2001/03/05 14:24:52 lazarus
|
||||
bugfixes for ide project code
|
||||
Revision 1.70 2001/03/08 15:59:06 lazarus
|
||||
IDE bugfixes and viewunit/forms functionality
|
||||
|
||||
Revision 1.68 2001/03/03 11:06:15 lazarus
|
||||
added project support, codetools
|
||||
|
@ -115,8 +115,9 @@ type
|
||||
TNewUnitType = (
|
||||
nuEmpty, // no code
|
||||
nuUnit, // unit
|
||||
nuForm // unit with form
|
||||
);
|
||||
nuForm, // unit with form
|
||||
nuCustomProgram // program
|
||||
);
|
||||
|
||||
|
||||
TUnitInfo = class(TObject)
|
||||
@ -183,7 +184,7 @@ type
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
TProjectType = // for a description see ProjectTypeDescriptions
|
||||
(ptProgram, ptApplication);
|
||||
(ptApplication, ptCustomProgram, ptProgram);
|
||||
|
||||
TProject = class(TObject)
|
||||
private
|
||||
@ -266,24 +267,27 @@ const
|
||||
ResourceFileExt = '.lrs';
|
||||
|
||||
ProjectTypeNames : array[TProjectType] of string = (
|
||||
'Program','Application'
|
||||
'Application', 'Program', 'Custom program'
|
||||
);
|
||||
|
||||
ProjectTypeDescriptions : array[TProjectType] of string = (
|
||||
// ptApplication
|
||||
'Application'#13
|
||||
+'A graphical lcl/freepascal program. The program file is '
|
||||
+'automatically maintained by lazarus.'
|
||||
|
||||
// ptProgram
|
||||
'Program:'#13
|
||||
,'Program:'#13
|
||||
+'A freepascal program. The program file is automatically '
|
||||
+'maintained by lazarus.'
|
||||
|
||||
// ptCustomProgram
|
||||
,'Custom program:'#13
|
||||
+'A freepascal program.'
|
||||
|
||||
// ptApplication
|
||||
,'Application'#13
|
||||
+'A graphical lcl/freepascal program.'
|
||||
|
||||
);
|
||||
|
||||
ProjectDefaultExt : array[TProjectType] of string = (
|
||||
'.pp',
|
||||
'.lpr'
|
||||
'.lpr','.pp','.pp'
|
||||
);
|
||||
|
||||
|
||||
@ -715,6 +719,17 @@ begin
|
||||
Add('');
|
||||
Add('end.');
|
||||
Add('');
|
||||
end else if NewUnitType in [nuCustomProgram] then with Source do begin
|
||||
Add('program CustomProgram;');
|
||||
Add('');
|
||||
Add('{$mode objfpc}{$H+}');
|
||||
Add('');
|
||||
Add('uses');
|
||||
Add(' Classes, SysUtils;');
|
||||
Add('');
|
||||
Add('begin');
|
||||
Add('end.');
|
||||
Add('');
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -756,11 +771,12 @@ begin
|
||||
|
||||
// create program source
|
||||
case fProjectType of
|
||||
ptProgram, ptApplication:
|
||||
ptProgram, ptApplication, ptCustomProgram:
|
||||
begin
|
||||
PrgUnitInfo:=TUnitInfo.Create;
|
||||
PrgUnitInfo.IsPartOfProject:=true;
|
||||
PrgUnitInfo.SyntaxHighlighter:=ExtensionToLazSyntaxHighlighter('.lpr');
|
||||
PrgUnitInfo.SyntaxHighlighter:=
|
||||
ExtensionToLazSyntaxHighlighter(ProjectDefaultExt[fProjectType]);
|
||||
AddUnit(PrgUnitInfo,false);
|
||||
MainUnit:=0;
|
||||
with Units[MainUnit].Source do begin
|
||||
@ -770,7 +786,7 @@ begin
|
||||
Add('');
|
||||
Add('uses');
|
||||
case fProjectType of
|
||||
ptProgram: Add(' Classes;');
|
||||
ptProgram, ptCustomProgram: Add(' Classes;');
|
||||
ptApplication: Add(' Forms;');
|
||||
else
|
||||
Add(' { add your units here };');
|
||||
@ -991,7 +1007,7 @@ begin
|
||||
Units[MainUnit].Source.Text:=SrcText;
|
||||
end;
|
||||
|
||||
// delete bookmarks and breakpoints on this unit
|
||||
// delete bookmarks on this unit
|
||||
if OldUnitInfo.EditorIndex>=0 then begin
|
||||
Bookmarks.DeleteAllWithEditorIndex(OldUnitInfo.EditorIndex);
|
||||
end;
|
||||
@ -1261,6 +1277,7 @@ var NewProgramName,Ext,SrcTxt:string;
|
||||
SrcChanged:boolean;
|
||||
begin
|
||||
DoDirSeparators(NewProjectFilename);
|
||||
NewProjectFilename:=ExpandFilename(NewProjectFilename);
|
||||
if NewProjectFilename=fProjectFile then exit;
|
||||
Ext:=ExtractFileExt(NewProjectFilename);
|
||||
if ProjectType in [ptProgram, ptApplication] then begin
|
||||
@ -1368,8 +1385,8 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.11 2001/03/05 14:24:52 lazarus
|
||||
bugfixes for ide project code
|
||||
Revision 1.12 2001/03/08 15:59:06 lazarus
|
||||
IDE bugfixes and viewunit/forms functionality
|
||||
|
||||
Revision 1.10 2001/03/03 11:06:15 lazarus
|
||||
added project support, codetools
|
||||
|
@ -2,11 +2,11 @@
|
||||
{
|
||||
/***************************************************************************
|
||||
ViewUnit_dlg.pp
|
||||
-------------------
|
||||
TViewUnit is the application dialog for displaying all units in a project.
|
||||
-------------------
|
||||
TViewUnit is the application dialog for displaying all units in a project.
|
||||
|
||||
|
||||
Initial Revision : Sat Feb 19 17:42 CST 1999
|
||||
Initial Revision : Sat Feb 19 17:42 CST 1999
|
||||
|
||||
|
||||
***************************************************************************/
|
||||
@ -20,149 +20,158 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
}
|
||||
{$H+}
|
||||
unit ViewUnit_Dlg;
|
||||
|
||||
{$mode objfpc}
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,LResources,buttons,stdctrls;
|
||||
|
||||
SysUtils, Classes, Controls, Forms, Dialogs, LResources, Buttons, StdCtrls;
|
||||
|
||||
type
|
||||
|
||||
TViewUnits1 = class(TFORM)
|
||||
Edit1: TEdit;
|
||||
ListBox1: TListBox;
|
||||
TViewUnitsEntry = class
|
||||
public
|
||||
Name: string;
|
||||
ID: integer;
|
||||
Selected: boolean;
|
||||
constructor Create(AName: string; AnID: integer; ASelected: boolean);
|
||||
end;
|
||||
|
||||
TViewUnits = class(TForm)
|
||||
ListBox: TListBox;
|
||||
btnOK : TButton;
|
||||
btnCancel : TButton;
|
||||
Procedure btnOKClick(Sender : TOBject);
|
||||
Procedure btnCancelClick(Sender : TOBject);
|
||||
Procedure Listbox1Click(Sender : TObject);
|
||||
protected
|
||||
public
|
||||
// constructor Create(AOwner: TComponent); override;
|
||||
end;
|
||||
|
||||
var
|
||||
ViewUnits1 : TViewUnits1;
|
||||
|
||||
implementation
|
||||
|
||||
{
|
||||
constructor TViewUnits1.Create(AOwner: TComponent);
|
||||
var
|
||||
Pad : Integer;
|
||||
begin
|
||||
|
||||
inherited Create(AOwner);
|
||||
Caption := 'View Project Units';
|
||||
Left := 0;
|
||||
Top := 0;
|
||||
Width := 325;
|
||||
height := 200;
|
||||
Pad := 10;
|
||||
position := poScreenCenter;
|
||||
Name := 'ViewUnits1';
|
||||
|
||||
btnOK := TButton.Create(Self);
|
||||
btnOK.Parent := Self;
|
||||
btnOK.Left := ClientWidth - 90;
|
||||
btnOK.Top := pad;
|
||||
btnOK.Width := 75;
|
||||
btnOK.Height := 25;
|
||||
btnOK.Caption := 'OK';
|
||||
btnOK.Visible := True;
|
||||
btnOK.OnClick := @btnOKClick;
|
||||
btnOK.Name := 'btnOK';
|
||||
|
||||
btnCancel := TButton.Create(Self);
|
||||
btnCancel.Parent := Self;
|
||||
btnCancel.Left := ClientWidth - 90;
|
||||
btnCancel.Top := btnOK.Top + btnOK.Height + pad;
|
||||
btnCancel.Width := 75;
|
||||
btnCancel.Height := 25;
|
||||
btnCancel.Caption := 'Cancel';
|
||||
btnCancel.Visible := True;
|
||||
btnCancel.Name := 'btnCancel';
|
||||
btnCancel.OnClick := @btnCancelClick;
|
||||
|
||||
Edit1 := TEdit.Create(Self);
|
||||
Edit1.Parent := Self;
|
||||
Edit1.Left := pad;
|
||||
Edit1.Top := pad;
|
||||
edit1.Width := ClientWidth - (ClientWidth - btnOK.Left) - (2*pad);
|
||||
Edit1.Height := 25;
|
||||
Edit1.Visible := True;
|
||||
Edit1.Name := 'Edit1';
|
||||
|
||||
Listbox1:= TListBox.Create(Self);
|
||||
with Listbox1 do begin
|
||||
Parent:= Self;
|
||||
Top:= Edit1.Height + Edit1.Top + Pad;
|
||||
Left:= pad;
|
||||
Width:= ClientWidth - (ClientWidth - btnOK.Left) - (2*pad);
|
||||
Height:= Self.Height - Top - pad;
|
||||
Visible:= true;
|
||||
MultiSelect:= false;
|
||||
Name := 'Listbox1';
|
||||
OnClick := @ListBox1Click;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
end;
|
||||
|
||||
|
||||
function ShowViewUnitsDlg(Entries: TList; MultiSelect: boolean): TModalResult;
|
||||
// Entries is a list of TViewUnitsEntry(s)
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
function ShowViewUnitsDlg(Entries: TList;
|
||||
MultiSelect: boolean): TModalResult;
|
||||
var ViewUnits: TViewUnits;
|
||||
i: integer;
|
||||
begin
|
||||
ViewUnits:=TViewUnits.Create(Application);
|
||||
try
|
||||
ViewUnits.ListBox.Visible:=false;
|
||||
ViewUnits.ListBox.MultiSelect:=MultiSelect;
|
||||
with ViewUnits.ListBox.Items do begin
|
||||
BeginUpdate;
|
||||
Clear;
|
||||
for i:=0 to Entries.Count-1 do
|
||||
Add(TViewUnitsEntry(Entries[i]).Name);
|
||||
EndUpdate;
|
||||
end;
|
||||
for i:=0 to Entries.Count-1 do
|
||||
ViewUnits.ListBox.Selected[i]:=TViewUnitsEntry(Entries[i]).Selected;
|
||||
ViewUnits.ListBox.Visible:=true;
|
||||
Result:=ViewUnits.ShowModal;
|
||||
if Result=mrOk then begin
|
||||
for i:=0 to Entries.Count-1 do
|
||||
TViewUnitsEntry(Entries[i]).Selected:=ViewUnits.ListBox.Selected[i];
|
||||
end;
|
||||
finally
|
||||
ViewUnits.Free;
|
||||
end;
|
||||
end;
|
||||
}
|
||||
|
||||
Procedure TViewUnits1.btnOKClick(Sender : TOBject);
|
||||
{ TViewUnitsEntry }
|
||||
|
||||
constructor TViewUnitsEntry.Create(AName: string; AnID: integer;
|
||||
ASelected: boolean);
|
||||
begin
|
||||
inherited Create;
|
||||
Name:=AName;
|
||||
ID:=AnID;
|
||||
Selected:=ASelected;
|
||||
end;
|
||||
|
||||
{ TViewUnits }
|
||||
|
||||
constructor TViewUnits.Create(AOwner: TComponent);
|
||||
var Pad : Integer;
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
if LazarusResources.Find(Classname)=nil then begin
|
||||
Caption := 'View Project Units';
|
||||
SetBounds((Screen.Width-345) div 2, (Screen.Height-220) div 2, 325, 200);
|
||||
Pad := 10;
|
||||
Position := poScreenCenter;
|
||||
|
||||
btnOK := TButton.Create(Self);
|
||||
with btnOk do begin
|
||||
Parent := Self;
|
||||
Left := Self.Width - 90;
|
||||
Top := pad;
|
||||
Width := 75;
|
||||
Height := 25;
|
||||
Caption := 'OK';
|
||||
Visible := True;
|
||||
OnClick := @btnOKClick;
|
||||
Name := 'btnOK';
|
||||
end;
|
||||
|
||||
btnCancel := TButton.Create(Self);
|
||||
with btnCancel do begin
|
||||
Parent := Self;
|
||||
Left := Self.Width - 90;
|
||||
Top := btnOK.Top + btnOK.Height + pad;
|
||||
Width := 75;
|
||||
Height := 25;
|
||||
Caption := 'Cancel';
|
||||
Visible := True;
|
||||
Name := 'btnCancel';
|
||||
OnClick := @btnCancelClick;
|
||||
end;
|
||||
|
||||
Listbox:= TListBox.Create(Self);
|
||||
with Listbox do begin
|
||||
Parent:= Self;
|
||||
Top:= Pad;
|
||||
Left:= Pad;
|
||||
Width:= Self.Width - (Self.Width - btnOK.Left) - (2*pad);
|
||||
Height:= Self.Height - Top - Pad;
|
||||
Visible:= true;
|
||||
MultiSelect:= false;
|
||||
Name := 'Listbox';
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Procedure TViewUnits.btnOKClick(Sender : TOBject);
|
||||
Begin
|
||||
{
|
||||
Search the list to see if it is already on a page.
|
||||
If so, simply set that page to the front. If not
|
||||
then load it into a new page.
|
||||
}
|
||||
modalresult := mrOK;
|
||||
ModalResult := mrOK;
|
||||
End;
|
||||
|
||||
|
||||
Procedure TViewUnits1.btnCancelClick(Sender : TOBject);
|
||||
Procedure TViewUnits.btnCancelClick(Sender : TOBject);
|
||||
Begin
|
||||
ModalResult := mrCancel;
|
||||
ModalResult := mrCancel;
|
||||
end;
|
||||
|
||||
Procedure TViewUnits1.listbox1Click(Sender : TObject);
|
||||
Var
|
||||
I : Integer;
|
||||
Begin
|
||||
if Listbox1.Items.Count > 0 then
|
||||
Begin
|
||||
for i := 0 to Listbox1.Items.Count-1 do
|
||||
Begin
|
||||
if Listbox1.Selected[I] then
|
||||
Begin
|
||||
Assert(False, 'Trace:Selected index is '+ IntToStr(i) + ' and test is ' + Listbox1.Items.Strings[i]);
|
||||
Edit1.Text := Listbox1.Items.Strings[i];
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
initialization
|
||||
{Do not change the following}
|
||||
{<LAZARUSFORMDEF>}
|
||||
{$I viewunits1.lrs}
|
||||
{<LAZARUSFORMDEFEND>}
|
||||
{}
|
||||
{ $I viewunits1.lrs}
|
||||
|
||||
|
||||
end.
|
||||
{
|
||||
$Log$
|
||||
Revision 1.7 2001/03/08 15:59:06 lazarus
|
||||
IDE bugfixes and viewunit/forms functionality
|
||||
|
||||
Revision 1.6 2001/01/16 23:30:45 lazarus
|
||||
trying to determine what's crashing LAzarus on load.
|
||||
Shane
|
||||
|
Loading…
Reference in New Issue
Block a user