Browse Source

Cleaned up entry.*. New file now works, but did simplify it abit, that is removed new header and new c++ file, hope that was ok. More cleanup of source.* too.

merge-requests/365/head
eidheim 11 years ago
parent
commit
88c83660c1
  1. 2
      juci/config.json
  2. 119
      juci/entry.cc
  3. 50
      juci/entry.h
  4. 6
      juci/menu.xml
  5. 124
      juci/notebook.cc
  6. 25
      juci/notebook.h
  7. 2
      juci/window.cc

2
juci/config.json

@ -40,8 +40,6 @@
}, },
"keybindings": { "keybindings": {
"new_file": "<control>n", "new_file": "<control>n",
"new_h_file": "<control><alt>h",
"new_cc_file": "<control><alt>c",
"open_folder": "<control><alt>o", "open_folder": "<control><alt>o",
"open_file": "<control>o", "open_file": "<control>o",
"save": "<control>s", "save": "<control>s",

119
juci/entry.cc

@ -1,74 +1,61 @@
#include "entry.h" #include "entry.h"
Entry::View::View() :
view_(Gtk::ORIENTATION_HORIZONTAL), Entry::Entry() :
button_apply_(Gtk::Stock::APPLY), Gtk::Box(Gtk::ORIENTATION_HORIZONTAL),
button_close_(Gtk::Stock::CLOSE), button_apply_set_filename(Gtk::Stock::APPLY),
button_next_("Next"), button_close(Gtk::Stock::CLOSE),
button_prev_("Prev"){ button_next("Next"),
} button_prev("Prev"){
Gtk::Box& Entry::View::view() { entry.signal_activate().connect([this](){
return view_; if(activate) {
} activate();
void Entry::View::OnShowSetFilenName(std::string exstension) {
entry_.set_max_length(50);
entry_.set_text(exstension);
view_.pack_start(entry_);
view_.pack_end(button_close_, Gtk::PACK_SHRINK);
view_.pack_end(button_apply_, Gtk::PACK_SHRINK);
}
void Entry::View::OnShowSearch(std::string current){
entry_.set_max_length(50);
entry_.set_text(current);
view_.pack_start(entry_);
view_.pack_start(button_next_, Gtk::PACK_SHRINK);
view_.pack_start(button_prev_, Gtk::PACK_SHRINK);
view_.pack_end(button_close_, Gtk::PACK_SHRINK);
}
void Entry::View::OnHideEntry(bool is_new_file)
{
view_.remove(entry_);
view_.remove(button_close_);
if(!is_new_file){
view_.remove(button_next_);
view_.remove(button_prev_);
}else{
view_.remove(button_apply_);
} }
});
entry.signal_key_press_event().connect(sigc::mem_fun(*this, &Entry::on_key_press), false);
} }
Entry::Controller::Controller() { bool Entry::on_key_press(GdkEventKey* key) {
} if(key->keyval==GDK_KEY_Escape)
Gtk::Box& Entry::Controller::view() { hide();
return view_.view(); return false;
}
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::OnShowSearch(std::string current){
view_.OnShowSearch(current);
view_.view().show_all();
view_.entry().grab_focus();
view_.entry().set_position(0);
} }
void Entry::Controller::OnHideEntries(bool is_new_file){
view_.OnHideEntry(is_new_file); void Entry::show_set_filename() {
} hide();
std::string Entry::Controller::text(){ entry.set_max_length(50);
return view_.entry().get_text(); entry.set_text("");
} pack_start(entry);
Gtk::Button& Entry::Controller::button_apply(){ pack_end(button_close, Gtk::PACK_SHRINK);
return view_.button_apply(); pack_end(button_apply_set_filename, Gtk::PACK_SHRINK);
} show_all();
Gtk::Button& Entry::Controller::button_close(){ entry.grab_focus();
return view_.button_close(); entry.set_position(0);
} activate=[this](){
Gtk::Button& Entry::Controller::button_next(){ button_apply_set_filename.clicked();
return view_.button_next(); };
} }
Gtk::Button& Entry::Controller::button_prev(){
return view_.button_prev(); void Entry::show_search(const std::string& current){
hide();
entry.set_max_length(50);
entry.set_text(current);
pack_start(entry);
pack_start(button_next, Gtk::PACK_SHRINK);
pack_start(button_prev, Gtk::PACK_SHRINK);
pack_end(button_close, Gtk::PACK_SHRINK);
show_all();
entry.grab_focus();
entry.set_position(0);
activate=[this](){
button_next.clicked();
};
}
void Entry::hide() {
auto widgets=get_children();
for(auto &w: widgets)
remove(*w);
} }
std::string Entry::operator()() {
return entry.get_text();
}

50
juci/entry.h

@ -2,43 +2,21 @@
#define JUCI_ENTRY_H_ #define JUCI_ENTRY_H_
#include <iostream> #include <iostream>
#include <functional>
#include "gtkmm.h" #include "gtkmm.h"
#include "keybindings.h"
namespace Entry {
class View {
public:
View();
Gtk::Box& view();
Gtk::Entry& entry(){return entry_;}
Gtk::Button& button_apply(){return button_apply_;};
Gtk::Button& button_close(){return button_close_;};
Gtk::Button& button_next(){return button_next_;};
Gtk::Button& button_prev(){return button_prev_;};
void OnShowSetFilenName(std::string exstension);
void OnShowSearch(std::string current);
void OnHideEntry(bool is_new_file);
protected:
Gtk::Box view_;
Gtk::Entry entry_;
Gtk::Button button_apply_, button_close_, button_next_, button_prev_;
};
class Controller {
public:
Controller();
Gtk::Box& view();
Gtk::Button& button_apply();
Gtk::Button& button_close();
Gtk::Button& button_next();
Gtk::Button& button_prev();
std::string text();
void OnShowSetFilenName(std::string exstension);
void OnShowSearch(std::string current);
void OnHideEntries(bool is_new_file);
View view_;
};// class controller
} // namespace notebook
class Entry: public Gtk::Box {
public:
Entry();
void show_set_filename();
void show_search(const std::string& current);
void hide();
std::string operator()();
Gtk::Entry entry;
Gtk::Button button_apply_set_filename, button_close, button_next, button_prev;
private:
bool on_key_press(GdkEventKey* key);
std::function<void()> activate;
};
#endif // JUCI_ENTRY_H_ #endif // JUCI_ENTRY_H_

6
juci/menu.xml

@ -1,11 +1,7 @@
<ui> <ui>
<menubar name='MenuBar'> <menubar name='MenuBar'>
<menu action='FileMenu'> <menu action='FileMenu'>
<menu action='FileNew'> <menuitem action='FileNewFile'/>
<menuitem action='FileNewStandard'/>
<menuitem action='FileNewCC'/>
<menuitem action='FileNewH'/>
</menu>
<menuitem action='FileOpenFile'/> <menuitem action='FileOpenFile'/>
<menuitem action='FileOpenFolder'/> <menuitem action='FileOpenFolder'/>
<menuitem action='FileSave'/> <menuitem action='FileSave'/>

124
juci/notebook.cc

@ -2,12 +2,6 @@
#include "notebook.h" #include "notebook.h"
#include "logging.h" #include "logging.h"
Notebook::Model::Model() {
cc_extension_ = ".cpp";
h_extension_ = ".hpp";
scrollvalue_ = 50;
}
Notebook::View::View() : notebook_() { Notebook::View::View() : notebook_() {
view_.pack2(notebook_); view_.pack2(notebook_);
view_.set_position(120); view_.set_position(120);
@ -40,31 +34,12 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::Stock::FILE)); Gtk::Stock::FILE));
keybindings.action_group_menu()-> keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewStandard", add(Gtk::Action::create("FileNewFile",
"New empty file"), "New file"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["new_file"]), .key_map()["new_file"]),
[this]() { [this]() {
is_new_file_ = true; OnFileNewFile();
OnFileNewEmptyfile();
});
keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewCC",
"New source file"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_cc_file"]),
[this]() {
is_new_file_ = true;
OnFileNewCCFile();
});
keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewH",
"New header file"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_h_file"]),
[this]() {
is_new_file_ = true;
OnFileNewHeaderFile();
}); });
keybindings.action_group_menu()-> keybindings.action_group_menu()->
add(Gtk::Action::create("WindowCloseTab", add(Gtk::Action::create("WindowCloseTab",
@ -80,7 +55,6 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["edit_find"]), .key_map()["edit_find"]),
[this]() { [this]() {
is_new_file_ = false;
OnEditSearch(); OnEditSearch();
// TODO(Oyvang) Zalox, Forgi)Create function OnEditFind(); // TODO(Oyvang) Zalox, Forgi)Create function OnEditFind();
}); });
@ -141,33 +115,41 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
INFO("Done Redo"); INFO("Done Redo");
}); });
entry_.view_.entry().signal_activate(). entry.button_apply_set_filename.signal_clicked().connect([this]() {
connect( std::string filename=entry();
[this]() { if(filename!="") {
if (is_new_file_) { if(project_path!="" && !boost::filesystem::path(filename).is_absolute())
//OnNewPage(entry_.text()); //TODO: rewrite new file (the file needs to be created before opened with Source::Controller in order to choose the correct view implementation) filename=project_path+"/"+filename;
entry_.OnHideEntries(is_new_file_); boost::filesystem::path p(filename);
} else { if(boost::filesystem::exists(p)) {
Search(true); //TODO: alert user that file already exists
} }
else {
std::ofstream f(p.string().c_str());
if(f) {
OnOpenFile(boost::filesystem::canonical(p).string());
if(project_path!="")
directories.open_folder(project_path); //TODO: Do refresh instead
}
else {
//TODO: alert user of error creating file
}
f.close();
}
}
entry.hide();
}); });
entry_.button_apply().signal_clicked(). entry.button_close.signal_clicked().
connect(
[this]() {
//OnNewPage(entry_.text()); //TODO: rewrite new file (the file needs to be created before opened with Source::Controller in order to choose the correct view implementation)
entry_.OnHideEntries(is_new_file_);
});
entry_.button_close().signal_clicked().
connect( connect(
[this]() { [this]() {
entry_.OnHideEntries(is_new_file_); entry.hide();
}); });
entry_.button_next().signal_clicked(). entry.button_next.signal_clicked().
connect( connect(
[this]() { [this]() {
Search(true); Search(true);
}); });
entry_.button_prev().signal_clicked(). entry.button_prev.signal_clicked().
connect( connect(
[this]() { [this]() {
Search(false); Search(false);
@ -184,9 +166,6 @@ Notebook::Controller::~Controller() {
Gtk::Paned& Notebook::Controller::view() { Gtk::Paned& Notebook::Controller::view() {
return view_.view(); return view_.view();
} }
Gtk::Box& Notebook::Controller::entry_view() {
return entry_.view();
}
void Notebook::Controller::OnOpenFile(std::string path) { void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file"); INFO("Notebook open file");
@ -233,28 +212,22 @@ void Notebook::Controller::OnCloseCurrentPage() {
editor_vec_.erase(editor_vec_.begin()+page); editor_vec_.erase(editor_vec_.begin()+page);
} }
} }
void Notebook::Controller::OnFileNewEmptyfile() { void Notebook::Controller::OnFileNewFile() {
entry_.OnShowSetFilenName(""); entry.show_set_filename();
}
void Notebook::Controller::OnFileNewCCFile() {
entry_.OnShowSetFilenName(model_.cc_extension_);
}
void Notebook::Controller::OnFileNewHeaderFile() {
entry_.OnShowSetFilenName(model_.h_extension_);
} }
void Notebook::Controller::OnEditCopy() { void Notebook::Controller::OnEditCopy() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(*text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_); CurrentTextView().get_buffer()->copy_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditPaste() { void Notebook::Controller::OnEditPaste() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(*text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_); CurrentTextView().get_buffer()->paste_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditCut() { void Notebook::Controller::OnEditCut() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(*text_vec_.at(CurrentPage()))->cut_clipboard(refClipboard_); CurrentTextView().get_buffer()->cut_clipboard(refClipboard_);
} }
} }
@ -263,8 +236,8 @@ std::string Notebook::Controller::GetCursorWord() {
int page = CurrentPage(); int page = CurrentPage();
std::string word; std::string word;
Gtk::TextIter start, end; Gtk::TextIter start, end;
start = Buffer(*text_vec_.at(page))->get_insert()->get_iter(); start = CurrentTextView().get_buffer()->get_insert()->get_iter();
end = Buffer(*text_vec_.at(page))->get_insert()->get_iter(); end = CurrentTextView().get_buffer()->get_insert()->get_iter();
if (!end.ends_line()) { if (!end.ends_line()) {
while (!end.ends_word()) { while (!end.ends_word()) {
end.forward_char(); end.forward_char();
@ -275,28 +248,28 @@ std::string Notebook::Controller::GetCursorWord() {
start.backward_char(); start.backward_char();
} }
} }
word = Buffer(*text_vec_.at(page))->get_text(start, end); word = CurrentTextView().get_buffer()->get_text(start, end);
// TODO(Oyvang) fix selected text // TODO(Oyvang) fix selected text
return word; return word;
} }
void Notebook::Controller::OnEditSearch() { void Notebook::Controller::OnEditSearch() {
search_match_end_ = search_match_end_ =
Buffer(*text_vec_.at(CurrentPage()))->get_iter_at_offset(0); CurrentTextView().get_buffer()->get_iter_at_offset(0);
entry_.OnShowSearch(GetCursorWord()); entry.show_search(GetCursorWord());
} }
void Notebook::Controller::Search(bool forward) { void Notebook::Controller::Search(bool forward) {
INFO("Notebook search"); INFO("Notebook search");
int page = CurrentPage(); int page = CurrentPage();
std::string search_word; std::string search_word;
search_word = entry_.text(); search_word = entry();
Gtk::TextIter test; Gtk::TextIter test;
if ( !forward ) { if ( !forward ) {
if ( search_match_start_ == 0 || if ( search_match_start_ == 0 ||
search_match_start_.get_line_offset() == 0) { search_match_start_.get_line_offset() == 0) {
search_match_start_ = Buffer(*text_vec_.at(CurrentPage()))->end(); search_match_start_ = CurrentTextView().get_buffer()->end();
} }
search_match_start_. search_match_start_.
backward_search(search_word, backward_search(search_word,
@ -306,7 +279,7 @@ void Notebook::Controller::Search(bool forward) {
search_match_end_); search_match_end_);
} else { } else {
if ( search_match_end_ == 0 ) { if ( search_match_end_ == 0 ) {
search_match_end_ = Buffer(*text_vec_.at(CurrentPage()))->begin(); search_match_end_ = CurrentTextView().get_buffer()->begin();
} }
search_match_end_. search_match_end_.
forward_search(search_word, forward_search(search_word,
@ -348,11 +321,6 @@ int Notebook::Controller::CurrentPage() {
return Notebook().get_current_page(); return Notebook().get_current_page();
} }
Glib::RefPtr<Gtk::TextBuffer>
Notebook::Controller::Buffer(Source::Controller &source) {
return source.view->get_buffer();
}
int Notebook::Controller::Pages() { int Notebook::Controller::Pages() {
return Notebook().get_n_pages(); return Notebook().get_n_pages();
} }
@ -360,14 +328,6 @@ Gtk::Notebook& Notebook::Controller::Notebook() {
return view_.notebook(); return view_.notebook();
} }
void Notebook::Controller::BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
buffer) {
buffer->signal_end_user_action().connect(
[this]() {
//UpdateHistory();
});
}
std::string Notebook::Controller::CurrentPagePath(){ std::string Notebook::Controller::CurrentPagePath(){
return text_vec_.at(CurrentPage())->view->file_path; return text_vec_.at(CurrentPage())->view->file_path;
} }

25
juci/notebook.h

@ -11,15 +11,9 @@
#include <map> #include <map>
#include <sigc++/sigc++.h> #include <sigc++/sigc++.h>
#include "clangmm.h" #include "clangmm.h"
#include "keybindings.h"
namespace Notebook { namespace Notebook {
class Model {
public:
Model();
std::string cc_extension_;
std::string h_extension_;
int scrollvalue_;
};
class View { class View {
public: public:
View(); View();
@ -35,37 +29,29 @@ namespace Notebook {
Source::Config& config, Source::Config& config,
Directories::Config& dir_cfg); Directories::Config& dir_cfg);
~Controller(); ~Controller();
Glib::RefPtr<Gtk::TextBuffer> Buffer(Source::Controller &source);
Source::View& CurrentTextView(); Source::View& CurrentTextView();
int CurrentPage(); int CurrentPage();
Gtk::Box& entry_view();
Gtk::Notebook& Notebook(); Gtk::Notebook& Notebook();
std::string CurrentPagePath(); std::string CurrentPagePath();
void OnBufferChange();
void BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
buffer);
void OnCloseCurrentPage(); void OnCloseCurrentPage();
std::string GetCursorWord(); std::string GetCursorWord();
void OnEditCopy(); void OnEditCopy();
void OnEditCut(); void OnEditCut();
void OnEditPaste(); void OnEditPaste();
void OnEditSearch(); void OnEditSearch();
void OnFileNewCCFile(); void OnFileNewFile();
void OnFileNewEmptyfile();
void OnFileNewHeaderFile();
void OnFileOpenFolder();
bool OnSaveFile(); bool OnSaveFile();
bool OnSaveFile(std::string path); bool OnSaveFile(std::string path);
void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, void OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column); Gtk::TreeViewColumn* column);
void OnOpenFile(std::string filename); void OnOpenFile(std::string filename);
bool ScrollEventCallback(GdkEventScroll* scroll_event);
int Pages(); int Pages();
Gtk::Paned& view(); Gtk::Paned& view();
void Search(bool forward); void Search(bool forward);
std::string OnSaveFileAs(); std::string OnSaveFileAs();
std::string project_path; std::string project_path;
Directories::Controller directories; Directories::Controller directories; //Todo: make private after creating open_directory()
Entry entry;
private: private:
void CreateKeybindings(Keybindings::Controller& keybindings); void CreateKeybindings(Keybindings::Controller& keybindings);
void AskToSaveDialog(); void AskToSaveDialog();
@ -73,9 +59,6 @@ namespace Notebook {
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup; Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Source::Config& source_config; Source::Config& source_config;
View view_; View view_;
Model model_;
bool is_new_file_; //TODO: Remove this
Entry::Controller entry_;
std::vector<std::unique_ptr<Source::Controller> > text_vec_; std::vector<std::unique_ptr<Source::Controller> > text_vec_;
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_; std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_;

2
juci/window.cc

@ -111,7 +111,7 @@ Window::Window() :
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry, Gtk::PACK_SHRINK);
paned_.set_position(300); paned_.set_position(300);
paned_.pack1(notebook_.view(), true, false); paned_.pack1(notebook_.view(), true, false);
paned_.pack2(terminal_.view(), true, true); paned_.pack2(terminal_.view(), true, true);

Loading…
Cancel
Save