Browse Source

Optimilised code, added copy,paste and cut function

master
oyvang 11 years ago
parent
commit
86ec615d96
  1. 10
      juci/entry.cc
  2. 2
      juci/juci.cc
  3. 7
      juci/keybindings.cc
  4. 15
      juci/keybindings.h
  5. 75
      juci/menu.cc
  6. 24
      juci/menu.h
  7. 62
      juci/notebook.cc
  8. 6
      juci/notebook.h
  9. 6
      juci/window.cc
  10. 5
      juci/window.h

10
juci/entry.cc

@ -9,14 +9,10 @@ Entry::View::View() :
view_(Gtk::ORIENTATION_HORIZONTAL),
button_apply_(Gtk::Stock::APPLY),
button_cancel_(Gtk::Stock::CANCEL){
// container_.add(view_);
std::cout<<"View Entry"<<std::endl;
}
Gtk::Box& Entry::View::view() {
return view_;
}
void Entry::View::OnShowSetFilenName(std::string exstension) {
entry_.set_max_length(50);
entry_.set_text(exstension);
@ -30,26 +26,20 @@ void Entry::View::OnHideEntry()
view_.remove(button_cancel_);
view_.remove(button_apply_);
}
Entry::Controller::Controller() {
std::cout<<"Controller Entry"<<std::endl;
}
Gtk::Box& Entry::Controller::view() {
return view_.view();
}
Gtk::Button& Entry::Controller::button_apply(){
return view_.button_apply();
}
void Entry::Controller::OnShowSetFilenName(std::string exstension) {
view_.OnShowSetFilenName(exstension);
view_.view().show_all();
view_.entry().grab_focus();
view_.entry().set_position(0);
}
void Entry::Controller::OnHideEntries(){
view_.OnHideEntry();
}

2
juci/juci.cc

@ -1,13 +1,11 @@
#include "window.h"
int main(int argc, char *argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(
argc,
argv,
"no.sout.juci");
Window window;
return app->run(window);
}

7
juci/keybindings.cc

@ -51,16 +51,11 @@ Keybindings::Model::~Model() {
Keybindings::Controller::Controller() {
action_group_menu_ = Gtk::ActionGroup::create();
ui_manager_menu_ = Gtk::UIManager::create();
action_group_hidden_ = Gtk::ActionGroup::create();
ui_manager_hidden_ = Gtk::UIManager::create();
}
Keybindings::Controller::~Controller(){
}
void Keybindings::Controller::BuildMenu() {
try {
ui_manager_menu_->add_ui_from_string(model_.menu_ui_string());
@ -70,8 +65,6 @@ void Keybindings::Controller::BuildMenu() {
}
ui_manager_menu_->insert_action_group(action_group_menu_);
}
void Keybindings::Controller::BuildHiddenMenu() {
try {
ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string());

15
juci/keybindings.h

@ -6,7 +6,6 @@
#include "gtkmm.h"
namespace Keybindings {
class Model {
public:
Model();
@ -16,34 +15,25 @@ namespace Keybindings {
private:
std::string menu_ui_string_;
std::string hidden_ui_string_;
};
}; // Model
class Controller {
public:
Controller();
virtual ~Controller();
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() {
return action_group_menu_;
};
Glib::RefPtr<Gtk::UIManager> ui_manager_menu() {
return ui_manager_menu_;
};
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden() {
return action_group_hidden_;
};
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden() {
return ui_manager_hidden_;
};
void BuildMenu();
void BuildHiddenMenu();
protected:
Glib::RefPtr<Gtk::UIManager> ui_manager_menu_;
Glib::RefPtr<Gtk::ActionGroup> action_group_menu_;
@ -51,8 +41,7 @@ namespace Keybindings {
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_;
private:
Keybindings::Model model_;
};
};//Controller
}
#endif // JUCI_KEYBINDINGS_H_

75
juci/menu.cc

@ -1,26 +1,20 @@
#include "menu.h"
// VIEW
Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) {
Gtk::MenuBar menutest;
view_.pack_end(menutest);
}// view controller
}
Gtk::Box &Menu::View::view(
Glib::RefPtr<Gtk::UIManager> ui_manager) {
view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK);
return view_;
}
// CONTROLLER
Menu::Controller::Controller(Keybindings::Controller& keybindings) :
menu_view_(Gtk::ORIENTATION_VERTICAL),
keybindings_(keybindings) {
/* Add action to menues */
/* START file menu */
/* File-> New files end */
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile",
Gtk::Stock::OPEN),
[this]() {
@ -31,42 +25,18 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
[this]() {
OnFileOpenFolder();
});
/* END file menu */
/* START edit menu */
keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu",
Gtk::Stock::EDIT));
keybindings_.action_group_menu()->add(Gtk::Action::create("EditCopy",
Gtk::Stock::COPY),
[this]() {
OnEditCopy();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("EditCut",
Gtk::Stock::CUT),
[this]() {
OnEditCut();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("EditPaste",
Gtk::Stock::PASTE),
[this]() {
OnEditPaste();
});
/* END edit menu */
/* START window menu */
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu",
"_Window"));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow",
"Split window"),
Gtk::AccelKey("<control><alt>S"),
[this]() {
OnWindowSplitWindow();
});
/* END window menu */
/* START Plugin menu */
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu",
"_Plugins"));
/*Plugin->snippet*/
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet",
"Snippet"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet",
@ -75,9 +45,6 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
[this]() {
OnPluginAddSnippet();
});
/* End snippet */
/* END plugin menu */
/* START help menu */
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu",
Gtk::Stock::HELP));
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout",
@ -85,8 +52,6 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
[this]() {
OnHelpAbout();
});
// Hidden actions
keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"),
Gtk::AccelKey("<control><alt>K"),
[this]() {
@ -94,67 +59,35 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
});
keybindings_.BuildMenu();
keybindings_.BuildHiddenMenu();
/* END help menu */
}
}//Controller
Gtk::Box &Menu::Controller::view() {
return menu_view_.view(keybindings_.ui_manager_menu());
}
void Menu::Controller::OnPluginAddSnippet() {
//TODO(Forgi add you snippet magic code)
std::cout << "Add snipper" << std::endl;
juci_api::py::LoadPlugin("snippet");
}
// void Menu::Controller::LoadPlugin() {
// juci_api::py::LoadPlugin("plugin_name");
// }
void Menu::Controller::OnFileOpenFile() {
std::cout << "Open file clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnFileOpenFolder() {
std::cout << "Open folder clicked" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditCopy() {
std::cout << "Clicked copy" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditCut() {
std::cout << "Clicked cut" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditPaste() {
std::cout << "Clicked paste" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnEditFind() {
std::cout << "Clicked find" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnWindowSplitWindow() {
std::cout << "Clicked split window" << std::endl;
//TODO(Oyvang) Legg til funksjon
}
void Menu::Controller::OnHelpAbout() {
std::cout << "Clicked about" << std::endl;
//TODO(Oyvang) Legg til funksjon

24
juci/menu.h

@ -6,53 +6,31 @@
#include "keybindings.h"
#include "api.h"
namespace Menu {
class View {
public:
explicit View(Gtk::Orientation orient);
Gtk::Box &view(Glib::RefPtr<Gtk::UIManager> ui_manager);
protected:
Gtk::Box view_;
}; // class View
class Controller {
public:
explicit Controller(Keybindings::Controller& keybindings);
Gtk::Box &view();
private:
Keybindings::Controller keybindings_;
Keybindings::Controller &keybindings_;
View menu_view_;
void OnFileNewEmptyfile();
// Signal handlers
void OnFileNewCCFile();
void OnFileNewHeaderFile();
void OnFileOpenFile();
void OnFileOpenFolder();
void OnPluginAddSnippet();
void OnWindowCloseTab();
void OnEditCopy();
void OnEditCut();
void OnEditPaste();
void OnEditFind();
void OnWindowSplitWindow();
void OnHelpAbout();
}; // class Controller
} // namespace Menu

62
juci/notebook.cc

@ -9,20 +9,16 @@ 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++");
refClipboard = Gtk::Clipboard::get();
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"),
Gtk::Stock::NEW,
"New empty file",
"Create a new file"),
[this]() {
OnFileNewEmptyfile();
});
@ -47,37 +43,44 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
keybindings.action_group_menu()->add(Gtk::Action::create("EditFind",
Gtk::Stock::FIND),
[this]() {
// OnEditFind();
//TODO(Oyvang, Zalox, Forgi)Create function OnEditFind();
});
keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy",
Gtk::Stock::COPY),
[this]() {
OnEditCopy();
});
keybindings.action_group_menu()->add(Gtk::Action::create("EditCut",
Gtk::Stock::CUT),
[this]() {
OnEditCut();
});
keybindings.action_group_menu()->add(Gtk::Action::create("EditPaste",
Gtk::Stock::PASTE),
[this]() {
OnEditPaste();
});
entry_.view_.entry().signal_activate().connect(
[this]() {
OnNewPage(entry_.view_.entry().get_text());
entry_.OnHideEntries();
});
}
}//Constructor
Gtk::Box& Notebook::Controller::view() {
return view_.view();
}
Gtk::Box& Notebook::Controller::entry_view(){
return entry_.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();
view_.notebook().set_focus_child(*scrolledwindow_vec_.back());
view().show_all_children();
view_.notebook().set_current_page(view_.notebook().get_n_pages()-1);
}
void Notebook::Controller::OnCloseCurrentPage() {
//TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close?
int page = view_.notebook().get_current_page();
@ -87,21 +90,32 @@ void Notebook::Controller::OnCloseCurrentPage() {
source_vec_.erase(source_vec_.begin()+ page);
scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page);
}
void Notebook::Controller::OnFileNewEmptyfile() {
entry_.OnShowSetFilenName("");
//TODO(Oyvang) Legg til funksjon for Entry file name.extension
}
void Notebook::Controller::OnFileNewCCFile() {
entry_.OnShowSetFilenName(".cc");
//TODO(Oyvang) Legg til funksjon for Entry file name.extension
}
void Notebook::Controller::OnFileNewHeaderFile() {
entry_.OnShowSetFilenName(".h");
//TODO(Oyvang) Legg til funksjon for Entry file name.extension
}
void Notebook::Controller::OnEditCopy() {
std::cout << "Clicked copy" << std::endl;
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)->view().get_buffer();
buffer->copy_clipboard(refClipboard);
}
void Notebook::Controller::OnEditPaste() {
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)->view().get_buffer();
buffer->paste_clipboard(refClipboard);
};
void Notebook::Controller::OnEditCut() {
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)->view().get_buffer();
buffer->cut_clipboard(refClipboard);
}

6
juci/notebook.h

@ -28,9 +28,15 @@ namespace Notebook {
Entry::Controller entry_;
std::vector<Source::Controller*> source_vec_;
std::vector<Gtk::ScrolledWindow*> scrolledwindow_vec_;
Glib::RefPtr<Gtk::Clipboard> refClipboard;
std::list<Gtk::TargetEntry> listTargets;
void OnFileNewEmptyfile();
void OnFileNewCCFile();
void OnFileNewHeaderFile();
void OnEditCopy();
void OnEditPaste();
void OnEditCut();
};// class controller
} // namespace notebook

6
juci/window.cc

@ -5,14 +5,13 @@ Window::Window() :
notebook_(keybindings_),
menu_(keybindings_){
set_title("juCi++");
set_default_size(600, 00);
set_default_size(600, 400);
add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT),
[this]() {
OnWindowHide();
});
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group());
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group());
@ -20,10 +19,7 @@ Window::Window() :
window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook_.view());
show_all_children();
} // Window constructor
void Window::OnWindowHide() {
hide();
}

5
juci/window.h

@ -10,8 +10,6 @@ class Window : public Gtk::Window {
public:
Window();
Gtk::Box window_box_;
private:
Keybindings::Controller keybindings_;
Menu::Controller menu_;
@ -19,9 +17,6 @@ private:
//signal handlers
void OnWindowHide();
};
#endif // JUCI_WINDOW_H_

Loading…
Cancel
Save