src/eric7/Project/Project.py

branch
eric7
changeset 9214
bd28e56047d7
parent 9210
15743bae8a50
child 9221
bf71ee032bb4
equal deleted inserted replaced
9213:2bf743848d2f 9214:bd28e56047d7
49 from .DebuggerPropertiesFile import DebuggerPropertiesFile 49 from .DebuggerPropertiesFile import DebuggerPropertiesFile
50 50
51 from Sessions.SessionFile import SessionFile 51 from Sessions.SessionFile import SessionFile
52 52
53 from Tasks.TasksFile import TasksFile 53 from Tasks.TasksFile import TasksFile
54
55 from CodeFormatting.BlackFormattingAction import BlackFormattingAction
54 56
55 57
56 class Project(QObject): 58 class Project(QObject):
57 """ 59 """
58 Class implementing the project management functionality. 60 Class implementing the project management functionality.
2344 self.makeGrp.setEnabled( 2346 self.makeGrp.setEnabled(
2345 self.pdata["MAKEPARAMS"]["MakeEnabled"]) 2347 self.pdata["MAKEPARAMS"]["MakeEnabled"])
2346 self.menuMakeAct.setEnabled( 2348 self.menuMakeAct.setEnabled(
2347 self.pdata["MAKEPARAMS"]["MakeEnabled"]) 2349 self.pdata["MAKEPARAMS"]["MakeEnabled"])
2348 self.menuOtherToolsAct.setEnabled(True) 2350 self.menuOtherToolsAct.setEnabled(True)
2351 self.menuFormattingAct.setEnabled(True)
2349 2352
2350 self.projectAboutToBeCreated.emit() 2353 self.projectAboutToBeCreated.emit()
2351 2354
2352 hashStr = str(QCryptographicHash.hash( 2355 hashStr = str(QCryptographicHash.hash(
2353 QByteArray(self.ppath.encode("utf-8")), 2356 QByteArray(self.ppath.encode("utf-8")),
3037 self.makeGrp.setEnabled( 3040 self.makeGrp.setEnabled(
3038 self.pdata["MAKEPARAMS"]["MakeEnabled"]) 3041 self.pdata["MAKEPARAMS"]["MakeEnabled"])
3039 self.menuMakeAct.setEnabled( 3042 self.menuMakeAct.setEnabled(
3040 self.pdata["MAKEPARAMS"]["MakeEnabled"]) 3043 self.pdata["MAKEPARAMS"]["MakeEnabled"])
3041 self.menuOtherToolsAct.setEnabled(True) 3044 self.menuOtherToolsAct.setEnabled(True)
3045 self.menuFormattingAct.setEnabled(True)
3042 3046
3043 # open a project debugger properties file being quiet 3047 # open a project debugger properties file being quiet
3044 # about errors 3048 # about errors
3045 if Preferences.getProject("AutoLoadDbgProperties"): 3049 if Preferences.getProject("AutoLoadDbgProperties"):
3046 self.__readDebugProperties(True) 3050 self.__readDebugProperties(True)
3294 self.menuPackagersAct.setEnabled(False) 3298 self.menuPackagersAct.setEnabled(False)
3295 self.pluginGrp.setEnabled(False) 3299 self.pluginGrp.setEnabled(False)
3296 self.makeGrp.setEnabled(False) 3300 self.makeGrp.setEnabled(False)
3297 self.menuMakeAct.setEnabled(False) 3301 self.menuMakeAct.setEnabled(False)
3298 self.menuOtherToolsAct.setEnabled(False) 3302 self.menuOtherToolsAct.setEnabled(False)
3303 self.menuFormattingAct.setEnabled(False)
3299 3304
3300 self.__model.projectClosed() 3305 self.__model.projectClosed()
3301 self.projectClosedHooks.emit() 3306 self.projectClosedHooks.emit()
3302 self.projectClosed.emit(shutdown) 3307 self.projectClosed.emit(shutdown)
3303 3308
3503 project specific word and exclude list 3508 project specific word and exclude list
3504 """ 3509 """
3505 pwl = "" 3510 pwl = ""
3506 if self.pdata["SPELLWORDS"]: 3511 if self.pdata["SPELLWORDS"]:
3507 pwl = os.path.join(self.ppath, self.pdata["SPELLWORDS"]) 3512 pwl = os.path.join(self.ppath, self.pdata["SPELLWORDS"])
3513 if not os.path.isfile(pwl):
3514 pwl = ""
3508 3515
3509 pel = "" 3516 pel = ""
3510 if self.pdata["SPELLEXCLUDES"]: 3517 if self.pdata["SPELLEXCLUDES"]:
3511 pel = os.path.join(self.ppath, self.pdata["SPELLEXCLUDES"]) 3518 pel = os.path.join(self.ppath, self.pdata["SPELLEXCLUDES"])
3519 if not os.path.isfile(pel):
3520 pel = ""
3512 3521
3513 return (pwl, pel) 3522 return (pwl, pel)
3514 3523
3515 def getDefaultSourceExtension(self): 3524 def getDefaultSourceExtension(self):
3516 """ 3525 """
3920 def initActions(self): 3929 def initActions(self):
3921 """ 3930 """
3922 Public slot to initialize the project related actions. 3931 Public slot to initialize the project related actions.
3923 """ 3932 """
3924 self.actions = [] 3933 self.actions = []
3934
3935 ###################################################################
3936 ## Project actions
3937 ###################################################################
3925 3938
3926 self.actGrp1 = createActionGroup(self) 3939 self.actGrp1 = createActionGroup(self)
3927 3940
3928 act = EricAction( 3941 act = EricAction(
3929 self.tr('New project'), 3942 self.tr('New project'),
3986 """<b>Save as</b>""" 3999 """<b>Save as</b>"""
3987 """<p>This saves the current project to a new file.</p>""" 4000 """<p>This saves the current project to a new file.</p>"""
3988 )) 4001 ))
3989 self.saveasAct.triggered.connect(self.saveProjectAs) 4002 self.saveasAct.triggered.connect(self.saveProjectAs)
3990 self.actions.append(self.saveasAct) 4003 self.actions.append(self.saveasAct)
3991 4004
4005 ###################################################################
4006 ## Project management actions
4007 ###################################################################
4008
3992 self.actGrp2 = createActionGroup(self) 4009 self.actGrp2 = createActionGroup(self)
3993 4010
3994 self.addFilesAct = EricAction( 4011 self.addFilesAct = EricAction(
3995 self.tr('Add files to project'), 4012 self.tr('Add files to project'),
3996 UI.PixmapCache.getIcon("fileMisc"), 4013 UI.PixmapCache.getIcon("fileMisc"),
4126 """ associations. Lexers are used to highlight the editor""" 4143 """ associations. Lexers are used to highlight the editor"""
4127 """ text.</p>""" 4144 """ text.</p>"""
4128 )) 4145 ))
4129 self.lexersAct.triggered.connect(self.__showLexerAssociations) 4146 self.lexersAct.triggered.connect(self.__showLexerAssociations)
4130 self.actions.append(self.lexersAct) 4147 self.actions.append(self.lexersAct)
4131 4148
4149 ###################################################################
4150 ## Project debug actions
4151 ###################################################################
4152
4132 self.dbgActGrp = createActionGroup(self) 4153 self.dbgActGrp = createActionGroup(self)
4133 4154
4134 act = EricAction( 4155 act = EricAction(
4135 self.tr('Debugger Properties'), 4156 self.tr('Debugger Properties'),
4136 self.tr('Debugger &Properties...'), 0, 0, 4157 self.tr('Debugger &Properties...'), 0, 0,
4191 """<p>This resets the project specific debugger settings.</p>""" 4212 """<p>This resets the project specific debugger settings.</p>"""
4192 )) 4213 ))
4193 act.triggered.connect(self.__initDebugProperties) 4214 act.triggered.connect(self.__initDebugProperties)
4194 self.actions.append(act) 4215 self.actions.append(act)
4195 4216
4217 ###################################################################
4218 ## Project session actions
4219 ###################################################################
4220
4196 self.sessActGrp = createActionGroup(self) 4221 self.sessActGrp = createActionGroup(self)
4197 4222
4198 act = EricAction( 4223 act = EricAction(
4199 self.tr('Load session'), 4224 self.tr('Load session'),
4200 self.tr('Load session'), 0, 0, 4225 self.tr('Load session'), 0, 0,
4201 self.sessActGrp, 'project_load_session') 4226 self.sessActGrp, 'project_load_session')
4202 act.setStatusTip(self.tr('Load the projects session file.')) 4227 act.setStatusTip(self.tr('Load the projects session file.'))
4240 """<b>Delete session</b>""" 4265 """<b>Delete session</b>"""
4241 """<p>This deletes the projects session file</p>""" 4266 """<p>This deletes the projects session file</p>"""
4242 )) 4267 ))
4243 act.triggered.connect(self.__deleteSession) 4268 act.triggered.connect(self.__deleteSession)
4244 self.actions.append(act) 4269 self.actions.append(act)
4270
4271 ###################################################################
4272 ## Project Tools - check actions
4273 ###################################################################
4245 4274
4246 self.chkGrp = createActionGroup(self) 4275 self.chkGrp = createActionGroup(self)
4247 4276
4248 self.codeMetricsAct = EricAction( 4277 self.codeMetricsAct = EricAction(
4249 self.tr('Code Metrics'), 4278 self.tr('Code Metrics'),
4283 """<b>Profile Data...</b>""" 4312 """<b>Profile Data...</b>"""
4284 """<p>This shows the profiling data for the project.</p>""" 4313 """<p>This shows the profiling data for the project.</p>"""
4285 )) 4314 ))
4286 self.codeProfileAct.triggered.connect(self.__showProfileData) 4315 self.codeProfileAct.triggered.connect(self.__showProfileData)
4287 self.actions.append(self.codeProfileAct) 4316 self.actions.append(self.codeProfileAct)
4317
4318 ###################################################################
4319 ## Project Tools - graphics actions
4320 ###################################################################
4288 4321
4289 self.graphicsGrp = createActionGroup(self) 4322 self.graphicsGrp = createActionGroup(self)
4290 4323
4291 self.applicationDiagramAct = EricAction( 4324 self.applicationDiagramAct = EricAction(
4292 self.tr('Application Diagram'), 4325 self.tr('Application Diagram'),
4312 """<b>Load Diagram...</b>""" 4345 """<b>Load Diagram...</b>"""
4313 """<p>This loads a diagram from file.</p>""" 4346 """<p>This loads a diagram from file.</p>"""
4314 )) 4347 ))
4315 self.loadDiagramAct.triggered.connect(self.__loadDiagram) 4348 self.loadDiagramAct.triggered.connect(self.__loadDiagram)
4316 self.actions.append(self.loadDiagramAct) 4349 self.actions.append(self.loadDiagramAct)
4317 4350
4351 ###################################################################
4352 ## Project Tools - plugin packaging actions
4353 ###################################################################
4354
4318 self.pluginGrp = createActionGroup(self) 4355 self.pluginGrp = createActionGroup(self)
4319 4356
4320 self.pluginPkgListAct = EricAction( 4357 self.pluginPkgListAct = EricAction(
4321 self.tr('Create Package List'), 4358 self.tr('Create Package List'),
4322 UI.PixmapCache.getIcon("pluginArchiveList"), 4359 UI.PixmapCache.getIcon("pluginArchiveList"),
4323 self.tr('Create &Package List'), 0, 0, 4360 self.tr('Create &Package List'), 0, 0,
4324 self.pluginGrp, 'project_plugin_pkglist') 4361 self.pluginGrp, 'project_plugin_pkglist')
4366 """ is modified to reflect a snapshot release.</p>""" 4403 """ is modified to reflect a snapshot release.</p>"""
4367 )) 4404 ))
4368 self.pluginSArchiveAct.triggered.connect( 4405 self.pluginSArchiveAct.triggered.connect(
4369 self.__pluginCreateSnapshotArchives) 4406 self.__pluginCreateSnapshotArchives)
4370 self.actions.append(self.pluginSArchiveAct) 4407 self.actions.append(self.pluginSArchiveAct)
4408
4409 ###################################################################
4410 ## Project Tools - make actions
4411 ###################################################################
4371 4412
4372 self.makeGrp = createActionGroup(self) 4413 self.makeGrp = createActionGroup(self)
4373 4414
4374 self.makeExecuteAct = EricAction( 4415 self.makeExecuteAct = EricAction(
4375 self.tr('Execute Make'), 4416 self.tr('Execute Make'),
4398 )) 4439 ))
4399 self.makeTestAct.triggered.connect( 4440 self.makeTestAct.triggered.connect(
4400 lambda: self.__executeMake(questionOnly=True)) 4441 lambda: self.__executeMake(questionOnly=True))
4401 self.actions.append(self.makeTestAct) 4442 self.actions.append(self.makeTestAct)
4402 4443
4444 ###################################################################
4445 ## Project Tools - other tools actions
4446 ###################################################################
4447
4448 self.othersGrp = createActionGroup(self)
4449
4403 self.createSBOMAct = EricAction( 4450 self.createSBOMAct = EricAction(
4404 self.tr('Create SBOM File'), 4451 self.tr('Create SBOM File'),
4405 self.tr('Create &SBOM File'), 0, 0, 4452 self.tr('Create &SBOM File'), 0, 0,
4406 self, 'project_create_sbom') 4453 self.othersGrp, 'project_create_sbom')
4407 self.createSBOMAct.setStatusTip( 4454 self.createSBOMAct.setStatusTip(
4408 self.tr("Create a SBOM file of the project dependencies.")) 4455 self.tr("Create a SBOM file of the project dependencies."))
4409 self.createSBOMAct.setWhatsThis(self.tr( 4456 self.createSBOMAct.setWhatsThis(self.tr(
4410 """<b>Create SBOM File</b>""" 4457 """<b>Create SBOM File</b>"""
4411 """<p>This allows the creation of a SBOM file of the project""" 4458 """<p>This allows the creation of a SBOM file of the project"""
4412 """ dependencies. This may be based on various input sources""" 4459 """ dependencies. This may be based on various input sources"""
4413 """ and will be saved as a CycloneDX SBOM file.</p>""" 4460 """ and will be saved as a CycloneDX SBOM file.</p>"""
4414 )) 4461 ))
4415 self.createSBOMAct.triggered.connect(self.__createSBOMFile) 4462 self.createSBOMAct.triggered.connect(self.__createSBOMFile)
4416 self.actions.append(self.createSBOMAct) 4463 self.actions.append(self.createSBOMAct)
4417 4464
4465 ###################################################################
4466 ## Project Tools - code formatting actions
4467 ###################################################################
4468
4469 self.blackFormattingGrp = createActionGroup(self)
4470
4471 self.blackAboutAct = EricAction(
4472 self.tr("About Black"),
4473 self.tr("&Black"),
4474 0, 0,
4475 self.blackFormattingGrp, "project_black_about"
4476 )
4477 self.blackAboutAct.setStatusTip(
4478 self.tr("Show some information about 'Black'.")
4479 )
4480 self.blackAboutAct.setWhatsThis(self.tr(
4481 "<b>Black</b>"
4482 "<p>This shows some information about the installed 'Black' tool.</p>"
4483 ))
4484 self.blackAboutAct.triggered.connect(self.__aboutBlack)
4485 self.actions.append(self.blackAboutAct)
4486 font = self.blackAboutAct.font()
4487 font.setBold(True)
4488 self.blackAboutAct.setFont(font)
4489
4490 self.blackFormatAct = EricAction(
4491 self.tr("Format Code"),
4492 self.tr("&Format Code"),
4493 0, 0,
4494 self.blackFormattingGrp, "project_black_format_code"
4495 )
4496 self.blackFormatAct.setStatusTip(
4497 self.tr("Format the project sources with 'Black'.")
4498 )
4499 self.blackFormatAct.setWhatsThis(self.tr(
4500 "<b>Format Code</b>"
4501 "<p>This shows a dialog to enter parameters for the formatting run and"
4502 " reformats the project sources using 'Black'.</p>"
4503 ))
4504 self.blackFormatAct.triggered.connect(
4505 lambda: self.__performFormatWithBlack(BlackFormattingAction.Format)
4506 )
4507 self.actions.append(self.blackFormatAct)
4508
4509 self.blackCheckFormattingAct = EricAction(
4510 self.tr("Check Code Formatting"),
4511 self.tr("&Check Code Formatting"),
4512 0, 0,
4513 self.blackFormattingGrp, "project_black_check_code"
4514 )
4515 self.blackCheckFormattingAct.setStatusTip(
4516 self.tr(
4517 "Check, if the project sources need to be reformatted with 'Black'."
4518 )
4519 )
4520 self.blackCheckFormattingAct.setWhatsThis(self.tr(
4521 "<b>Check Code Formatting</b>"
4522 "<p>This shows a dialog to enter parameters for the format check run and"
4523 " performs a check, if the project sources need to be reformatted using"
4524 " 'Black'.</p>"
4525 ))
4526 self.blackCheckFormattingAct.triggered.connect(
4527 lambda: self.__performFormatWithBlack(BlackFormattingAction.Check)
4528 )
4529 self.actions.append(self.blackCheckFormattingAct)
4530
4531 self.blackDiffFormattingAct = EricAction(
4532 self.tr("Code Formatting Diff"),
4533 self.tr("Code Formatting &Diff"),
4534 0, 0,
4535 self.blackFormattingGrp, "project_black_diff_code"
4536 )
4537 self.blackDiffFormattingAct.setStatusTip(
4538 self.tr(
4539 "Generate a unified diff of potential project source reformatting"
4540 " with 'Black'."
4541 )
4542 )
4543 self.blackDiffFormattingAct.setWhatsThis(self.tr(
4544 "<b>Diff Code Formatting</b>"
4545 "<p>This shows a dialog to enter parameters for the format diff run and"
4546 " generates a unified diff of potential project source reformatting using"
4547 " 'Black'.</p>"
4548 ))
4549 self.blackDiffFormattingAct.triggered.connect(
4550 lambda: self.__performFormatWithBlack(BlackFormattingAction.Diff)
4551 )
4552 self.actions.append(self.blackDiffFormattingAct)
4553
4418 self.closeAct.setEnabled(False) 4554 self.closeAct.setEnabled(False)
4419 self.saveAct.setEnabled(False) 4555 self.saveAct.setEnabled(False)
4420 self.saveasAct.setEnabled(False) 4556 self.saveasAct.setEnabled(False)
4421 self.actGrp2.setEnabled(False) 4557 self.actGrp2.setEnabled(False)
4422 self.propsAct.setEnabled(False) 4558 self.propsAct.setEnabled(False)
4444 self.vcsMenu.setTearOffEnabled(True) 4580 self.vcsMenu.setTearOffEnabled(True)
4445 self.vcsProjectHelper.initMenu(self.vcsMenu) 4581 self.vcsProjectHelper.initMenu(self.vcsMenu)
4446 self.vcsMenu.setEnabled(self.vcsSoftwareAvailable()) 4582 self.vcsMenu.setEnabled(self.vcsSoftwareAvailable())
4447 self.checksMenu = QMenu(self.tr('Chec&k'), toolsMenu) 4583 self.checksMenu = QMenu(self.tr('Chec&k'), toolsMenu)
4448 self.checksMenu.setTearOffEnabled(True) 4584 self.checksMenu.setTearOffEnabled(True)
4585 self.formattingMenu = QMenu(self.tr("Code &Formatting"), toolsMenu)
4586 self.formattingMenu.setTearOffEnabled(True)
4449 self.menuShow = QMenu(self.tr('Sho&w'), toolsMenu) 4587 self.menuShow = QMenu(self.tr('Sho&w'), toolsMenu)
4450 self.graphicsMenu = QMenu(self.tr('&Diagrams'), toolsMenu) 4588 self.graphicsMenu = QMenu(self.tr('&Diagrams'), toolsMenu)
4451 self.packagersMenu = QMenu(self.tr('Pac&kagers'), toolsMenu) 4589 self.packagersMenu = QMenu(self.tr('Pac&kagers'), toolsMenu)
4452 self.apidocMenu = QMenu(self.tr('Source &Documentation'), toolsMenu) 4590 self.apidocMenu = QMenu(self.tr('Source &Documentation'), toolsMenu)
4453 self.apidocMenu.setTearOffEnabled(True) 4591 self.apidocMenu.setTearOffEnabled(True)
4465 "Apidoc": self.apidocMenu, 4603 "Apidoc": self.apidocMenu,
4466 "Debugger": self.debuggerMenu, 4604 "Debugger": self.debuggerMenu,
4467 "Packagers": self.packagersMenu, 4605 "Packagers": self.packagersMenu,
4468 "Make": self.makeMenu, 4606 "Make": self.makeMenu,
4469 "OtherTools": self.othersMenu, 4607 "OtherTools": self.othersMenu,
4608 "Formatting": self.formattingMenu,
4470 } 4609 }
4471 4610
4472 # connect the aboutToShow signals 4611 # connect the aboutToShow signals
4473 self.recentMenu.aboutToShow.connect(self.__showContextMenuRecent) 4612 self.recentMenu.aboutToShow.connect(self.__showContextMenuRecent)
4474 self.recentMenu.triggered.connect(self.__openRecent) 4613 self.recentMenu.triggered.connect(self.__openRecent)
4480 self.packagersMenu.aboutToShow.connect(self.__showContextMenuPackagers) 4619 self.packagersMenu.aboutToShow.connect(self.__showContextMenuPackagers)
4481 self.sessionMenu.aboutToShow.connect(self.__showContextMenuSession) 4620 self.sessionMenu.aboutToShow.connect(self.__showContextMenuSession)
4482 self.debuggerMenu.aboutToShow.connect(self.__showContextMenuDebugger) 4621 self.debuggerMenu.aboutToShow.connect(self.__showContextMenuDebugger)
4483 self.makeMenu.aboutToShow.connect(self.__showContextMenuMake) 4622 self.makeMenu.aboutToShow.connect(self.__showContextMenuMake)
4484 self.othersMenu.aboutToShow.connect(self.__showContextMenuOthers) 4623 self.othersMenu.aboutToShow.connect(self.__showContextMenuOthers)
4624 self.formattingMenu.aboutToShow.connect(self.__showContextMenuFormat)
4485 menu.aboutToShow.connect(self.__showMenu) 4625 menu.aboutToShow.connect(self.__showMenu)
4486 4626
4487 # build the show menu 4627 # build the show menu
4488 self.menuShow.setTearOffEnabled(True) 4628 self.menuShow.setTearOffEnabled(True)
4489 self.menuShow.addAction(self.codeMetricsAct) 4629 self.menuShow.addAction(self.codeMetricsAct)
4514 self.makeMenu.addActions(self.makeGrp.actions()) 4654 self.makeMenu.addActions(self.makeGrp.actions())
4515 self.makeMenu.addSeparator() 4655 self.makeMenu.addSeparator()
4516 4656
4517 # build the 'Other Tools' menu 4657 # build the 'Other Tools' menu
4518 self.othersMenu.setTearOffEnabled(True) 4658 self.othersMenu.setTearOffEnabled(True)
4519 self.othersMenu.addAction(self.createSBOMAct) 4659 self.othersMenu.addActions(self.othersGrp.actions())
4660 self.othersMenu.addSeparator()
4661
4662 # build the 'Code Formatting' menu
4663 self.formattingMenu.setTearOffEnabled(True)
4664 self.formattingMenu.addActions(self.blackFormattingGrp.actions())
4665 self.formattingMenu.addSeparator()
4520 4666
4521 # build the project main menu 4667 # build the project main menu
4522 menu.setTearOffEnabled(True) 4668 menu.setTearOffEnabled(True)
4523 menu.addActions(self.actGrp1.actions()) 4669 menu.addActions(self.actGrp1.actions())
4524 self.menuRecentAct = menu.addMenu(self.recentMenu) 4670 self.menuRecentAct = menu.addMenu(self.recentMenu)
4543 toolsMenu.addSeparator() 4689 toolsMenu.addSeparator()
4544 toolsMenu.addMenu(self.vcsMenu) 4690 toolsMenu.addMenu(self.vcsMenu)
4545 toolsMenu.addSeparator() 4691 toolsMenu.addSeparator()
4546 self.menuCheckAct = toolsMenu.addMenu(self.checksMenu) 4692 self.menuCheckAct = toolsMenu.addMenu(self.checksMenu)
4547 toolsMenu.addSeparator() 4693 toolsMenu.addSeparator()
4694 self.menuFormattingAct = toolsMenu.addMenu(self.formattingMenu)
4695 toolsMenu.addSeparator()
4548 self.menuMakeAct = toolsMenu.addMenu(self.makeMenu) 4696 self.menuMakeAct = toolsMenu.addMenu(self.makeMenu)
4549 toolsMenu.addSeparator() 4697 toolsMenu.addSeparator()
4550 self.menuDiagramAct = toolsMenu.addMenu(self.graphicsMenu) 4698 self.menuDiagramAct = toolsMenu.addMenu(self.graphicsMenu)
4551 toolsMenu.addSeparator() 4699 toolsMenu.addSeparator()
4552 self.menuShowAct = toolsMenu.addMenu(self.menuShow) 4700 self.menuShowAct = toolsMenu.addMenu(self.menuShow)
4564 self.menuDebuggerAct.setEnabled(False) 4712 self.menuDebuggerAct.setEnabled(False)
4565 self.menuApidocAct.setEnabled(False) 4713 self.menuApidocAct.setEnabled(False)
4566 self.menuPackagersAct.setEnabled(False) 4714 self.menuPackagersAct.setEnabled(False)
4567 self.menuMakeAct.setEnabled(False) 4715 self.menuMakeAct.setEnabled(False)
4568 self.menuOtherToolsAct.setEnabled(False) 4716 self.menuOtherToolsAct.setEnabled(False)
4717 self.menuFormattingAct.setEnabled(False)
4569 4718
4570 self.__menu = menu 4719 self.__menu = menu
4571 self.__toolsMenu = toolsMenu 4720 self.__toolsMenu = toolsMenu
4572 4721
4573 return menu, toolsMenu 4722 return menu, toolsMenu
5954 return self.pdata["DOCSTRING"] 6103 return self.pdata["DOCSTRING"]
5955 6104
5956 ######################################################################### 6105 #########################################################################
5957 ## Below are methods implementing the 'SBOM' support 6106 ## Below are methods implementing the 'SBOM' support
5958 ######################################################################### 6107 #########################################################################
5959 6108
5960 def __showContextMenuOthers(self): 6109 def __showContextMenuOthers(self):
5961 """ 6110 """
5962 Private slot called before the 'Other Tools' menu is shown. 6111 Private slot called before the 'Other Tools' menu is shown.
5963 """ 6112 """
5964 self.showMenu.emit("OtherTools", self.othersMenu) 6113 self.showMenu.emit("OtherTools", self.othersMenu)
5969 Private slot to create a SBOM file of the project dependencies. 6118 Private slot to create a SBOM file of the project dependencies.
5970 """ 6119 """
5971 import CycloneDXInterface 6120 import CycloneDXInterface
5972 6121
5973 CycloneDXInterface.createCycloneDXFile("<project>") 6122 CycloneDXInterface.createCycloneDXFile("<project>")
6123
6124 #########################################################################
6125 ## Below are methods implementing the 'Code Formatting' support
6126 #########################################################################
6127
6128 def __showContextMenuFormat(self):
6129 """
6130 Private slot called before the 'Code Formatting' menu is shown.
6131 """
6132 self.showMenu.emit("Formatting", self.othersMenu)
6133
6134 @pyqtSlot()
6135 def __aboutBlack(self):
6136 """
6137 Private slot to show some information about the installed 'Black' tool.
6138 """
6139 import black
6140
6141 EricMessageBox.information(
6142 None,
6143 self.tr("About Black"),
6144 self.tr("""<p><b>Black Version {0}</b></p>"""
6145 """<p><i>Black</i> is the uncompromising Python code"""
6146 """ formatter.</p>""").format(black.__version__)
6147 )
6148
6149 def __performFormatWithBlack(self, action):
6150 """
6151 Private method to format the project sources using the 'Black' tool.
6152
6153 Following actions are supported.
6154 <ul>
6155 <li>BlackFormattingAction.Format - the code reformatting is performed</li>
6156 <li>BlackFormattingAction.Check - a check is performed, if code formatting
6157 is necessary</li>
6158 <li>BlackFormattingAction.Diff - a unified diff of potential code formatting
6159 changes is generated</li>
6160 </ul>
6161
6162 @param action formatting operation to be performed
6163 @type BlackFormattingAction
6164 """
6165 from CodeFormatting.BlackConfigurationDialog import BlackConfigurationDialog
6166 from CodeFormatting.BlackFormattingDialog import BlackFormattingDialog
6167
6168 if ericApp().getObject("ViewManager").checkAllDirty():
6169 dlg = BlackConfigurationDialog(withProject=True)
6170 if dlg.exec() == QDialog.DialogCode.Accepted:
6171 config = dlg.getConfiguration()
6172
6173 formattingDialog = BlackFormattingDialog(
6174 config,
6175 self.getProjectFiles("SOURCES", normalized=True),
6176 project=self,
6177 action=action
6178 )
6179 formattingDialog.exec()
5974 6180
5975 # 6181 #
5976 # eflag: noqa = M601 6182 # eflag: noqa = M601

eric ide

mercurial