From: <wp...@us...> - 2009-07-07 17:15:52
|
Revision: 803 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=803&view=rev Author: wp2udk Date: 2009-07-07 17:15:39 +0000 (Tue, 07 Jul 2009) Log Message: ----------- Fix for compatibility with < Delphi 2009. Modified Paths: -------------- trunk/Source/Design/InstantModelExpert.pas Modified: trunk/Source/Design/InstantModelExpert.pas =================================================================== --- trunk/Source/Design/InstantModelExpert.pas 2009-07-07 10:59:47 UTC (rev 802) +++ trunk/Source/Design/InstantModelExpert.pas 2009-07-07 17:15:39 UTC (rev 803) @@ -998,9 +998,16 @@ begin Module := Modules[I] as IOTAModule; Editor := FIDEInterface.SourceEditor(Module); + +{$IFDEF D12+} Source := UTF8ToUnicodeString(FIDEInterface.ReadEditorSource(Editor)); Stream := TStringStream.Create(Source, TEncoding.Unicode); - try +{$ELSE} + Source := FIDEInterface.ReadEditorSource(Editor); + Stream := TStringStream.Create(Source); +{$ENDIF} + + try Model.LoadModule(Stream, Editor.FileName); finally Stream.Free; |
From: <dav...@us...> - 2009-08-16 05:23:25
|
Revision: 828 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=828&view=rev Author: davidvtaylor Date: 2009-08-16 05:23:17 +0000 (Sun, 16 Aug 2009) Log Message: ----------- Revise IDE menu handling to make menu entries visible to GExperts and IDE menu customization dialogs - Install custom TAction instances into the IDE ActionList - Add Ctrl-Shift-B shortcut to DatabaseBuilder menu entry - Add logic to disable action event handlers when design package is unloaded Modified Paths: -------------- trunk/Source/Design/InstantModelExpert.pas Modified: trunk/Source/Design/InstantModelExpert.pas =================================================================== --- trunk/Source/Design/InstantModelExpert.pas 2009-08-15 10:38:20 UTC (rev 827) +++ trunk/Source/Design/InstantModelExpert.pas 2009-08-16 05:23:17 UTC (rev 828) @@ -24,7 +24,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Nando Dessena, Steven Mitchell, Brian Andersen + * Nando Dessena, Steven Mitchell, Brian Andersen, David Taylor * * ***** END LICENSE BLOCK ***** *) @@ -41,7 +41,7 @@ uses Classes, ToolsAPI, InstantOTA, Menus, ImgList, ExtCtrls, Forms, InstantDesignResources, InstantModelExplorer, InstantCode, - InstantConsts; + InstantConsts, ActnList; type TIOMetaDataCheckState = (mcNeverChecked, mcCheckError, mcCheckCorrect); @@ -165,10 +165,13 @@ InstantConnectionManager, Dialogs; const + SIOIdeMenuCategory = 'InstantObjects'; SBuilderItemCaption = 'InstantObjects Database &Builder...'; - SBuilderItemName = 'InstantBuilderItem'; + SBuilderItemName = 'InstantBuilderItem'; // Do not localize SExplorerItemCaption = 'InstantObjects &Model Explorer'; - SExplorerItemName = 'InstantExplorerItem'; + SExplorerItemName = 'InstantExplorerItem'; // Do not localize + SExplorerItemActionName = 'InstantExplorerItemAction'; // Do not localize + SBuilderItemActionName = 'InstantBuilderItemAction'; // Do not localize SModelCompiler = 'Model Compiler'; SResFileExt = '.mdr'; UpdateInterval = 500; @@ -186,6 +189,81 @@ InstantCodeReaderIdle := ReaderIdle; end; +function FindOrCreateMenuAction(AName, ACaption: string; + AEventHandler: TNotifyEvent; AImageIndex : integer = -1; + AShortCut: TShortCut = 0): TContainedAction; +var + IdeMainForm: TCustomForm; + IdeActionList: TCustomActionList; + NTAServices: INTAServices; + NewAction: TAction; + I: integer; +begin + // Get the IDE's action list + NTAServices := BorlandIDEServices as INTAServices; + Assert(Assigned(NTAServices)); + IdeActionList := NTAServices.ActionList; + Assert(Assigned(IdeActionList)); + + // Search for an existing IDE action + Result := nil; + for I := 0 to IdeActionList.ActionCount-1 do + begin + if (not SameText(IdeActionList.Actions[I].Name, AName)) then + continue; + Result := IdeActionList.Actions[I]; + // Reconnect/enable the event handler (package reload) + Result.OnExecute := AEventHandler; + if (Result is TCustomAction) then + TCustomAction(Result).Enabled := true; + break; + end; + + // Create a new action if not found + if (not assigned(Result)) then + begin + // Get the IDE's main form + Assert(Assigned(Application)); + IdeMainForm := Application.FindComponent('AppBuilder') as TCustomForm; + + // Create and initialize the action + NewAction := TAction.Create(IdeMainForm); + NewAction.ActionList := IdeActionList; + NewAction.Name := AName; + NewAction.Caption := ACaption; + NewAction.Category := SIOIdeMenuCategory; + NewAction.ImageIndex := AImageIndex; + NewAction.ShortCut := AShortCut; + NewAction.OnExecute := AEventHandler; + Result := NewAction; + end; +end; + +// Searches for an IDE action matching the given name and +// diables its OnExecute event handlers This avoids an AV +// if the expert is unloaded (e.g. during a package rebuild) +procedure DisableMenuAction(AName: string); +var + IdeActionList: TCustomActionList; + NTAServices: INTAServices; + I: integer; +begin + // Get the IDE's action list + NTAServices := BorlandIDEServices as INTAServices; + Assert(Assigned(NTAServices)); + IdeActionList := NTAServices.ActionList; + Assert(Assigned(IdeActionList)); + + // Search for and diable IDE action + for I := 0 to IdeActionList.ActionCount-1 do + begin + if (not SameText(IdeActionList.Actions[I].Name, AName)) then + continue; + IdeActionList.Actions[I].OnExecute := nil; + break; + end; +end; + function FindText(const SubStr, Str: string; var Pos, Line, Column: Integer): Boolean; var @@ -464,13 +542,13 @@ procedure CreateBuilderMenuItem; begin FBuilderItem := TReferencedMenuItem.Create(nil, FBuilderItem); - with FBuilderItem do - begin - Name := SBuilderItemName; - Caption := SBuilderItemCaption; - Action := Explorer.BuildDatabaseAction; - ImageIndex := FToolImageOffset + 1; - end; + FBuilderItem.Name := SBuilderItemName; + FBuilderItem.Action := FindOrCreateMenuAction( + SBuilderItemActionName, + SBuilderItemCaption, + BuilderItemClick, + FToolImageOffset + 1, + Menus.ShortCut(Word('B'), [ssCtrl, ssShift])); end; var @@ -496,14 +574,14 @@ if Assigned(Menu) then begin FExplorerItem := TMenuItem.Create(nil); - with FExplorerItem do - begin - Name := SExplorerItemName; - Caption := SExplorerItemCaption; - ShortCut := Menus.ShortCut(Word('M'), [ssCtrl, ssShift]); - ImageIndex := FToolImageOffset; - OnClick := ExplorerItemClick; - end; + FExplorerItem.Name := SExplorerItemName; + FExplorerItem.Action := FindOrCreateMenuAction( + SExplorerItemActionName, + SExplorerItemCaption, + ExplorerItemClick, + FToolImageOffset, + Menus.ShortCut(Word('M'), [ssCtrl, ssShift])); + {$IFDEF D9+} Item := ItemByName(Menu, 'ViewStructureItem'); {$ELSE} @@ -681,6 +759,8 @@ destructor TInstantModelExpert.Destroy; begin + DisableMenuAction(SBuilderItemActionName); + DisableMenuAction(SExplorerItemActionName); Application.OnIdle := FSaveApplicationIdle; DetachMenus; FUpdateTimer.Free; |
From: <dav...@us...> - 2009-08-17 06:05:12
|
Revision: 835 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=835&view=rev Author: davidvtaylor Date: 2009-08-17 06:05:03 +0000 (Mon, 17 Aug 2009) Log Message: ----------- Fixes and refinements to Model Explorer attribute enhancement and improved IDE menu integration - Fix for problems where IDE menu images are incorrect after packages are reloaded - Redesign of IDE menu Action list image handling to use newer INTAServices.AddMasked method - Remove obsolete menu image handling logic and refactor procedure code into class methods - Add logic to enable/disable the Model Explorer and Database Builder actions based on project state Merged changes to show an attributes pane in Model Explorer (code provided by David MoorHouse) See thread in repository forum: "Enhancement: Show Attributes in the IO Model Explorer" 10-10-2007 - Cleaned up code a bit, adjusted default sizing/positioning and added control size constraints - Fixed an AV when switching between projects in the IDE (caused by model reloading) - Added the new InstantAttributeView frame to the IDE design packages (only D2009 tested. D5,D6,K3 ignored) Modified Paths: -------------- trunk/Source/Design/InstantModelExpert.pas Modified: trunk/Source/Design/InstantModelExpert.pas =================================================================== --- trunk/Source/Design/InstantModelExpert.pas 2009-08-17 05:52:54 UTC (rev 834) +++ trunk/Source/Design/InstantModelExpert.pas 2009-08-17 06:05:03 UTC (rev 835) @@ -77,8 +77,6 @@ FMustUpdateAfterCompile: Boolean; FResourceModule: TInstantDesignResourceModule; FSaveApplicationIdle: TIdleEvent; - FToolImageCount: Integer; - FToolImageOffset: Integer; FUpdateDisableCount: Integer; FUpdateTimer: TTimer; MetaDataCheckState : TIOMetaDataCheckState; @@ -113,8 +111,13 @@ function CreateIDEInterface: TInstantOTAIDEInterface; function CreateUpdateTimer: TTimer; procedure DetachMenus; + procedure DetachMenuActionEvent(AName: string); procedure EnumSources(Modules: TInterfaceList; Enumerator: TSourceEnumerator); + function FindMenuAction(AName: string; out AAction: TContainedAction): boolean; + function FindOrCreateMenuAction(AName, ACaption: string; + AEventHandler: TNotifyEvent; AImageIndex : integer = -1; + AShortCut: TShortCut = 0): TContainedAction; procedure CheckIOMetadataKeyword(const FileName, Source: string); procedure ExplorerItemClick(Sender: TObject); procedure GetModelModules(Modules: TInterfaceList); @@ -132,6 +135,7 @@ procedure ShowExplorer; procedure UpdateModel; procedure UpdateTimerTick(Sender: TObject); + procedure UpdateMenuActions; property CurrentSource: string read GetCurrentSource; property Explorer: TInstantModelExplorerForm read GetExplorer; public @@ -162,17 +166,16 @@ uses SysUtils, TypInfo, InstantDesignUtils, InstantUtils, InstantUnitSelect, - InstantConnectionManager, Dialogs; + InstantConnectionManager, Dialogs, Graphics; const SIOIdeMenuCategory = 'InstantObjects'; SBuilderItemCaption = 'InstantObjects Database &Builder...'; + SExplorerItemCaption = 'InstantObjects &Model Explorer'; SBuilderItemName = 'InstantBuilderItem'; // Do not localize - SExplorerItemCaption = 'InstantObjects &Model Explorer'; SExplorerItemName = 'InstantExplorerItem'; // Do not localize SExplorerItemActionName = 'InstantExplorerItemAction'; // Do not localize SBuilderItemActionName = 'InstantBuilderItemAction'; // Do not localize - SModelCompiler = 'Model Compiler'; SResFileExt = '.mdr'; UpdateInterval = 500; @@ -189,81 +192,6 @@ InstantCodeReaderIdle := ReaderIdle; end; -function FindOrCreateMenuAction(AName, ACaption: string; - AEventHandler: TNotifyEvent; AImageIndex : integer = -1; - AShortCut: TShortCut = 0): TContainedAction; -var - IdeMainForm: TCustomForm; - IdeActionList: TCustomActionList; - NTAServices: INTAServices; - NewAction: TAction; - I: integer; -begin - // Get the IDE's action list - NTAServices := BorlandIDEServices as INTAServices; - Assert(Assigned(NTAServices)); - IdeActionList := NTAServices.ActionList; - Assert(Assigned(IdeActionList)); - - // Search for an existing IDE action - Result := nil; - for I := 0 to IdeActionList.ActionCount-1 do - begin - if (not SameText(IdeActionList.Actions[I].Name, AName)) then - continue; - Result := IdeActionList.Actions[I]; - // Reconnect/enable the event handler (package reload) - Result.OnExecute := AEventHandler; - if (Result is TCustomAction) then - TCustomAction(Result).Enabled := true; - break; - end; - - // Create a new action if not found - if (not assigned(Result)) then - begin - // Get the IDE's main form - Assert(Assigned(Application)); - IdeMainForm := Application.FindComponent('AppBuilder') as TCustomForm; - - // Create and initialize the action - NewAction := TAction.Create(IdeMainForm); - NewAction.ActionList := IdeActionList; - NewAction.Name := AName; - NewAction.Caption := ACaption; - NewAction.Category := SIOIdeMenuCategory; - NewAction.ImageIndex := AImageIndex; - NewAction.ShortCut := AShortCut; - NewAction.OnExecute := AEventHandler; - Result := NewAction; - end; -end; - -// Searches for an IDE action matching the given name and -// diables its OnExecute event handlers This avoids an AV -// if the expert is unloaded (e.g. during a package rebuild) -procedure DisableMenuAction(AName: string); -var - IdeActionList: TCustomActionList; - NTAServices: INTAServices; - I: integer; -begin - // Get the IDE's action list - NTAServices := BorlandIDEServices as INTAServices; - Assert(Assigned(NTAServices)); - IdeActionList := NTAServices.ActionList; - Assert(Assigned(IdeActionList)); - - // Search for and diable IDE action - for I := 0 to IdeActionList.ActionCount-1 do - begin - if (not SameText(IdeActionList.Actions[I].Name, AName)) then - continue; - IdeActionList.Actions[I].OnExecute := nil; - break; - end; -end; - function FindText(const SubStr, Str: string; var Pos, Line, Column: Integer): Boolean; var @@ -546,8 +474,7 @@ FBuilderItem.Action := FindOrCreateMenuAction( SBuilderItemActionName, SBuilderItemCaption, - BuilderItemClick, - FToolImageOffset + 1, + BuilderItemClick, 1, Menus.ShortCut(Word('B'), [ssCtrl, ssShift])); end; @@ -557,18 +484,12 @@ begin if not Assigned(BorlandIDEServices) then Exit; + MainMenu := (BorlandIDEServices as INTAServices40).MainMenu; + if not Assigned(MainMenu) then Exit; - { Add images } - with MainMenu.Images do - begin - FToolImageOffset := Count; - FToolImageCount := FResourceModule.ToolImages.Count; - AddImages(TCustomImageList(FResourceModule.ToolImages)); - end; - { Add 'Model Explorer' to View-menu } Menu := ItemByName(MainMenu.Items, 'ViewsMenu'); if Assigned(Menu) then @@ -578,8 +499,7 @@ FExplorerItem.Action := FindOrCreateMenuAction( SExplorerItemActionName, SExplorerItemCaption, - ExplorerItemClick, - FToolImageOffset, + ExplorerItemClick, 0, Menus.ShortCut(Word('M'), [ssCtrl, ssShift])); {$IFDEF D9+} @@ -658,6 +578,8 @@ UpdateModel; FActiveProjectName := ''; end; + + UpdateMenuActions; end; procedure TInstantModelExpert.CollectModules(Project: IOTAProject; @@ -758,8 +680,6 @@ destructor TInstantModelExpert.Destroy; begin - DisableMenuAction(SBuilderItemActionName); - DisableMenuAction(SExplorerItemActionName); Application.OnIdle := FSaveApplicationIdle; DetachMenus; FUpdateTimer.Free; @@ -770,25 +690,32 @@ end; procedure TInstantModelExpert.DetachMenus; -var - MainMenu: TMainMenu; - I: Integer; begin - if not Application.Terminated then - begin - { Remove images } - MainMenu := (BorlandIDEServices as INTAServices40).MainMenu; - if Assigned(MainMenu) and Assigned(MainMenu.Images) then - with MainMenu.Images do - for I := 0 to Pred(FToolImageCount) do - Delete(FToolImageOffset); - end; + { Unhook action event handlers } + DetachMenuActionEvent(SBuilderItemActionName); + DetachMenuActionEvent(SExplorerItemActionName); { Remove items } FBuilderItem.Free; FExplorerItem.Free; end; +// Searches for an IDE action matching the given name and disables its +// OnExecute event handler and sets Visible to False. This disables +// the action and avoids an AV if the expert is unloaded and the +// event handler becomes invalid (e.g. during a package rebuild) +procedure TInstantModelExpert.DetachMenuActionEvent(AName: string); +var + LAction : TContainedAction; +begin + if (FindMenuAction(AName, LAction)) then + begin + LAction.OnExecute := nil; + if (LAction is TCustomAction) then + TCustomAction(LAction).Visible := False; + end; +end; + procedure TInstantModelExpert.DisableUpdate; begin Inc(FUpdateDisableCount); @@ -855,6 +782,91 @@ LoadModel(Model); end; +// Searches for an IDE action matching the given name +function TInstantModelExpert.FindMenuAction(AName: string; + out AAction: TContainedAction): boolean; +var + IdeActionList: TCustomActionList; + NTAServices: INTAServices; + I: integer; +begin + // Get the IDE's action list + NTAServices := BorlandIDEServices as INTAServices; + Assert(Assigned(NTAServices)); + IdeActionList := NTAServices.ActionList; + Assert(Assigned(IdeActionList)); + + // Search for and diable IDE action + AAction := nil; + + for I := 0 to IdeActionList.ActionCount-1 do + begin + if (not SameText(IdeActionList.Actions[I].Name, AName)) then + continue; + AAction := IdeActionList.Actions[I]; + break; + end; + + Result := assigned(AAction); +end; + +function TInstantModelExpert.FindOrCreateMenuAction(AName, ACaption: string; + AEventHandler: TNotifyEvent; AImageIndex : integer = -1; + AShortCut: TShortCut = 0): TContainedAction; +var + NTAServices: INTAServices; + IdeMainForm: TCustomForm; + IdeActionList: TCustomActionList; + NewAction: TAction; + ActionImage: TBitmap; +begin + if (FindMenuAction(AName, Result)) then + begin + // Enable action and connect the event handler + Result.OnExecute := AEventHandler; + if (Result is TCustomAction) then + begin + TCustomAction(Result).Enabled := true; + TCustomAction(Result).Visible := true; + end; + end else + begin + // Get the IDE's main form + Assert(Assigned(Application)); + IdeMainForm := Application.FindComponent('AppBuilder') as TCustomForm; + + // Get the IDE's action list + NTAServices := (BorlandIDEServices as INTAServices); + Assert(Assigned(NTAServices)); + IdeActionList := NTAServices.ActionList; + Assert(Assigned(IdeActionList)); + + // Create and initialize the action + NewAction := TAction.Create(IdeMainForm); + NewAction.ActionList := IdeActionList; + NewAction.Name := AName; + NewAction.Caption := ACaption; + NewAction.Category := SIOIdeMenuCategory; + NewAction.ShortCut := AShortCut; + NewAction.OnExecute := AEventHandler; + Result := NewAction; + + if (AImageIndex >= 0) and (AImageIndex < FResourceModule.ToolImages.Count) then + begin + ActionImage := TBitmap.Create; + + try + FResourceModule.ToolImages.GetBitmap(AImageIndex,ActionImage); + Assert(Assigned(ActionImage)); + NewAction.ImageIndex := NTAServices.AddMasked(ActionImage, + ActionImage.TransparentColor,AName); + finally + FreeAndNil(ActionImage); + end; + end; + end; +end; + function TInstantModelExpert.GetActiveProject: IOTAProject; begin with FIDEInterface do @@ -1273,6 +1285,25 @@ UpdateModel; end; +procedure TInstantModelExpert.UpdateMenuActions; + + procedure EnableMenuItem(const AMenuItem: TMenuItem; AEnable: boolean); + begin + if (assigned(AMenuItem)) then + if (AMenuItem.Action is TCustomAction) then + TCustomAction(AMenuItem.Action).Enabled := AEnable; + end; + +var + HaveProject: boolean; + HaveModel: boolean; +begin + HaveProject := Assigned(ActiveProject); + HaveModel := Explorer.Model.ModuleCount > 0; + EnableMenuItem(FExplorerItem, HaveProject); + EnableMenuItem(FBuilderItem, HaveModel); +end; + procedure TInstantModelExpert.CheckIOMetadataKeyword(const FileName, Source: string); begin if pos('{ stored', Source) > 0 then |
From: <dav...@us...> - 2012-01-09 23:03:39
|
Revision: 951 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=951&view=rev Author: davidvtaylor Date: 2012-01-09 23:03:33 +0000 (Mon, 09 Jan 2012) Log Message: ----------- * Fix icon transparency problem with Delphi XE and XE2 Modified Paths: -------------- trunk/Source/Design/InstantModelExpert.pas Modified: trunk/Source/Design/InstantModelExpert.pas =================================================================== --- trunk/Source/Design/InstantModelExpert.pas 2012-01-04 22:16:02 UTC (rev 950) +++ trunk/Source/Design/InstantModelExpert.pas 2012-01-09 23:03:33 UTC (rev 951) @@ -856,6 +856,7 @@ ActionImage := TBitmap.Create; try + ActionImage.PixelFormat := pf24bit; FResourceModule.ToolImages.GetBitmap(AImageIndex,ActionImage); Assert(Assigned(ActionImage)); NewAction.ImageIndex := NTAServices.AddMasked(ActionImage, |