public GUIManager() { // AppDomain.CurrentDomain.ProcessExit += DBManager.OnExit; Application.Initialize(ToolkitType.Gtk); // Initialize main window MainWindow = new GUIWindow() { Title = "Password Manager", Width = 500, Height = 600, Resizable = true }; LoggedIn = false; MainMenu = new Menu(); // Creates the 'File' menu item MenuItem fileMenu = new MenuItem("File"); fileMenu.SubMenu = new Menu(); // Adds the 'Home' command to 'File' menu MenuItem homeCommand = new MenuItem(new Command("Home")); fileMenu.SubMenu.Items.Add(homeCommand); // Adds the 'Settings' command to 'File' menu MenuItem settingsCommand = new MenuItem(new Command("Settings")); fileMenu.SubMenu.Items.Add(settingsCommand); // Adds the 'Logout' command to 'File' menu MenuItem logoutCommand = new MenuItem(new Command("Logout")); fileMenu.SubMenu.Items.Add(logoutCommand); // Finalize fileMenu MainMenu.Items.Add((fileMenu)); logoutCommand.Sensitive = false; // Change after logged in // Creates the 'Help' menu item MenuItem helpMenu = new MenuItem("Help"); helpMenu.SubMenu = new Menu(); // Adds 'About' item to 'Help' menu MenuItem aboutSubMenu = new MenuItem("About"); helpMenu.SubMenu.Items.Add(aboutSubMenu); // Finalize helpMenu MainMenu.Items.Add(helpMenu); // Make login page LoginPage = new LoginPage(this); // Set buttons for window switching aboutSubMenu.Clicked += delegate { // Make about page AboutPage = new AboutPage(this); MainWindow.Content = AboutPage; }; homeCommand.Clicked += delegate { // If not logged in, 'Home' sends to login page if (!LoggedIn) { // Make login page LoginPage = new LoginPage(this); MainWindow.Content = LoginPage; } else // Else send to home page { // Make management page ManagementPage = new ManagementPage(this); MainWindow.Content = ManagementPage; } }; logoutCommand.Clicked += delegate { LoggedIn = false; DBManager.Instance.CloseDB(); // Make login page LoginPage = new LoginPage(this); MainWindow.Content = LoginPage; }; settingsCommand.Clicked += delegate { SettingsPage settingsPage = new SettingsPage(this); MainWindow.Content = settingsPage; }; MainWindow.Content = LoginPage; // First page MainWindow.MainMenu = MainMenu; }
public void CloseProperly(object sender, EventArgs e) { DBManager.Instance.CloseDB(); Application.Exit(); }