@@ -31,6 +31,7 @@ interface
3131uses
3232 ToolsApi,
3333 Spring.Collections,
34+ DPM.IDE.Types,
3435 DPM.IDE.Logger,
3536 DPM.IDE.ProjectController;
3637
@@ -44,13 +45,13 @@ interface
4445// need the StorageNotifier
4546
4647type
47- TDPMIDENotifier = class (TInterfacedObject, IOTANotifier, IOTAIDENotifier)
48+ TDPMIDENotifier = class (TInterfacedObject, IOTANotifier, IOTAIDENotifier, IDPMIDENotifier )
4849 private
4950 FLogger : IDPMIDELogger;
5051 FLoadingGroup : boolean;
5152 FGroupProjects : IList<string>;
5253 FProjectController : IDPMIDEProjectController;
53-
54+ FProjectNotifiers : IDictionary<string, IOTAProjectNotifier>;
5455 protected
5556 // IOTANotifier
5657 procedure AfterSave ;
@@ -65,6 +66,17 @@ TDPMIDENotifier = class(TInterfacedObject, IOTANotifier, IOTAIDENotifier)
6566 procedure FileNotification (NotifyCode : TOTAFileNotification; const FileName : string; var Cancel : Boolean);
6667
6768 function LoadProjectGroup (const fileName : string) : boolean;
69+
70+ procedure AddProjectNotifier (const fileName : string);
71+ procedure RemoveProjectNotifier (const fileName : string);
72+
73+
74+ // IDPMIDENotifier;
75+ procedure ProjectActivePlatformChanged (const platform : string);
76+ procedure ProjectRenamed (const oldFileName : string; const newFileName : string);
77+ procedure ActiveProjectChanged ;
78+
79+
6880 public
6981 constructor Create(const logger : IDPMIDELogger; const projectController : IDPMIDEProjectController);
7082 destructor Destroy; override;
@@ -77,10 +89,38 @@ implementation
7789 DPM.Core.Utils.Path,
7890 DPM.Core.Utils.System,
7991 DPM.Core.Project.Interfaces,
80- DPM.Core.Project.GroupProjReader;
92+ DPM.Core.Project.GroupProjReader,
93+ DPM.IDE.ProjectNotifier;
8194
8295{ TDPMIDENotifier }
8396
97+ procedure TDPMIDENotifier.ActiveProjectChanged ;
98+ var
99+ activeProject : IOTAProject;
100+ begin
101+ activeProject := (BorlandIDEServices as IOTAModuleServices).GetActiveProject;
102+ if activeProject <> nil then
103+ FProjectController.ActiveProjectChanged(activeProject);
104+
105+ end ;
106+
107+ procedure TDPMIDENotifier.AddProjectNotifier (const fileName: string);
108+ var
109+ notifier : IOTAProjectNotifier;
110+ Module : IOTAModule;
111+ project : IOTAProject;
112+ begin
113+ Module := (BorlandIDEServices as IOTAModuleServices).FindModule(FileName);
114+ if Supports(Module ,IOTAProject, project) then
115+ begin
116+ notifier := TDPMProjectNotifier.Create(FLogger, Self, fileName, project);
117+ FProjectNotifiers.Add(LowerCase(fileName), notifier);
118+
119+ project.AddNotifier(notifier);
120+
121+ end ;
122+ end ;
123+
84124procedure TDPMIDENotifier.AfterCompile (Succeeded : Boolean);
85125begin
86126end ;
@@ -100,9 +140,9 @@ procedure TDPMIDENotifier.BeforeSave;
100140constructor TDPMIDENotifier.Create(const logger : IDPMIDELogger; const projectController : IDPMIDEProjectController);
101141begin
102142 FLogger := logger;
103- FGroupProjects := TCollections.CreateList < string > ;
143+ FGroupProjects := TCollections.CreateList<string> ;
144+ FProjectNotifiers := TCollections.CreateDictionary<string, IOTAProjectNotifier>;
104145 FProjectController := projectController;
105-
106146end ;
107147
108148destructor TDPMIDENotifier.Destroy;
@@ -215,7 +255,6 @@ procedure TDPMIDENotifier.FileNotification(NotifyCode : TOTAFileNotification; co
215255 end ;
216256 ofnFileOpened :
217257 begin
218- // make sire we ignore the groupproj here.
219258 if ext <> ' .dproj' then
220259 exit;
221260 FLogger.Debug(' TDPMIDENotifier ofnFileOpened ' + FileName);
@@ -236,6 +275,7 @@ procedure TDPMIDENotifier.FileNotification(NotifyCode : TOTAFileNotification; co
236275 if not FLoadingGroup then
237276 FProjectController.EndLoading(TProjectMode.pmSingle);
238277 { $IFEND}
278+ AddProjectNotifier(FileName);
239279
240280 end ;
241281 ofnFileClosing :
@@ -246,7 +286,15 @@ procedure TDPMIDENotifier.FileNotification(NotifyCode : TOTAFileNotification; co
246286 FProjectController.ProjectClosed(FileName)
247287 else
248288 FProjectController.ProjectGroupClosed;
289+ RemoveProjectNotifier(FileName);
249290 end ;
291+
292+ ofnActiveProjectChanged :
293+ begin
294+ if not FLoadingGroup then
295+ ActiveProjectChanged;
296+ end ;
297+
250298 { $IF CompilerVersion >= 34.0 }
251299 // 10.4 or later
252300 ofnBeginProjectGroupOpen :
@@ -269,7 +317,7 @@ procedure TDPMIDENotifier.FileNotification(NotifyCode : TOTAFileNotification; co
269317 exit;
270318
271319 FProjectController.EndLoading(TProjectMode.pmGroup);
272- FLoadingGroup := true ;
320+ FLoadingGroup := false ;
273321 end ;
274322 ofnBeginProjectGroupClose :
275323 begin
@@ -295,8 +343,39 @@ procedure TDPMIDENotifier.FileNotification(NotifyCode : TOTAFileNotification; co
295343
296344procedure TDPMIDENotifier.Modified ;
297345begin
346+ TSystemUtils.OutputDebugString(' TDPMIDENotifier.Modified' );
298347 FLogger.Debug(' TDPMIDENotifier.Modified' );
299348end ;
300349
350+ procedure TDPMIDENotifier.ProjectActivePlatformChanged (const platform: string);
351+ begin
352+ TSystemUtils.OutputDebugString(' TDPMIDENotifier.ProjectActivePlatformChanged : ' + platform);
353+ FProjectController.ActivePlatformChanged(platform);
354+ end ;
355+
356+ procedure TDPMIDENotifier.ProjectRenamed (const oldFileName, newFileName: string);
357+ var
358+ key : string;
359+ notifier : IOTAProjectNotifier;
360+ begin
361+ key := LowerCase(oldFileName);
362+ if FProjectNotifiers.TryExtract(key, notifier) then
363+ begin
364+ FProjectNotifiers.Remove(key);
365+ key := LowerCase(newFileName);
366+ FProjectNotifiers.Add(key, notifier);
367+ end ;
368+ end ;
369+
370+ procedure TDPMIDENotifier.RemoveProjectNotifier (const fileName: string);
371+ var
372+ key : string;
373+ begin
374+ key := LowerCase(fileName);
375+ if FProjectNotifiers.ContainsKey(key) then
376+ FProjectNotifiers.Remove(key);
377+
378+ end ;
379+
301380end .
302381
0 commit comments