From c4089d9a574b5f9466136d30f8248ee63229ea7c Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 16 Feb 2015 11:11:50 +0100 Subject: [PATCH] BAB-17 #time 8h #comment Need to implement Entry for text name and extension to complete this notebook. --- juci/CMakeLists.txt | 1 + juci/keybindings.cc | 2 - juci/menu.cc | 47 +----------------------- juci/notebook.cc | 89 +++++++++++++++++++++++++++++++++++++++++++++ juci/notebook.h | 36 ++++++++++++++++++ juci/window.cc | 10 ++--- juci/window.h | 20 +++++----- 7 files changed, 143 insertions(+), 62 deletions(-) diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 0374908..a18463f 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -69,6 +69,7 @@ add_executable(${project_name} source window api + notebook #there is no need for extentions ) diff --git a/juci/keybindings.cc b/juci/keybindings.cc index 040f1bd..5aba847 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -1,7 +1,6 @@ #include "keybindings.h" Keybindings::Model::Model() { - std::cout<<"Keybindings: Model constructor run"< " @@ -50,7 +49,6 @@ Keybindings::Model::~Model() { } Keybindings::Controller::Controller() { - std::cout<<"Keybindings: Controller constructor run"<add(Gtk::Action::create("FileMenu", - Gtk::Stock::FILE)); - /* File->New files */ - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew", "New")); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewStandard", - Gtk::Stock::NEW, "New empty file", "Create a new file"), - [this]() { - OnFileNewEmptyfile(); - }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewCC", - "New cc file"), - Gtk::AccelKey("c"), - [this]() { - OnFileNewCCFile(); - }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewH", - "New h file"), - Gtk::AccelKey("h"), - [this]() { - OnFileNewHeaderFile(); - }); + /* File-> New files end */ keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), @@ -79,12 +59,7 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : /* START window menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", "_Window")); - keybindings_.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", - "Close tab"), - Gtk::AccelKey("w"), - [this]() { - OnWindowCloseTab(); - }); + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", "Split window"), Gtk::AccelKey("S"), @@ -136,20 +111,6 @@ Gtk::Box &Menu::Controller::view() { return menu_view_.view(keybindings_.ui_manager_menu()); } -void Menu::Controller::OnFileNewEmptyfile() { - std::cout << "New file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - -void Menu::Controller::OnFileNewCCFile() { - std::cout << "New cc file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - -void Menu::Controller::OnFileNewHeaderFile() { - std::cout << "New header file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} void Menu::Controller::OnPluginAddSnippet() { //TODO(Forgi add you snippet magic code) @@ -172,10 +133,6 @@ void Menu::Controller::OnFileOpenFolder() { //TODO(Oyvang) Legg til funksjon } -void Menu::Controller::OnWindowCloseTab() { - std::cout << "Closing tab clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} void Menu::Controller::OnEditCopy() { std::cout << "Clicked copy" << std::endl; diff --git a/juci/notebook.cc b/juci/notebook.cc index e69de29..2a309d5 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -0,0 +1,89 @@ +#include "notebook.h" + + +Notebook::View::View() : + view_(Gtk::ORIENTATION_VERTICAL){ + +} +Gtk::Box& Notebook::View::view() { + view_.pack_start(notebook_); + return view_; +} + +Notebook::Controller::Controller(Keybindings::Controller keybindings) { + scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); + source_vec_.push_back(new Source::Controller); + scrolledwindow_vec_.back()->add(source_vec_.back()->view()); + view_.notebook().append_page(*scrolledwindow_vec_.back(), "juCi++"); + + + keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", + Gtk::Stock::FILE)); + /* File->New files */ + keybindings.action_group_menu()->add(Gtk::Action::create("FileNew", "New")); + keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", + Gtk::Stock::NEW, "New empty file", "Create a new file"), + [this]() { + OnFileNewEmptyfile(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", + "New cc file"), + Gtk::AccelKey("c"), + [this]() { + OnFileNewCCFile(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", + "New h file"), + Gtk::AccelKey("h"), + [this]() { + OnFileNewHeaderFile(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", + "Close tab"), + Gtk::AccelKey("w"), + [this]() { + OnCloseCurrentPage(); + }); + +} + +Gtk::Box& Notebook::Controller::view() { + return view_.view(); +} + +void Notebook::Controller::OnNewPage(std::string name) { + + scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); + source_vec_.push_back(new Source::Controller); + scrolledwindow_vec_.back()->add(source_vec_.back()->view()); + view_.notebook().append_page(*scrolledwindow_vec_.back(), name); + view_.notebook().show_all_children(); +} + +void Notebook::Controller::OnCloseCurrentPage() { + int page = view_.notebook().get_current_page(); + view_.notebook().remove_page(page); + delete source_vec_.at(page); + delete scrolledwindow_vec_.at(page); + source_vec_.erase(source_vec_.begin()+ page); + scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page); +} + +void Notebook::Controller::OnFileNewEmptyfile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + +void Notebook::Controller::OnFileNewCCFile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + +void Notebook::Controller::OnFileNewHeaderFile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + + + + diff --git a/juci/notebook.h b/juci/notebook.h index e69de29..35adb9a 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -0,0 +1,36 @@ +#ifndef JUCI_NOTEBOOK_H_ +#define JUCI_NOTEBOOK_H_ + +#include +#include "gtkmm.h" +#include "keybindings.h" +#include "source.h" + +namespace Notebook { + class View : public Gtk::Box { + public: + View(); + Gtk::Box& view(); + Gtk::Notebook& notebook(){return notebook_;} + protected: + Gtk::Box view_; + Gtk::Notebook notebook_; + }; + class Controller { + public: + Controller(Keybindings::Controller keybindings); + Gtk::Box& view(); + void OnNewPage(std::string name); + void OnCloseCurrentPage(); + private: + View view_; + std::vector source_vec_; + std::vector scrolledwindow_vec_; + void OnFileNewEmptyfile(); + void OnFileNewCCFile(); + void OnFileNewHeaderFile(); + };// class controller +} // namespace notebook + + +#endif // JUCI_NOTEBOOK_H_ diff --git a/juci/window.cc b/juci/window.cc index 5a7ee49..6cda23c 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -2,6 +2,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), + notebook_(keybindings_), menu_(keybindings_){ set_title("juCi++"); set_default_size(600, 600); @@ -9,22 +10,19 @@ Window::Window() : keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), [this]() { - OnSystemQuit(); + OnWindowHide(); }); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); - window_box_.pack_start(source().view()); + window_box_.pack_start(notebook_.view()); show_all_children(); } // Window constructor -Source::Controller& Window::source() { - return source_; -} -void Window::OnSystemQuit() { +void Window::OnWindowHide() { hide(); } diff --git a/juci/window.h b/juci/window.h index c9f6a69..36b76a2 100644 --- a/juci/window.h +++ b/juci/window.h @@ -1,25 +1,27 @@ -#ifndef JUCI_JUCI_H_ -#define JUCI_JUCI_H_ +#ifndef JUCI_WINDOW_H_ +#define JUCI_WINDOW_H_ #include #include "gtkmm.h" #include "menu.h" -#include "source.h" +#include "notebook.h" class Window : public Gtk::Window { public: Window(); - virtual ~Window() {} + Gtk::Box window_box_; + private: Keybindings::Controller keybindings_; Menu::Controller menu_; - Source::Controller& source(); - Source::Controller source_; - Gtk::Box window_box_; + Notebook::Controller notebook_; //signal handlers - void OnSystemQuit(); + void OnWindowHide(); + }; -#endif // JUCI_JUCI_H_ + + +#endif // JUCI_WINDOW_H_