From 4c7fde32e9ead935e8100ce576ad43b203782d5e Mon Sep 17 00:00:00 2001 From: juha Date: Mon, 7 Sep 2020 09:27:58 +0000 Subject: [PATCH] Jedi Code Format: Delete unused units. git-svn-id: trunk@63873 - --- .gitattributes | 2 - components/jcf2/IdePlugin/JcfIdeMain.pas | 382 ------------------- components/jcf2/IdePlugin/JcfIdeRegister.pas | 332 ---------------- 3 files changed, 716 deletions(-) delete mode 100644 components/jcf2/IdePlugin/JcfIdeMain.pas delete mode 100644 components/jcf2/IdePlugin/JcfIdeRegister.pas diff --git a/.gitattributes b/.gitattributes index c59dc24ef3..53f4fbb196 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2279,8 +2279,6 @@ components/jcf2/Contributions/StyleEditor/JCFStyle.bdsproj svneol=native#text/pl components/jcf2/Contributions/StyleEditor/JCFStyle.cfg svneol=native#text/plain components/jcf2/Contributions/StyleEditor/JCFStyle.res -text components/jcf2/Contributions/StyleEditor/Readme.txt svneol=native#text/plain -components/jcf2/IdePlugin/JcfIdeMain.pas svneol=native#text/pascal -components/jcf2/IdePlugin/JcfIdeRegister.pas svneol=native#text/pascal components/jcf2/IdePlugin/lazarus/Makefile svneol=native#text/plain components/jcf2/IdePlugin/lazarus/Makefile.compiled svneol=native#text/plain components/jcf2/IdePlugin/lazarus/Makefile.fpc svneol=native#text/plain diff --git a/components/jcf2/IdePlugin/JcfIdeMain.pas b/components/jcf2/IdePlugin/JcfIdeMain.pas deleted file mode 100644 index e53062ac27..0000000000 --- a/components/jcf2/IdePlugin/JcfIdeMain.pas +++ /dev/null @@ -1,382 +0,0 @@ -unit JcfIdeMain; - -{ AFS 7 Jan 2K - JEDI Code Format IDE plugin main class - - global object that implements the callbacks from the menu items } - - -{(*} -(*------------------------------------------------------------------------------ - Delphi Code formatter source code - -The Original Code is JcfIdeMain, released May 2003. -The Initial Developer of the Original Code is Anthony Steele. -Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele. -All Rights Reserved. -Contributor(s): Anthony Steele. - -The contents of this file are subject to the Mozilla Public License Version 1.1 -(the "License"). you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://www.mozilla.org/NPL/ - -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. -See the License for the specific language governing rights and limitations -under the License. - -Alternatively, the contents of this file may be used under the terms of -the GNU General Public License Version 2 or later (the "GPL") -See http://www.gnu.org/licenses/gpl.html -------------------------------------------------------------------------------*) -{*)} - -{$I JcfGlobal.inc} - -interface - -uses - { delphi }Windows, SysUtils, Classes, - { delphi design time } - ToolsAPI, - { local} - EditorConverter, FileConverter, ConvertTypes; - -type - TJcfIdeMain = class(TObject) - private - fcEditorConverter: TEditorConverter; - fcFileConverter: TFileConverter; - - procedure MakeEditorConverter; - - procedure LogIDEMessage(const psFile, psMessage: string; - const peMessageType: TStatusMessageType; - const piY, piX: integer); - procedure FormatFile(const psFileName: string); - - procedure ClearToolMessages; - procedure ConvertEditor(const pciEditor: IOTASourceEditor); - - - protected - public - constructor Create; - destructor Destroy; override; - - procedure ShortcutKeyCallback(const Context: IOTAKeyContext; - KeyCode: TShortcut; var BindingResult: TKeyBindingResult); - - procedure DoFormatCurrentIDEWindow(Sender: TObject); - procedure DoFormatProject(Sender: TObject); - procedure DoFormatOpen(Sender: TObject); - procedure DoRegistrySettings(Sender: TObject); - procedure DoFormatSettings(Sender: TObject); - procedure DoAbout(Sender: TObject); - end; - - -implementation - -uses - { delphi } - Menus, Dialogs, Controls, - { local } - JcfStringUtils, - fAllSettings, fAbout, JcfRegistrySettings, fRegistrySettings; - - -function FileIsAllowedType(const psFileName: string): boolean; -const - ALLOWED_FILE_TYPES: array[1..3] of string = ('.pas', '.dpr', '.dpk'); -begin - Result := StrIsOneOf(StrRight(psFileName, 4), ALLOWED_FILE_TYPES); -end; - - -{ the function GetCurrentProject is from Erik's OpenTools API FAQ and Resources - http://www.gexperts.org/opentools/ -} -// Modified from code posted by Ray Lischner (www.tempest-sw.com) -function GetCurrentProject: IOTAProject; -var - Services: IOTAModuleServices; - Module: IOTAModule; - Project: IOTAProject; - ProjectGroup: IOTAProjectGroup; - MultipleProjects: boolean; - I: integer; -begin - Result := nil; - MultipleProjects := False; - Services := BorlandIDEServices as IOTAModuleServices; - for I := 0 to Services.ModuleCount - 1 do - begin - Module := Services.Modules[I]; - if Module.QueryInterface(IOTAProjectGroup, ProjectGroup) = S_OK then - begin - Result := ProjectGroup.ActiveProject; - Exit; - end - else if Module.QueryInterface(IOTAProject, Project) = S_OK then - begin - if Result = nil then - // Found the first project, so save it - Result := Project - else - MultipleProjects := True; - // It doesn't look good, but keep searching for a project group - end; - end; - if MultipleProjects then - Result := nil; -end; - - -constructor TJcfIdeMain.Create; -begin - inherited; - { both of these are created on demand } - fcEditorConverter := nil; - fcFileConverter := nil; -end; - -destructor TJcfIdeMain.Destroy; -begin - FreeAndNil(fcEditorConverter); - FreeAndNil(fcFileConverter); - inherited; -end; - -procedure TJcfIdeMain.DoFormatCurrentIDEWindow(Sender: TObject); -var - hRes: HResult; - lciEditManager: IOTAEditorServices; - lciEditor: IOTASourceEditor; -begin - // get the current editor window - hRes := BorlandIDEServices.QueryInterface(IOTAEditorServices, lciEditManager); - if hRes <> S_OK then - exit; - if lciEditManager = nil then - exit; - - lciEditor := lciEditManager.TopBuffer; - if (lciEditor = nil) or (lciEditor.EditViewCount = 0) then - begin - LogIdeMessage('', 'No current window', mtInputError, -1, -1); - exit; - end; - - ConvertEditor(lciEditor); -end; - -procedure TJcfIdeMain.ConvertEditor(const pciEditor: IOTASourceEditor); -begin - MakeEditorConverter; - - ClearToolMessages; - fcEditorConverter.Clear; - fcEditorConverter.BeforeConvert; - fcEditorConverter.Convert(pciEditor); - fcEditorConverter.AfterConvert; -end; - -procedure TJcfIdeMain.DoFormatProject(Sender: TObject); -var - lciProject: IOTAProject; - lciModule: IOTAModuleInfo; - {$IFDEF VER170} - lciAction: IOTAActionServices; - {$ENDIF} - liLoop: integer; - lsMsg: string; -begin - {$IFDEF VER170} - lciAction := BorlandIDEServices as IOTAActionServices; - {$ENDIF} - lciProject := GetCurrentProject; - if lciProject = nil then - exit; - - lsMsg := 'JEDI Code Format of ' + lciProject.FileName + NativeLineBreak + - 'Are you sure that you want to format all ' + IntToStr(lciProject.GetModuleCount) + - ' files in the project.'; - - if MessageDlg(lsMsg, mtConfirmation, [mbYes, mbNo], 0) <> mrYes then - exit; - - ClearToolMessages; - - { loop through all modules in the project } - for liLoop := 0 to lciProject.GetModuleCount - 1 do - begin - lciModule := lciProject.GetModule(liLoop); - FormatFile(lciModule.FileName); - {$IFDEF VER170} - lciAction.ReloadFile(lciModule.FileName); - {$ENDIF} - end; -end; - -procedure TJcfIdeMain.DoFormatOpen(Sender: TObject); -var - hRes: HResult; - lciEditManager: IOTAEditorServices; - lciIterateBuffers: IOTAEditBufferIterator; - lciEditor: IOTASourceEditor; - liLoop: integer; -begin - hRes := BorlandIDEServices.QueryInterface(IOTAEditorServices, lciEditManager); - if hRes <> S_OK then - exit; - if lciEditManager = nil then - exit; - - MakeEditorConverter; - - lciIterateBuffers := nil; - lciEditManager.GetEditBufferIterator(lciIterateBuffers); - if lciIterateBuffers = nil then - exit; - - ClearToolMessages; - fcEditorConverter.BeforeConvert; - - for liLoop := 0 to lciIterateBuffers.Count - 1 do - begin - lciEditor := lciIterateBuffers.EditBuffers[liLoop]; - - // check that it's open, and a .pas or .dpr - if (lciEditor <> nil) and (lciEditor.EditViewCount > 0) and - (FileIsAllowedType(lciEditor.FileName)) then - begin - fcEditorConverter.Convert(lciEditor); - end; - end; - - fcEditorConverter.AfterConvert; -end; - - -procedure TJcfIdeMain.FormatFile(const psFileName: string); -begin - if not FileExists(psFileName) then - exit; - - // check that it's a .pas or .dpr - if not FileIsAllowedType(psFileName) then - exit; - - if fcFileConverter = nil then - begin - fcFileConverter := TFileConverter.Create; - fcFileConverter.OnStatusMessage := LogIDEMessage; - end; - - fcFileConverter.ProcessFile(psFileName); -end; - -procedure TJcfIdeMain.DoFormatSettings(Sender: TObject); -var - lfAllSettings: TFormAllSettings; -begin - if not GetRegSettings.HasRead then - GetRegSettings.ReadAll; - - lfAllSettings := TFormAllSettings.Create(nil); - try - lfAllSettings.Execute; - finally - lfAllSettings.Release; - end; -end; - -procedure TJcfIdeMain.DoAbout(Sender: TObject); -var - lcAbout: TfrmAboutBox; -begin - lcAbout := TfrmAboutBox.Create(nil); - try - lcAbout.ShowModal; - finally - lcAbout.Free; - end; -end; - -procedure TJcfIdeMain.DoRegistrySettings(Sender: TObject); -var - lcAbout: TfmRegistrySettings; -begin - if not GetRegSettings.HasRead then - GetRegSettings.ReadAll; - - lcAbout := TfmRegistrySettings.Create(nil); - try - lcAbout.Execute; - finally - lcAbout.Free; - end; -end; - -procedure TJcfIdeMain.ShortcutKeyCallback(const Context: IOTAKeyContext; - KeyCode: TShortcut; var BindingResult: TKeyBindingResult); -var - liShortcut: TShortCut; -begin - liShortcut := Shortcut(Ord('K'), [ssCtrl]); - - if KeyCode = liShortcut then - DoFormatCurrentIDEWindow(nil); -end; - -procedure TJcfIdeMain.LogIDEMessage(const psFile, psMessage: string; - const peMessageType: TStatusMessageType; - const piY, piX: integer); -var - lciMessages: IOTAMessageServices40; - hRes: HResult; -begin - { no empty lines in this log } - if psMessage = '' then - exit; - - hRes := BorlandIDEServices.QueryInterface(IOTAMessageServices40, lciMessages); - if hRes <> S_OK then - exit; - if lciMessages = nil then - exit; - - if (piY >= 0) and (piX >= 0) then - lciMessages.AddToolMessage(psFile, psMessage, 'JCF', piY, piX) - else - lciMessages.AddTitleMessage('JCF: ' + psFile + ' ' + psMessage); - -end; - -procedure TJcfIdeMain.MakeEditorConverter; -begin - if fcEditorConverter = nil then - begin - fcEditorConverter := TEditorConverter.Create; - fcEditorConverter.OnStatusMessage := LogIDEMessage; - end; - - Assert(fcEditorConverter <> nil); -end; - -procedure TJcfIdeMain.ClearToolMessages; -var - lciMessages: IOTAMessageServices40; - hRes: HResult; -begin - hRes := BorlandIDEServices.QueryInterface(IOTAMessageServices40, lciMessages); - if hRes <> S_OK then - exit; - if lciMessages = nil then - exit; - - lciMessages.ClearToolMessages; -end; - -end. diff --git a/components/jcf2/IdePlugin/JcfIdeRegister.pas b/components/jcf2/IdePlugin/JcfIdeRegister.pas deleted file mode 100644 index 139ce29aaf..0000000000 --- a/components/jcf2/IdePlugin/JcfIdeRegister.pas +++ /dev/null @@ -1,332 +0,0 @@ -unit JcfIdeRegister; - -{ AFS 7 Jan 2K - JEDI Code Format IDE plugin registration } - -{(*} -(*------------------------------------------------------------------------------ - Delphi Code formatter source code - -The Original Code is JcfIdeRegister, released May 2003. -The Initial Developer of the Original Code is Anthony Steele. -Portions created by Anthony Steele are Copyright (C) 1999-2000 Anthony Steele. -All Rights Reserved. -Contributor(s): Anthony Steele, Juergen Kehrel - -The contents of this file are subject to the Mozilla Public License Version 1.1 -(the "License"). you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://www.mozilla.org/NPL/ - -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. -See the License for the specific language governing rights and limitations -under the License. - -Alternatively, the contents of this file may be used under the terms of -the GNU General Public License Version 2 or later (the "GPL") -See http://www.gnu.org/licenses/gpl.html -------------------------------------------------------------------------------*) -{*)} - -{$I JcfGlobal.inc} - -interface - -uses - { delphi } - Windows, SysUtils, Classes, ToolsAPI; - - -procedure Register; - -implementation - -uses - { delphi } - Menus, ActnList, - { local } - JcfIdeMain, Delay; - -const - NAME_MENU_TOOLS = 'ToolsMenu'; - FORMAT_MENU_NAME = 'JEDI Code &Format'; - FORMAT_CURRENT_NAME = '&Current Editor Window'; - FORMAT_PROJECT_NAME = '&All Files in Project'; - FORMAT_OPEN_NAME = 'All &Open Windows'; - FORMAT_REG_SETTINGS_MENU_NAME = '&Registry Settings'; - FORMAT_SETTINGS_MENU_NAME = '&Format Settings'; - FORMAT_ABOUT_MENU_NAME = '&About'; - -{ find the TMenuItem for the IDE main menu tools } -function GetToolsMenu: TMenuItem; -var - hRes: HResult; - lciMenuServices: INTAServices40; - lcMainMenu: TMenu; - lcTestMenu: TMenuItem; - liLoop: integer; -begin - Result := nil; - - { get the menu services } - hRes := BorlandIDEServices.QueryInterface(INTAServices40, lciMenuServices); - if hRes <> S_OK then - exit; - if lciMenuServices = nil then - exit; - - { get the main menu } - lcMainMenu := lciMenuServices.MainMenu; - - { get the tools menu - find it by looking for the control name - since this stays the same even if the display text - has been localised/translated } - for liLoop := 0 to lcMainMenu.Items.Count - 1 do - begin - lcTestMenu := lcMainMenu.Items[liLoop]; - if CompareText(lcTestMenu.Name, NAME_MENU_TOOLS) = 0 then - begin - result := lcTestMenu; - break; - end; - end; -end; - -{ the object that does all the work - - created the first time that a JCF menu item is selected } -var - lcJCFIDE: TJcfIdeMain; - { object to delay registration } - lcDelayedRegister: TDelay; - { count the number of times that the plugin menus have been attempted } - miMenuTries: integer = 0; - -const - MAX_TRIES = 100; - -{ called from Finalization } -procedure RemoveMenuItems; -var - fcMainMenu: TMenuItem; - - procedure RemoveMenuItem(const psName: string); - var - lcItem: TMenuItem; - begin - Assert(psName <> ''); - Assert(fcMainMenu <> nil); - - lcItem := fcMainMenu.Find(psName); - if lcItem <> nil then - fcMainMenu.Remove(lcItem); - end; - -var - fcToolsMenu: TMenuItem; -begin - { remove any existant menu items - - this causes crashes of not done right } - fcToolsMenu := GetToolsMenu; - if fcToolsMenu = nil then - exit; - - fcMainMenu := fcToolsMenu.Find(FORMAT_MENU_NAME); - - if fcMainMenu <> nil then - begin - RemoveMenuItem(FORMAT_CURRENT_NAME); - RemoveMenuItem(FORMAT_PROJECT_NAME); - RemoveMenuItem(FORMAT_OPEN_NAME); - RemoveMenuItem(FORMAT_SETTINGS_MENU_NAME); - - fcToolsMenu.Remove(fcMainMenu); - end; - - FreeAndNil(fcMainMenu); -end; - -function IDEActionList: TCustomActionList; -var - NTAServices: INTAServices; -begin - NTAServices := BorlandIDEServices as INTAServices; - Result := NTAServices.ActionList; -end; - -procedure AddMenuItems(var pbDoAgain: boolean); -var - fcMainMenu: TMenuItem; - - procedure AddMenuItem(const psName: string; const pcHandler: TNotifyEvent; - const piShortCutKey: TShortCut = 0); - var - lcItem: TMenuItem; - lcAction: TAction; - begin - Assert(psName <> ''); - // must have a callback unless it's a seperator line - Assert(Assigned(pcHandler) or (psName = '-')); - - lcItem := TMenuItem.Create(fcMainMenu); - Assert(lcItem <> nil); - - if psName = '-' then - begin - lcItem.Caption := psName; - lcItem.OnClick := pcHandler; - end - else - begin - lcAction := TAction.Create(fcMainMenu); - lcAction.Category := StripHotKey(FORMAT_MENU_NAME); - lcAction.Name := 'jcf' + StringReplace(StripHotKey(psName), ' ', '', [rfReplaceAll]) + 'Action'; - lcAction.Caption := psName; - lcAction.OnExecute := pcHandler; - lcAction.ActionList := IDEactionList; - if piShortCutKey <> 0 then - lcAction.ShortCut := piShortCutKey; - - lcItem.Action := lcAction; - end; - - Assert(fcMainMenu <> nil); - fcMainMenu.Add(lcItem); - end; - -var - fcToolsMenu: TMenuItem; - liLoop: integer; -begin - { give up after trying several times } - if miMenuTries >= MAX_TRIES then - exit; - - Inc(miMenuTries); - - { this doesn't work during program startup?!? } - fcToolsMenu := GetToolsMenu; - if fcToolsMenu = nil then - exit; - - { make these menu items in the Register proc, & - free them in finalization } - fcMainMenu := TMenuItem.Create(fcToolsMenu); - fcMainMenu.Caption := FORMAT_MENU_NAME; - - // find first separator jbk - for liLoop := 0 to fcToolsMenu.Count - 1 do - begin - if fcToolsMenu.Items[liLoop].IsLine then - begin - fcToolsMenu.Insert(liLoop, fcMainMenu); - Break; - end; - end; - - // is it in there ? - fcMainMenu := fcToolsMenu.Find(FORMAT_MENU_NAME); - - if (fcMainMenu <> nil) then - begin - // it worked. Now add menu subitems - - AddMenuItem(FORMAT_CURRENT_NAME, lcJCFIDE.DoFormatCurrentIDEWindow, - ShortCut((Ord('F')), [ssCtrl, ssAlt])); - - AddMenuItem(FORMAT_PROJECT_NAME, lcJCFIDE.DoFormatProject); - AddMenuItem(FORMAT_OPEN_NAME, lcJCFIDE.DoFormatOpen); - - AddMenuItem('-', nil); - AddMenuItem(FORMAT_REG_SETTINGS_MENU_NAME, lcJCFIDE.DoRegistrySettings); - AddMenuItem(FORMAT_SETTINGS_MENU_NAME, lcJCFIDE.DoFormatSettings); - - AddMenuItem('-', nil); - AddMenuItem(FORMAT_ABOUT_MENU_NAME, lcJCFIDE.DoAbout); - - // debug ShowMessage('menu add succeeded on try #' + IntToStr(miTries)); - pbDoAgain := False; - end - else - begin - // do over, a bit later - pbDoAgain := True; - RemoveMenuItems; - Sleep(0); - end; -end; - -{------------------------------------------------------------ - keyboard binding - ctrl-alt-f to format current unit - - based on - http://community.borland.com/article/0,1410,26389,00.html - and http://www.gexperts.org/opentools/ } - -type - TJcfKeyBindings = class(TNotifierObject, IOTAKeyboardBinding) - private - procedure OnShortcut(const Context: IOTAKeyContext; - KeyCode: TShortcut; var BindingResult: TKeyBindingResult); - - public - { IOTAKeyboardBinding methods } - function GetBindingType: TBindingType; - function GetDisplayName: string; - function GetName: string; - procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices); - end; - -function TJcfKeyBindings.GetBindingType: TBindingType; -begin - Result := btPartial; -end; - -function TJcfKeyBindings.GetDisplayName: string; -begin - Result := 'JCF'; -end; - -function TJcfKeyBindings.GetName: string; -begin - Result := 'Jedi.CodeFormatter'; -end; - -procedure TJcfKeyBindings.BindKeyboard(const BindingServices: IOTAKeyBindingServices); -var - liShortcut: TShortcut; -begin - liShortcut := ShortCut((Ord('F')), [ssCtrl, ssAlt]); - BindingServices.AddKeyBinding([liShortcut], OnShortcut, nil) -end; - -procedure TJcfKeyBindings.OnShortcut(const Context: IOTAKeyContext; - KeyCode: TShortcut; var BindingResult: TKeyBindingResult); -begin - lcJCFIDE.DoFormatCurrentIDEWindow(self); -end; - - -procedure Register; -begin - { delayed reg. technique from sample code by Mike Remec - http://www.miharemec.com/doc/ota-nmi.html } - Assert(lcDelayedRegister <> nil); - lcDelayedRegister.Proc := AddMenuItems; - lcDelayedRegister.DoItSoon; - - (BorlandIDEServices as IOTAKeyboardServices).AddKeyboardBinding(TJcfKeyBindings.Create); -end; - - -initialization - lcJCFIDE := TJcfIdeMain.Create; - lcDelayedRegister := TDelay.Create; - -finalization - FreeAndNil(lcDelayedRegister); - - RemoveMenuItems; - FreeAndNil(lcJCFIDE); -end.