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
+
8
+ { https://www.youtube.com/@code4delphi }
9
+ { **********************************************************************************}
10
+
1
11
unit IntensiveWizard.MainMenu;
2
12
3
13
interface
@@ -45,6 +55,9 @@ constructor TIntensiveWizardMainMenu.Create;
45
55
begin
46
56
FMainMenu := (BorlandIDEServices as INTAServices).MainMenu;
47
57
58
+ if (FMainMenu = nil )then
59
+ Exit;
60
+
48
61
FMenuItem := TMenuItem.Create(FMainMenu);
49
62
FMenuItem.Name := ' IntensiveWizardMenu1' ;
50
63
FMenuItem.Caption := ' Intensive Delphi' ;
@@ -71,35 +84,68 @@ procedure TIntensiveWizardMainMenu.AddSubMenus(const AName, ACaption: String; AC
71
84
end ;
72
85
73
86
procedure TIntensiveWizardMainMenu.GrupoAtivoOnClick (Sender: TObject);
87
+ var
88
+ LIOTAProjectGroup: IOTAProjectGroup;
74
89
begin
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);
76
95
end ;
77
96
78
97
procedure TIntensiveWizardMainMenu.ProjetoAtivoOnClick (Sender: TObject);
98
+ var
99
+ LIOTAProject: IOTAProject;
79
100
begin
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);
81
106
end ;
82
107
83
108
procedure TIntensiveWizardMainMenu.UnitAtualOnClick (Sender: TObject);
109
+ var
110
+ LIOTAModule: IOTAModule;
84
111
begin
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);
86
117
end ;
87
118
88
119
procedure TIntensiveWizardMainMenu.DocWikiClick (Sender: TObject);
120
+ const
121
+ C_LINK = ' https://docwiki.embarcadero.com/RADStudio/Alexandria/e/index.php?search=' ;
89
122
var
90
- LLink: String;
123
+ LTextoSelecionado: String;
124
+ LIOTAEditView: IOTAEditView;
91
125
begin
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' );
96
129
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);
98
133
end ;
99
134
100
135
procedure TIntensiveWizardMainMenu.BuildClick (Sender: TObject);
136
+ const
137
+ C_NOME_PROJETO_WIZARD = ' IntensiveWizard' ;
138
+ var
139
+ LIOTAProject: IOTAProject;
101
140
begin
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);
103
149
end ;
104
150
105
151
destructor TIntensiveWizardMainMenu.Destroy;
0 commit comments