11 changed files with 232 additions and 47 deletions
@ -0,0 +1,35 @@
|
||||
#include "controller.h" |
||||
|
||||
Controller::Menu::Menu() : |
||||
menu_view(Gtk::ORIENTATION_VERTICAL), |
||||
menu_model() { |
||||
/*Add action to menues*/ |
||||
menu_view.get_action_group()->add(Gtk::Action::create("FileMenu", "File")); |
||||
|
||||
menu_view.get_action_group()->add(Gtk::Action::create("FileNewStandard", |
||||
Gtk::Stock::NEW, "New empty file", "Create a new file"), |
||||
[this]() { |
||||
onNewEmptyfile(); |
||||
}); |
||||
|
||||
|
||||
|
||||
menu_view.set_ui_manager_action_group(menu_view.get_action_group()); |
||||
menu_view.set_ui_manger_string(menu_model.get_ui_string()); |
||||
} |
||||
|
||||
Controller::Menu::~Menu() { |
||||
|
||||
} |
||||
|
||||
Gtk::Box &Controller::Menu::get_view() { |
||||
return menu_view.get_view(); |
||||
} |
||||
|
||||
void Controller::Menu::onNewEmptyfile() { |
||||
std::cout << "New file clicked"<< std::endl; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#include "view.h" |
||||
#include "juci.h" |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
Glib::RefPtr <Gtk::Application> app = Gtk::Application::create(argc, argv, "org.bachelor.juci"); |
||||
|
||||
View view; |
||||
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "no.sout.juci"); |
||||
Window window; |
||||
|
||||
return app->run(view); |
||||
return app->run(window);; |
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
/*juCi++ main header file*/ |
||||
#ifndef JUCI_H |
||||
#define JUCI_H |
||||
|
||||
#include <iostream> |
||||
#include "gtkmm.h" |
||||
#include "view.h" |
||||
#include "model.h" |
||||
#include "controller.h" |
||||
|
||||
|
||||
class Window : public Gtk::Window { |
||||
public: |
||||
Window(); |
||||
|
||||
virtual ~Window(); |
||||
|
||||
Gtk::Box window_box; |
||||
|
||||
private: |
||||
Controller::Menu menu; |
||||
/*signal handler*/ |
||||
void onSystemQuit(); |
||||
|
||||
}; |
||||
|
||||
#endif // JUCI_H
|
||||
@ -0,0 +1,16 @@
|
||||
#include "model.h" |
||||
|
||||
Model::Menu::Menu() { |
||||
ui_string = |
||||
"<ui> " |
||||
" <menubar name='MenuBar'> " |
||||
" <menu action='FileMenu'> " |
||||
" <menuitem action='FileNewStandard'/> " |
||||
" <menuitem action='FileQuit'/> " |
||||
" </menu> " |
||||
" </menubar> " |
||||
"</ui> "; |
||||
} |
||||
|
||||
Model::Menu::~Menu() { |
||||
} |
||||
@ -1,19 +0,0 @@
|
||||
#include "view.h" |
||||
|
||||
View::View() : |
||||
window_box(Gtk::ORIENTATION_VERTICAL){ |
||||
|
||||
set_title("juCi++"); |
||||
set_default_size(800, 600); |
||||
maximize(); |
||||
|
||||
add(window_box); |
||||
|
||||
/*Add default views here */ |
||||
|
||||
show_all_children(); |
||||
|
||||
}; |
||||
View::~View() { |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
|
||||
#include "view.h" |
||||
|
||||
|
||||
/***********************************/ |
||||
/* MENU */ |
||||
/***********************************/ |
||||
View::Menu::Menu(Gtk::Orientation orientation) : |
||||
view(orientation) { |
||||
|
||||
action_group = Gtk::ActionGroup::create(); |
||||
ui_manager = Gtk::UIManager::create(); |
||||
|
||||
|
||||
} |
||||
|
||||
void View::Menu::set_ui_manger_string(std::string ui_string) { |
||||
try { |
||||
ui_manager->add_ui_from_string(ui_string); |
||||
} |
||||
catch (const Glib::Error &ex) { |
||||
std::cerr << "building menus failed: " << ex.what(); |
||||
} |
||||
} |
||||
|
||||
void View::Menu::set_ui_manager_action_group(Glib::RefPtr<Gtk::ActionGroup> action_group) { |
||||
ui_manager->insert_action_group(action_group); |
||||
} |
||||
|
||||
Gtk::Box &View::Menu::get_view() { |
||||
view.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK); |
||||
return view; |
||||
} |
||||
|
||||
|
||||
View::Menu::~Menu() { |
||||
} |
||||
@ -0,0 +1,33 @@
|
||||
#include "juci.h" |
||||
|
||||
Window::Window() : |
||||
window_box(Gtk::ORIENTATION_HORIZONTAL), |
||||
menu() { |
||||
|
||||
|
||||
set_title("example juCi++"); |
||||
set_default_size(600, 600); |
||||
|
||||
add(window_box); |
||||
menu.get_action_group()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), |
||||
[this]() { |
||||
onSystemQuit(); |
||||
}); |
||||
|
||||
add_accel_group(menu.get_ui_manager()->get_accel_group()); |
||||
|
||||
window_box.pack_start(menu.get_view()); |
||||
|
||||
|
||||
show_all_children(); |
||||
}; |
||||
|
||||
void Window::onSystemQuit() { |
||||
hide(); |
||||
} |
||||
|
||||
Window::~Window() { |
||||
|
||||
} |
||||
|
||||
|
||||
Loading…
Reference in new issue