diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index 2daf0a1..ceb9b10 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -78,6 +78,16 @@ def receiveHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[ReceiveHook] = Nil /** + * Override to add global menus. + */ + val globalMenus: Seq[GlobalMenu] = Nil + + /** + * Override to add global menus. + */ + def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[GlobalMenu] = Nil + + /** * This method is invoked in initialization of plugin system. * Register plugin functionality to PluginRegistry. */ @@ -100,6 +110,9 @@ (receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook => registry.addReceiveHook(receiveHook) } + (globalMenus ++ globalMenus(registry, context, settings)).foreach { menu => + registry.addGlobalMenu(menu) + } } /** diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index e69ab61..3b22750 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -33,6 +33,8 @@ private val receiveHooks = new ListBuffer[ReceiveHook] receiveHooks += new ProtectedBranchReceiveHook() + private val globalMenus = new ListBuffer[GlobalMenu] + def addPlugin(pluginInfo: PluginInfo): Unit = { plugins += pluginInfo } @@ -107,17 +109,23 @@ def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq - private case class GlobalAction( - method: String, - path: String, - function: (HttpServletRequest, HttpServletResponse, Context) => Any - ) + def addGlobalMenu(menu: GlobalMenu): Unit = { + globalMenus += menu + } - private case class RepositoryAction( - method: String, - path: String, - function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any - ) + def getGlobalMenus: Seq[GlobalMenu] = globalMenus.toSeq + +// private case class GlobalAction( +// method: String, +// path: String, +// function: (HttpServletRequest, HttpServletResponse, Context) => Any +// ) +// +// private case class RepositoryAction( +// method: String, +// path: String, +// function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any +// ) } @@ -201,6 +209,10 @@ } +abstract class GlobalMenu { + def createLink(context: Context): Option[(String, String)] +} + case class PluginInfo( pluginId: String, pluginName: String, diff --git a/src/main/twirl/gitbucket/core/main.scala.html b/src/main/twirl/gitbucket/core/main.scala.html index 88d9837..b7da04e 100644 --- a/src/main/twirl/gitbucket/core/main.scala.html +++ b/src/main/twirl/gitbucket/core/main.scala.html @@ -71,6 +71,11 @@ } } + @gitbucket.core.plugin.PluginRegistry().getGlobalMenus.map { menu => + @menu.createLink(context).map { case (label, link) => + @label + } + } @if(loginAccount.isDefined){