Browse Source

Commit

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
11755ae716
  1. 2
      juci/keybindings.cc
  2. 65
      juci/menu.cc
  3. 12
      juci/notebook.cc
  4. 4
      juci/notebook.h
  5. 33
      juci/source.cc
  6. 5
      juci/source.h
  7. 4
      juci/window.cc

2
juci/keybindings.cc

@ -54,7 +54,7 @@ Keybindings::Controller::Controller() {
action_group_hidden_ = Gtk::ActionGroup::create();
ui_manager_hidden_ = Gtk::UIManager::create();
}
Keybindings::Controller::~Controller(){
Keybindings::Controller::~Controller() {
}
void Keybindings::Controller::BuildMenu() {
try {

65
juci/menu.cc

@ -4,10 +4,9 @@ Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) {
Gtk::MenuBar menutest;
view_.pack_end(menutest);
}
Gtk::Box &Menu::View::view(
Glib::RefPtr<Gtk::UIManager> ui_manager) {
Glib::RefPtr<Gtk::UIManager> ui_manager) {
view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK);
return view_;
}
@ -15,48 +14,46 @@ Gtk::Box &Menu::View::view(
Menu::Controller::Controller(Keybindings::Controller& keybindings) :
menu_view_(Gtk::ORIENTATION_VERTICAL),
keybindings_(keybindings) {
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile",
Gtk::Stock::OPEN),
[this]() {
OnFileOpenFile();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
Gtk::Stock::FILE));
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder",
"Open folder"),
[this]() {
OnFileOpenFolder();
});
"Open folder"),
[this]() {
OnFileOpenFolder();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu",
Gtk::Stock::EDIT));
Gtk::Stock::EDIT));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu",
"_Window"));
"_Window"));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow",
"Split window"),
Gtk::AccelKey("<control><alt>S"),
[this]() {
OnWindowSplitWindow();
});
"Split window"),
Gtk::AccelKey("<control><alt>S"),
[this]() {
OnWindowSplitWindow();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu",
"_Plugins"));
"_Plugins"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet",
"Snippet"));
"Snippet"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet",
"Add snippet"),
Gtk::AccelKey("<alt>space"),
[this]() {
OnPluginAddSnippet();
});
"Add snippet"),
Gtk::AccelKey("<alt>space"),
[this]() {
OnPluginAddSnippet();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu",
Gtk::Stock::HELP));
Gtk::Stock::HELP));
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout",
Gtk::Stock::ABOUT),
[this]() {
OnHelpAbout();
});
Gtk::Stock::ABOUT),
[this]() {
OnHelpAbout();
});
keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"),
Gtk::AccelKey("<control><alt>K"),
[this]() {
OnHelpAbout();
});
Gtk::AccelKey("<control><alt>K"),
[this]() {
OnHelpAbout();
});
keybindings_.BuildMenu();
keybindings_.BuildHiddenMenu();
} // Controller

12
juci/notebook.cc

@ -108,7 +108,7 @@ void Notebook::Controller::OnFileNewHeaderFile() {
entry_.OnShowSetFilenName(".h");
}
void Notebook::Controller::OnEditCopy() {
if(view_.notebook().get_n_pages()!=0){
if (view_.notebook().get_n_pages() != 0) {
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)
->view().get_buffer();
@ -116,7 +116,7 @@ void Notebook::Controller::OnEditCopy() {
}
}
void Notebook::Controller::OnEditPaste() {
if(view_.notebook().get_n_pages()!=0){
if (view_.notebook().get_n_pages() != 0) {
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)
->view().get_buffer();
@ -124,7 +124,7 @@ void Notebook::Controller::OnEditPaste() {
}
}
void Notebook::Controller::OnEditCut() {
if(view_.notebook().get_n_pages()!=0){
if (view_.notebook().get_n_pages() != 0) {
int source_pos = view_.notebook().get_current_page();
Glib::RefPtr<Gtk::TextBuffer> buffer = source_vec_.at(source_pos)
->view().get_buffer();
@ -132,12 +132,12 @@ void Notebook::Controller::OnEditCut() {
}
}
void Notebook::Controller::OnOpenFile(std::string name, std::string content){
void Notebook::Controller::OnOpenFile(std::string filename) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->view().get_buffer()->set_text(content);
view_.notebook().append_page(*scrolledwindow_vec_.back(), name);
source_vec_.back()->OnOpenFile(filename);
view_.notebook().append_page(*scrolledwindow_vec_.back(), filename);
view_.notebook().show_all_children();
view_.notebook().set_focus_child(*scrolledwindow_vec_.back());
view_.notebook().set_current_page(view_.notebook().get_n_pages()-1);

4
juci/notebook.h

@ -11,7 +11,7 @@ namespace Notebook {
public:
View();
Gtk::Box& view();
Gtk::Notebook& notebook(){return notebook_;}
Gtk::Notebook& notebook() { return notebook_; }
protected:
Gtk::Box view_;
Gtk::Notebook notebook_;
@ -23,6 +23,7 @@ namespace Notebook {
Gtk::Box& entry_view();
void OnNewPage(std::string name);
void OnCloseCurrentPage();
void OnOpenFile(std::string filename);
private:
View view_;
Entry::Controller entry_;
@ -36,7 +37,6 @@ namespace Notebook {
void OnEditCopy();
void OnEditPaste();
void OnEditCut();
void OnOpenFile(std::string name, std::string content);
}; // class controller
} // namespace Notebook

33
juci/source.cc

@ -14,6 +14,7 @@ Source::View::View() {
// returns the new line
string Source::View::UpdateLine() {
Gtk::TextIter line(get_buffer()->get_insert()->get_iter());
// std::cout << line.get_line() << std::endl;
// for each word --> check what it is --> apply appropriate tag
return "";
}
@ -41,9 +42,18 @@ void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
int linum = loc.line_number();
int begin = loc.begin();
int end = loc.end();
buffer->apply_tag_by_name(theme.tagtable().at(type),
if(end < 0) end = 0;
if(begin < 0) begin = 0;
// for (auto &i : theme.tagtable()) {
// std::cout << "first: "<< i.first << " second: "<< i.second << std::endl;
// }
// std::cout << "type: " << type << std::endl;
buffer->apply_tag_by_name(theme.typetable().at(type),
buffer->get_iter_at_line_offset(linum, begin),
buffer->get_iter_at_line_offset(linum, end));
// std::cout << "This is a ans" << std::endl;
}
}
// Source::View::Theme::tagtable()
@ -52,11 +62,27 @@ const std::unordered_map<string, string>& Source::Theme::tagtable() const {
return tagtable_;
}
// Source::View::Theme::tagtable()
// returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::typetable() const {
return typetable_;
}
void Source::Theme::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTypeTable(
const std::unordered_map<string, string> &typetable) {
typetable_ = typetable;
}
void Source::Theme::InsertType(const string &key, const string &value) {
typetable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTagTable(
const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable;
@ -75,6 +101,11 @@ Source::Model::Model() :
for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file
theme_.InsertTag(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting tag. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
if (i.first.compare("colors")) { // checks the config-file
theme_.InsertType(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
}
}

5
juci/source.h

@ -13,10 +13,15 @@ namespace Source {
class Theme {
public:
const std::unordered_map<string, string>& tagtable() const;
const std::unordered_map<string, string>& typetable() const;
void SetTagTable(const std::unordered_map<string, string> &tagtable);
void InsertTag(const string &key, const string &value);
void SetTypeTable(const std::unordered_map<string, string> &tagtable);
void InsertType(const string &key, const string &value);
private:
std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_;
string background_;
}; // class Theme

4
juci/window.cc

@ -62,11 +62,9 @@ void Window::OnOpenFile() {
switch (result) {
case(Gtk::RESPONSE_OK): {
std::cout << "Open clicked." << std::endl;
std::string path = dialog.get_filename();
std::cout << "File selected: " << path << std::endl;
Source::Controller sourcefile;
notebook_.OnOpenFile(path, sourcefile.OnOpenFile(path));
notebook_.OnOpenFile(path);
break;
}
case(Gtk::RESPONSE_CANCEL): {

Loading…
Cancel
Save