# -*- coding: utf-8 -*-

import dabo.ui
import dabo.lib.datanav as datanav
from MenFileOpen import MenFileOpen
from MenReports import MenReports


class FrmBase(datanav.Form):

	def initProperties(self):
		super(FrmBase, self).initProperties()
		# Setting RequeryOnLoad to True will result in an automatic requery upon
		# form load, which may be appropriate for your app (if it is reasonably
		# certain that the dataset will be small no matter what).
		self.RequeryOnLoad = False
		self.Icon = "daboIcon.ico"


	def setupMenu(self):
		super(FrmBase, self).setupMenu()
		self.fillFileOpenMenu()
		self.fillReportsMenu()


	def fillFileOpenMenu(self):
		"""Add the File|Open menu, with menu items for opening each form."""
		app = self.Application
		fileMenu = self.MenuBar.getMenu("base_file")
		fileMenu.prependMenu(MenFileOpen(fileMenu))


	def fillReportsMenu(self):
		"""Add the Reports menu."""
		app = self.Application
		menReports = MenReports()

		# We want the reports menu right after the Actions menu:
		idx = self.MenuBar.getMenuIndex("actions")
		if idx is None:
			# punt:
			idx = 3
		idx += 1
		self.MenuBar.insertMenu(idx, menReports)

		# The datanav form puts a Quick Report option at the end of the Actions
		# menu, but let's move it over to the Reports menu instead.
		menu = self.MenuBar.getMenu("actions")
		idx = menu.getItemIndex("actions_quickreport")
		if idx is not None:
			qrItem = menu.remove(idx, False)
			menReports = self.MenuBar.getMenu("reports")
			menReports.prependSeparator()
			menReports.prependItem(qrItem)


