⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttoolsapihelperunit.pas

📁 CVS IDE plugin for Borland Delphi this is a good program,i like this kind of practise
💻 PAS
📖 第 1 页 / 共 2 页
字号:

function TToolsApiHelper.GetCurrentProjectGroupFiles(filelist: TStrings;
  fLowerCase: boolean): boolean;
var
  CurrentProjectGroup: IOTAProjectGroup;
  i: integer;
begin
  result := false;
  CurrentProjectGroup := GetCurrentProjectGroup;
  if assigned(CurrentProjectGroup) then
  begin
    for I := 0 to CurrentProjectGroup.ProjectCount - 1 do
    begin
      GetProjectFiles(CurrentProjectGroup.Projects[i], filelist, fLowerCase);
    end;
    result := true;
  end;
end;

function TToolsApiHelper.GetCurrentProjectFiles(filelist: TStrings;
  fLowerCase: boolean): boolean;
begin
  result := GetProjectFiles(GetCurrentProject, filelist, fLowerCase);
end;

function TToolsApiHelper.GetProjectFiles(aProject: IOTAProject; filelist: TStrings; fLowerCase: boolean = false): boolean;
var
  modinfo: IOTAModuleInfo;
  editor: IOTAEditor;
  count, i: integer;
  basefile, projectname, tmp: string;
begin
//  DebugStrF('TToolsApiHelper.GetProjectFiles(%s)', [aProject.FileName]);
  if assigned(aproject) then
  begin
    // get project files
    count := aproject.GetModuleFileCount;
    for i := 0 to count - 1 do
    begin
      try
        editor := aproject.GetModuleFileEditor(i);
        if assigned(editor) then
        begin
          AddToFileList(filelist, fLowerCase, editor.FileName);
        end;
      except
      end;
    end;

//guess what other files belong to that project');
    projectname := aproject.FileName;
    AddToFileList(filelist, fLowerCase, projectname);
    AddToFileList(filelist, fLowerCase, ChangeFileExt(projectname, '.todo'));
    AddToFileList(filelist, fLowerCase, ChangeFileExt(projectname, '.cfg'));
    AddToFileList(filelist, fLowerCase, ChangeFileExt(projectname, '.dof'));
// get modules of that project');
    count := aproject.GetModuleCount;
    for i := 0 to count - 1 do
    begin
      modinfo := aproject.GetModule(i);
      if assigned(modinfo) then
      begin
        basefile := modinfo.FileName;
        if (basefile <> '') then
        begin
          AddToFileList(filelist, fLowerCase, basefile);
// guess what files belong to that module;
//          DebugStrF('modinfo.ModuleType=%d', [modinfo.ModuleType]);
(*
          ModuleType seems to be 13 ! for CBuilder files ???!?!
          for the time being I check for all files regardless of moduletype !
*)
          AddToFileList(filelist, fLowerCase, ChangeFileExt(basefile, '.dfm'));
          tmp := LowerCase(ExtractFileExt(basefile));
          if (tmp = '.cpp') or (tmp = '.c') then
            AddToFileList(filelist, fLowerCase, ChangeFileExt(basefile, '.h'));

//          case modinfo.ModuleType of
//            utForm,
//              utDataModule:
//              begin
//                AddToFileList(filelist, fLowerCase, ChangeFileExt(basefile,
//                  '.dfm'));
//                tmp := LowerCase(ExtractFileExt(basefile));
//                if (tmp = '.cpp') or (tmp = '.c') then
//                  AddToFileList(filelist, fLowerCase, ChangeFileExt(basefile,
//                    '.h'));
//              end;
//            utUnit:
//              begin
//                tmp := LowerCase(ExtractFileExt(basefile));
//                if (tmp = '.cpp') or (tmp = '.c') then
//                  AddToFileList(filelist, fLowerCase, ChangeFileExt(basefile,
//                    'h'));
//              end;
//          end;
        end;
      end;
    end;
    result := true;
  end
  else
    result := false;
end;

procedure TToolsApiHelper.InitMessages;
var
  msgserv: IOTAMessageServices;
  comp: TComponent;
  action: TAction;
begin
  msgserv := BorlandIDEServices as IOTAMessageServices;
  if assigned(msgserv) then
  begin
    msgserv.ClearAllMessages;
    // taken from the Open Tools API Browser by Lucian Wischik
    comp := Application.FindComponent('EditorActionLists');
    if assigned(comp) then
    begin
      comp := comp.FindComponent('ecMessageView');
      action := comp as TAction;
      if assigned(action) then
        action.Execute;
    end;
  end;

end;

function TToolsApiHelper.OpenFile(filename: string): boolean;
var
  actserv: IOTAActionServices;
begin
  actserv := BorlandIDEServices as IOTAActionServices;
  if assigned(actserv) then
  begin
    FlushCache;
    result := actserv.OpenFile(filename);
  end
  else
    result := false;
end;

function TToolsApiHelper.OpenFileInEditor(filename: string;
  lineno: integer): boolean;
var
  module: IOTAModule;
  editor: IOTAEditor;
  i, filecount: integer;
begin
//  result := false;
  // find a method for editing conflict files...
  // for a .CPP or a .PAS file, the IDE opens the module instead of the file
  // this causes problems if the .DFM also contains a conflict, because the
  // IDE cannot load the file
  // so, currently, just open the file in notepad...
  CloseFile(filename);
  // open the file in notepad...
  ShellExec('notepad.exe ' + GetOptQuotedString(filename));
  result := OpenFile(filename);
  if (result) then
  begin
    module := GetModuleForFile(filename);
    if assigned(module) then
    begin
      filecount := module.GetModuleFileCount;
      for i := 0 to filecount - 1 do
      begin
        editor := module.GetModuleFileEditor(i);
        if assigned(editor) then
        begin
          if LowerCase(editor.FileName) = LowerCase(filename) then
          begin
            editor.Show;
            if (lineno > 0) then
            begin
            // show first conflict marker in editor
            end;
          end;
        end;
      end;
    end;
  end;
end;

function TToolsApiHelper.OpenProject(projectfile: string): boolean;
var
  actserv: IOTAActionServices;
begin
  actserv := BorlandIDEServices as IOTAActionServices;
  if assigned(actserv) then
  begin
    FlushCache;
    result := actserv.OpenProject(projectfile, false);
  end
  else
    result := false;
end;

function TToolsApiHelper.ReloadFile(filename: string): boolean;
var
  actserv: IOTAActionServices;
begin
  actserv := BorlandIDEServices as IOTAActionServices;
  if assigned(actserv) then
  begin
    FlushCache;
    result := actserv.ReloadFile(filename);
  end
  else
    result := false;
end;

function TToolsApiHelper.SaveAll: boolean;
var
  modserv: IOTAModuleServices;
begin
  modserv := BorlandIDEServices as IOTAModuleServices;
  if assigned(modserv) then
  begin
    FlushCache;
    result := modserv.SaveAll;
  end
  else
    result := false;
end;

function TToolsApiHelper.GetCurrentModule: IOTAModule;
var
  ModuleServices: IOTAModuleServices;
begin
  ModuleServices := BorlandIDEServices as IOTAModuleServices;
  Assert(Assigned(ModuleServices));
  Result := ModuleServices.CurrentModule;
end;

function TToolsApiHelper.GetCurrentProjectGroup: IOTAProjectGroup;
var
  IModuleServices: IOTAModuleServices;
  IModule: IOTAModule;
  i: Integer;
begin
  Assert(Assigned(BorlandIDEServices));

  IModuleServices := BorlandIDEServices as IOTAModuleServices;
  Assert(Assigned(IModuleServices));

  Result := nil;
  for i := 0 to IModuleServices.ModuleCount - 1 do
  begin
    IModule := IModuleServices.Modules[i];
    if Supports(IModule, IOTAProjectGroup, Result) then
      Break;
  end;
end;

function TToolsApiHelper.HasProjectGroup: boolean;
begin
  result := GetCurrentProjectGroup <> nil;
end;

function TToolsApiHelper.GetCurrentProject: IOTAProject;
var
  IProjectGroup: IOTAProjectGroup;
  IModuleServices: IOTAModuleServices;
  IModule: IOTAModule;
  i: Integer;
begin
  Result := nil;

  IProjectGroup := GetCurrentProjectGroup;
  if not Assigned(IProjectGroup) then
  begin
    Assert(Assigned(BorlandIDEServices));
    IModuleServices := BorlandIDEServices as IOTAModuleServices;
    Assert(Assigned(IModuleServices));

    for i := 0 to IModuleServices.ModuleCount - 1 do
    begin
      IModule := IModuleServices.Modules[i];
      if Supports(IModule, IOTAProject, Result) then
        Break;
    end;
  end;

  try
    // This raises exceptions in D5 with .bat projects active
    if Assigned(IProjectGroup) and (not Assigned(Result)) then
      Result := IProjectGroup.ActiveProject;
  except
    Result := nil;
  end;
end;

begin
  ToolsApiHelper := nil;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -