2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.git.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class TplAppGit
12 *
13 * This class provides methods to generate and manage Git-related menu items and actions
14 * within the Bearsampp application. It includes functionalities for creating Git menus,
15 * refreshing repositories, and handling startup actions.
16 */
18{
19 // Constants for menu and action identifiers
20 const MENU = 'git';
21 const MENU_REPOS = 'gitRepos';
22
23 const ACTION_REFRESH_REPOS = 'refreshGitRepos';
24 const ACTION_REFRESH_REPOS_STARTUP = 'refreshGitReposStartup';
25
26 /**
27 * Processes and generates the main Git menu.
28 *
29 * This method generates the main Git menu item, which includes options for managing
30 * Git repositories and actions related to Git functionalities.
31 *
32 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
33 *
34 * @return array The generated Git menu item and actions.
35 */
36 public static function process()
37 {
38 global $bearsamppLang;
39
40 return TplApp::getMenu($bearsamppLang->getValue(Lang::GIT), self::MENU, get_called_class());
41 }
42
43 /**
44 * Generates the Git menu with various options.
45 *
46 * This method creates the Git menu with options for opening Git console, Git GUI,
47 * refreshing repositories, and setting up repository scanning at startup.
48 *
49 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
50 * @global object $bearsamppTools Provides access to various tools and utilities.
51 *
52 * @return string The generated Git menu content.
53 */
54 public static function getMenuGit()
55 {
56 global $bearsamppLang, $bearsamppTools;
57
58 $tplRepos = TplApp::getMenu($bearsamppLang->getValue(Lang::REPOS), self::MENU_REPOS, get_called_class());
59 $emptyRepos = count(explode(PHP_EOL, $tplRepos[TplApp::SECTION_CONTENT])) == 2;
60 $isScanStartup = $bearsamppTools->getGit()->isScanStartup();
61
62 $tplRefreshRepos = TplApp::getActionMulti(
63 self::ACTION_REFRESH_REPOS, null,
65 false, get_called_class()
66 );
67 $tplRefreshReposStartup = TplApp::getActionMulti(
68 self::ACTION_REFRESH_REPOS_STARTUP, array($isScanStartup ? Config::DISABLED : Config::ENABLED),
69 array($bearsamppLang->getValue(Lang::MENU_SCAN_REPOS_STARTUP), $isScanStartup ? TplAestan::GLYPH_CHECK : ''),
70 false, get_called_class()
71 );
72
73 /* get path for git gui */
74 $gitgui = $bearsamppTools->getGit()->getSymlinkPath() . '/cmd';
75
79 $bearsamppTools->getConsoleZ()->getTabTitleGit()
80 ) . PHP_EOL .
83 $gitgui . '/git-gui',
85 ) . PHP_EOL .
86 TplAestan::getItemSeparator() . PHP_EOL .
87
88 // Items
89 (!$emptyRepos ? $tplRepos[TplApp::SECTION_CALL] . PHP_EOL : '') .
90 $tplRefreshRepos[TplApp::SECTION_CALL] . PHP_EOL .
91 $tplRefreshReposStartup[TplApp::SECTION_CALL] . PHP_EOL .
92
93 // Actions
94 (!$emptyRepos ? $tplRepos[TplApp::SECTION_CONTENT] . PHP_EOL : PHP_EOL) .
95 $tplRefreshRepos[TplApp::SECTION_CONTENT] . PHP_EOL .
96 $tplRefreshReposStartup[TplApp::SECTION_CONTENT];
97 }
98
99 /**
100 * Generates the Git repositories menu.
101 *
102 * This method creates the menu for listing and managing Git repositories found
103 * by the application.
104 *
105 * @global object $bearsamppTools Provides access to various tools and utilities.
106 *
107 * @return string The generated Git repositories menu content.
108 */
109 public static function getMenuGitRepos()
110 {
111 global $bearsamppTools;
112 $result = '';
113
114 foreach ($bearsamppTools->getGit()->findRepos() as $repo) {
116 basename($repo),
118 $bearsamppTools->getConsoleZ()->getTabTitleGit(),
119 $bearsamppTools->getConsoleZ()->getTabTitleGit($repo),
120 $repo
121 ) . PHP_EOL;
122 }
123
124 return $result;
125 }
126
127 /**
128 * Generates the action to refresh Git repositories.
129 *
130 * This method creates the action string for refreshing Git repositories. It includes
131 * commands to reload the application after refreshing the repositories.
132 *
133 * @return string The generated action string for refreshing Git repositories.
134 */
135 public static function getActionRefreshGitRepos()
136 {
139 }
140
141 /**
142 * Generates the action to refresh Git repositories at startup.
143 *
144 * This method creates the action string for setting up repository scanning at startup.
145 * It includes commands to reload the application after setting the startup action.
146 *
147 * @param int $scanStartup The flag indicating whether to enable or disable scanning at startup.
148 *
149 * @return string The generated action string for refreshing Git repositories at startup.
150 */
151 public static function getActionRefreshGitReposStartup($scanStartup)
152 {
153 return TplApp::getActionRun(Action::REFRESH_REPOS_STARTUP, array(ActionRefreshRepos::GIT, $scanStartup)) . PHP_EOL .
155 }
156}
$result
global $bearsamppLang
const REFRESH_REPOS_STARTUP
const REFRESH_REPOS
const DISABLED
const ENABLED
const MENU_SCAN_REPOS_STARTUP
const GITGUI
const REPOS
const GIT
const GIT_CONSOLE
const MENU_REFRESH_REPOS
static getItemSeparator()
static getItemConsoleZ($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
static getItemExe($caption, $exe, $glyph, $params=null)
static getActionRefreshGitReposStartup($scanStartup)
static getActionRefreshGitRepos()
static getMenuGitRepos()
const ACTION_REFRESH_REPOS
static getMenuGit()
const ACTION_REFRESH_REPOS_STARTUP
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
const SECTION_CALL
const SECTION_CONTENT
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
static getMenu($caption, $menu, $class)