1+ { **********************************************************************************}
2+ { Criador: César Cardoso - Code4Delphi }
3+ { Projeto criado durante palestra no Intensive Delphi 2023 }
4+ { Tema: Criação de Wizards e Experts para o Delphi utilizando a OTA Open Tools API }
5+ { }
6+ { https://github.com/Code4Delphi }
7+ { contato@code4delphi.com.br }
8+ { https://www.youtube.com/@code4delphi }
9+ { **********************************************************************************}
10+
111unit IntensiveWizard.MainMenu;
212
313interface
@@ -45,6 +55,9 @@ constructor TIntensiveWizardMainMenu.Create;
4555begin
4656 FMainMenu := (BorlandIDEServices as INTAServices).MainMenu;
4757
58+ if (FMainMenu = nil )then
59+ Exit;
60+
4861 FMenuItem := TMenuItem.Create(FMainMenu);
4962 FMenuItem.Name := ' IntensiveWizardMenu1' ;
5063 FMenuItem.Caption := ' Intensive Delphi' ;
@@ -71,35 +84,68 @@ procedure TIntensiveWizardMainMenu.AddSubMenus(const AName, ACaption: String; AC
7184end ;
7285
7386procedure TIntensiveWizardMainMenu.GrupoAtivoOnClick (Sender: TObject);
87+ var
88+ LIOTAProjectGroup: IOTAProjectGroup;
7489begin
75- ShowMessage((BorlandIDEServices as IOTAModuleServices).MainProjectGroup.FileName);
90+ LIOTAProjectGroup := (BorlandIDEServices as IOTAModuleServices).MainProjectGroup;
91+ if (LIOTAProjectGroup = nil )then
92+ raise Exception.Create(' Nenhum project group selecionado no momento' );
93+
94+ ShowMessage(LIOTAProjectGroup.FileName);
7695end ;
7796
7897procedure TIntensiveWizardMainMenu.ProjetoAtivoOnClick (Sender: TObject);
98+ var
99+ LIOTAProject: IOTAProject;
79100begin
80- ShowMessage(GetActiveProject.FileName);
101+ LIOTAProject := GetActiveProject;
102+ if (LIOTAProject = nil )then
103+ raise Exception.Create(' Nenhum projeto selecionado no momento' );
104+
105+ ShowMessage(LIOTAProject.FileName);
81106end ;
82107
83108procedure TIntensiveWizardMainMenu.UnitAtualOnClick (Sender: TObject);
109+ var
110+ LIOTAModule: IOTAModule;
84111begin
85- ShowMessage((BorlandIDEServices as IOTAModuleServices).CurrentModule.FileName);
112+ LIOTAModule := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
113+ if (LIOTAModule = nil )then
114+ raise Exception.Create(' Nenhuma unit selecionada no momento' );
115+
116+ ShowMessage(LIOTAModule.FileName);
86117end ;
87118
88119procedure TIntensiveWizardMainMenu.DocWikiClick (Sender: TObject);
120+ const
121+ C_LINK = ' https://docwiki.embarcadero.com/RADStudio/Alexandria/e/index.php?search=' ;
89122var
90- LLink: String;
123+ LTextoSelecionado: String;
124+ LIOTAEditView: IOTAEditView;
91125begin
92- LLink := ' https://docwiki.embarcadero.com/RADStudio/Alexandria/e/index.php?search=' +
93- (BorlandIDEServices as IOTAEditorServices).TopView.GetBlock.Text;
94-
95- ShowMessage(' Texto selecionado: ' + sLineBreak + (BorlandIDEServices as IOTAEditorServices).TopView.GetBlock.Text);
126+ LIOTAEditView := (BorlandIDEServices as IOTAEditorServices).TopView;
127+ if (LIOTAEditView = nil )then
128+ raise Exception.Create(' Não foi possível acessar o recurso para captura do texto selecionado' );
96129
97- ShellExecute(0 , nil , PChar(LLink), ' ' , ' ' , SW_ShowNormal);
130+ LTextoSelecionado := LIOTAEditView.GetBlock.Text;
131+ ShowMessage(' Texto selecionado: ' + sLineBreak + LIOTAEditView.GetBlock.Text);
132+ ShellExecute(0 , nil , PChar(C_LINK + LTextoSelecionado), ' ' , ' ' , SW_ShowNormal);
98133end ;
99134
100135procedure TIntensiveWizardMainMenu.BuildClick (Sender: TObject);
136+ const
137+ C_NOME_PROJETO_WIZARD = ' IntensiveWizard' ;
138+ var
139+ LIOTAProject: IOTAProject;
101140begin
102- GetActiveProject.ProjectBuilder.BuildProject(cmOTABuild, True, True);
141+ LIOTAProject := GetActiveProject;
142+ if (LIOTAProject = nil )then
143+ raise Exception.Create(' Nenhum projeto selecionado no momento' );
144+
145+ if (ChangeFileExt(ExtractFileName(LIOTAProject.FileName), EmptyStr) = C_NOME_PROJETO_WIZARD)then
146+ raise Exception.Create(' Não é possível realizar o build neste projeto: ' + C_NOME_PROJETO_WIZARD);
147+
148+ LIOTAProject.ProjectBuilder.BuildProject(cmOTABuild, True, True);
103149end ;
104150
105151destructor TIntensiveWizardMainMenu.Destroy;
0 commit comments