unit uDAIDEMenu_laz; {----------------------------------------------------------------------------} { Data Abstract Library - IDE Library } { } { compiler: Delphi 6 and up, Kylix 3 and up } { platform: Win32, Linux } { } { (c)opyright RemObjects Software. all rights reserved. } { } { Using this code requires a valid license of the Data Abstract } { which can be obtained at http://www.remobjects.com. } {----------------------------------------------------------------------------} {$IFDEF MSWINDOWS} {$I ..\DataAbstract.inc} {$ELSE} {$I ../DataAbstract.inc} {$ENDIF} interface uses {$IFDEF MSWINDOWS}Windows,ComObj,{$ENDIF} SysUtils,Classes,Forms,uEWMenuManager_laz, Menus, Graphics; type { TMenuItemInfo } TMenuItemInfo = record Caption, ShortCut : string; ImageIndex:integer; end; const MAX_MENU_ITEM = 0; var MenuItems : array[0..MAX_MENU_ITEM] of TMenuItemInfo = ( //(Caption: '-'; ShortCut: ''; Menu:nil; ImageIndex: -1), (Caption: 'Schema &Modeler'; ShortCut: ''; ImageIndex: 0) ); const mi_SchemaModeler = 0; type { TDAMenuWizard } TDAMenuWizard = class private protected { Misc } procedure CreateMenuItems; procedure LaunchSchemaModeler(Sender : TObject); function FindROMenu : TEWMenu; { IOTAWizard } function GetIDString: string; function GetName: string; public constructor Create; end; function GetSchemaModelerPath: string; function GetDllPath: String; function GetBinDir: string; procedure LaunchSchemaModeler(const aProjectName, someParams : string; aWait: boolean=false); procedure Register; implementation uses Controls, Registry, Dialogs,uEWTools, IDECommands, uRODL, uROIDETools_laz, uRODLGenTools, uROPleaseWaitForm, uDAIDEData, fROAbout, fCustomIDEMessagesForm, uROClasses, uROIDEMenu_laz; var wiz: TDAMenuWizard = nil; procedure Register; begin {$IFDEF MSWINDOWS} // DASM exists only for Windows wiz:= TDAMenuWizard.Create; {$ENDIF} {$IFNDEF FPC} RegisterPackageWizard(TDAMenuWizard.Create); {$ENDIF FPC} end; { TDAMenuWizard } constructor TDAMenuWizard.Create; begin inherited Create; CreateMenuItems; end; function TDAMenuWizard.GetIDString: string; begin Result := '{FE46996E-0AFA-4C8D-AF59-192F1D581FD1}' end; function TDAMenuWizard.GetName: string; begin Result := 'DAMenuWizard'; end; function TDAMenuWizard.FindROMenu: TEWMenu; begin result := gRemObjectsMenu; end; procedure TDAMenuWizard.CreateMenuItems; var romenu : TEWMenu; item : TEWMenuItem; i : Integer; lBitmap : TBitmap; begin romenu := FindROMenu; if (romenu=NIL) then Exit; with TDAIdeData.Create(nil) do try lBitmap := TBitmap.Create(); try for i := 0 to High(MenuItems) do begin item := romenu.CreateMenuItem(MenuItems[i].Caption,-1,[pAny],False); if MenuItems[i].ShortCut <> '' then Item.Command := RegisterIDECommand(RoMenu.CommandCategory, Item.Caption,Item.Caption,TextToIDEShortCut(MenuItems[i].ShortCut)); item.Tag := i; if MenuItems[i].ImageIndex > -1 then begin iml_Actions.GetBitmap(MenuItems[i].ImageIndex,lBitmap); if romenu.SubMenuImages <> nil then item.ImageIndex := romenu.SubMenuImages.AddMasked(lBitmap, clFuchsia); end; case i of mi_SchemaModeler : item.OnClick := LaunchSchemaModeler; else item.OnClick := NIL; end; romenu.Insert(6+i, item); end; finally lBitmap.Free(); end; finally Free(); end; end; function GetDllPath: String; {$IFDEF MSWINDOWS} var TheFileName : array[0..MAX_PATH] of char; {$ENDIF} begin {$IFDEF MSWINDOWS} TheFileName[0]:=#0; FillChar(TheFileName, SizeOf(TheFileName), #0); GetModuleFileName(hInstance, TheFileName, sizeof(TheFileName)); Result := ExtractFilePath(TheFileName); {$ELSE} Result := ''; {$ENDIF} end; function GetBinDir: string; begin // This function strips the "DCU\Dx" part of the path where the BPL is result := ExtractFilePath(GetDllPath); result := IncludeTrailingBackslash(Copy(result,1,Length(result)-7))+'Bin\'; end; function GetSchemaModelerPath: string; var reg: TRegIniFile; begin reg := TRegIniFile.Create('Software\RemObjects\Data Abstract'); try result := reg.ReadString('Schema Modeler', 'FullPath', GetBinDir+'DASchemaModeler.exe'); finally reg.Free; end; end; procedure LaunchSchemaModeler(const aProjectName, someParams : string; aWait: boolean=false); var exename : string; begin exename := GetSchemaModelerPath; if not FileExists(exename) then MessageDlg(Format('Cannot find "%s"', [exename]), mtError, [mbOK], 0) else begin if aWait then begin ExecuteAndWait(exename, someParams); end else begin RO_ShellExecute(0, 'open', PChar(exename), PChar(someParams), PChar(ExtractFilePath(aProjectName)), SW_NORMAL); end; end; end; procedure TDAMenuWizard.LaunchSchemaModeler(Sender: TObject); begin uDAIDEMenu_laz.LaunchSchemaModeler('', '/ns /platform:Delphi'); end; finalization if wiz <> nil then wiz.free; end.