15Slide
GTKSlide::MainWindow Class Reference

The main window of GTKSlide. More...

#include <MainWindow.h>

Inherits Window.

Public Member Functions

 MainWindow (Glib::RefPtr< Gtk::Application > &application, std::shared_ptr< Grid15::Grid > &newGridPtr)
 Creates and populates the GTKSlide main window. More...
 

Protected Member Functions

void createMenuBarAndAddToMainGrid ()
 Creates a menu bar for the window and adds it to GtkSlide::MainWindow::mainGrid (it is manage()ed) More...
 
void onMenuBarNewGame ()
 Resets the grid and handles the old one if it is not saved. More...
 
void onMenuBarLoad ()
 Loads the grid from a file and updates MainWindow::saveManager. More...
 
void onMenuBarAbout ()
 
bool save ()
 Saves the grid. More...
 
bool saveAs ()
 Saves the grid to a new file and updates MainWindow::saveManager. More...
 
bool exit (GdkEventAny *event)
 Exits 15Slide after checking if the grid is saved and handeling it. More...
 
int createNotSavedDialogAndRun ()
 A helper function which creates and runs a Gtk::MessageDialog asking the user what to do with the current unsaved grid. More...
 
int createErrorDialogAndRun (std::string errorMessage, std::string details="")
 A helper function which creates and runs a Gtk::MessageDialog informing the user of an error that has occured. More...
 

Protected Attributes

Gtk::Grid mainGrid
 The Gtk::Grid used for holding MainWindow::tileGrid and MainWindow::mainMenu. More...
 
std::shared_ptr< SaveManagersaveManager {}
 A SaveManager to manage autosaving with Gtk::MenuBar. More...
 
TileGrid tileGrid
 A graphical and interactive representation of a Grid15::Grid. More...
 
std::shared_ptr< Grid15::GridgridPtr {}
 A pointer to a Grid15::Grid for use with GTKSlide classes. More...
 
Glib::RefPtr< Gtk::Application > applicationPtr {}
 The Gtk::Application assisiated with this class, because Gtk::Window::get_application() is unreliable. More...
 

Detailed Description

The main window of GTKSlide.

Author
John Jekel
Date
2018-2018

Constructor & Destructor Documentation

◆ MainWindow()

GTKSlide::MainWindow::MainWindow ( Glib::RefPtr< Gtk::Application > &  application,
std::shared_ptr< Grid15::Grid > &  newGridPtr 
)

Creates and populates the GTKSlide main window.

Parameters
applicationThe Gtk::Application being used to run the window
newGridPtrThe Grid15::Grid to use
Exceptions
Gtk::BuilderErrorIf something goes wrong during parse
Glib::Markuperror If something goes wrong during parse
Glib::FileErrorIf a file error occurs
std::runtime_errorIf a menuBar cannot be created from the glade XML

Member Function Documentation

◆ createErrorDialogAndRun()

int GTKSlide::MainWindow::createErrorDialogAndRun ( std::string  errorMessage,
std::string  details = "" 
)
protected

A helper function which creates and runs a Gtk::MessageDialog informing the user of an error that has occured.

Parameters
errorMessageThe error message to display
detailsExtra details to put (Gtk::MessageDialog::set_secondary_text)
Returns
The responce from the user (result of Gtk::MessageDialog::run)
Bug:
Parameters are not string refrences or string views (const std::string & OR std::string_view)

◆ createMenuBarAndAddToMainGrid()

void GTKSlide::MainWindow::createMenuBarAndAddToMainGrid ( )
protected

Creates a menu bar for the window and adds it to GtkSlide::MainWindow::mainGrid (it is manage()ed)

Partly based on some Gtkmm examples: https://developer.gnome.org/gtkmm-tutorial/stable/sec-menus-examples.html.en

Exceptions
Gtk::BuilderErrorIf something goes wrong during parse
Glib::MarkupErrorIf something goes wrong during parse
Glib::FileErrorIf a file error occurs
std::runtime_errorIf a something cannot be created from the glade XML

◆ createNotSavedDialogAndRun()

int GTKSlide::MainWindow::createNotSavedDialogAndRun ( )
protected

A helper function which creates and runs a Gtk::MessageDialog asking the user what to do with the current unsaved grid.

Returns
The responce from the user (result of Gtk::MessageDialog::run)

◆ exit()

bool GTKSlide::MainWindow::exit ( GdkEventAny *  event)
protected

Exits 15Slide after checking if the grid is saved and handeling it.

Parameters
eventUnused; allows connecting to Gtk::Window::signal_delete_event() which requires it
Returns
Unused; allows connecting to Gtk::Window::signal_delete_event() which requires it

◆ onMenuBarAbout()

void GTKSlide::MainWindow::onMenuBarAbout ( )
protected

◆ onMenuBarLoad()

void GTKSlide::MainWindow::onMenuBarLoad ( )
protected

Loads the grid from a file and updates MainWindow::saveManager.

◆ onMenuBarNewGame()

void GTKSlide::MainWindow::onMenuBarNewGame ( )
protected

Resets the grid and handles the old one if it is not saved.

◆ save()

bool GTKSlide::MainWindow::save ( )
protected

Saves the grid.

Returns
True if the save works, or if it does not, the user choses a valid file and not cancel

◆ saveAs()

bool GTKSlide::MainWindow::saveAs ( )
protected

Saves the grid to a new file and updates MainWindow::saveManager.

Returns
True if the user choses a valid file and did not choose cancel

Member Data Documentation

◆ applicationPtr

Glib::RefPtr<Gtk::Application> GTKSlide::MainWindow::applicationPtr {}
protected

The Gtk::Application assisiated with this class, because Gtk::Window::get_application() is unreliable.

◆ gridPtr

std::shared_ptr<Grid15::Grid> GTKSlide::MainWindow::gridPtr {}
protected

A pointer to a Grid15::Grid for use with GTKSlide classes.

◆ mainGrid

Gtk::Grid GTKSlide::MainWindow::mainGrid
protected

The Gtk::Grid used for holding MainWindow::tileGrid and MainWindow::mainMenu.

◆ saveManager

std::shared_ptr<SaveManager> GTKSlide::MainWindow::saveManager {}
protected

A SaveManager to manage autosaving with Gtk::MenuBar.

◆ tileGrid

TileGrid GTKSlide::MainWindow::tileGrid
protected

A graphical and interactive representation of a Grid15::Grid.


The documentation for this class was generated from the following files: