Browse Source

Solved the scroll_to issue.

merge-requests/365/head
eidheim 11 years ago
parent
commit
0be130dd94
  1. 2
      juci/notebook.cc
  2. 12
      juci/source.cc
  3. 3
      juci/source.h
  4. 10
      juci/terminal.cc

2
juci/notebook.cc

@ -81,7 +81,7 @@ void Notebook::Controller::CreateKeybindings() {
if(location.first.size()>0) { if(location.first.size()>0) {
open_file(location.first); open_file(location.first);
CurrentSourceView()->get_buffer()->place_cursor(CurrentSourceView()->get_buffer()->get_iter_at_offset(location.second)); CurrentSourceView()->get_buffer()->place_cursor(CurrentSourceView()->get_buffer()->get_iter_at_offset(location.second));
CurrentSourceView()->scroll_to_insert(); CurrentSourceView()->scroll_to(CurrentSourceView()->get_buffer()->get_insert());
} }
} }
} }

12
juci/source.cc

@ -47,7 +47,8 @@ file_path(file_path), project_path(project_path) {
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
} }
scroll_to_insert_dispatcher.connect([this](){ get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
signal_size_allocate().connect([this](Gtk::Allocation& allocation){
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
}); });
} }
@ -68,15 +69,6 @@ string Source::View::get_line_before_insert() {
return line; return line;
} }
//TODO: Fix this dirty hack. Gtk's scroll_to is bugged...
void Source::View::scroll_to_insert() {
std::thread scroll_to_insert_thread([this](){
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
scroll_to_insert_dispatcher();
});
scroll_to_insert_thread.detach();
}
//Basic indentation //Basic indentation
bool Source::View::on_key_press_event(GdkEventKey* key) { bool Source::View::on_key_press_event(GdkEventKey* key) {
auto config=Singleton::Config::source(); auto config=Singleton::Config::source();

3
juci/source.h

@ -49,7 +49,6 @@ public:
View(const std::string& file_path, const std::string& project_path); View(const std::string& file_path, const std::string& project_path);
std::string get_line(size_t line_number); std::string get_line(size_t line_number);
std::string get_line_before_insert(); std::string get_line_before_insert();
void scroll_to_insert();
std::string file_path; std::string file_path;
std::string project_path; std::string project_path;
Gtk::TextIter search_start, search_end; Gtk::TextIter search_start, search_end;
@ -57,8 +56,6 @@ public:
std::function<std::pair<std::string, unsigned>()> get_declaration_location; std::function<std::pair<std::string, unsigned>()> get_declaration_location;
protected: protected:
bool on_key_press_event(GdkEventKey* key); bool on_key_press_event(GdkEventKey* key);
private:
Glib::Dispatcher scroll_to_insert_dispatcher;
}; // class View }; // class View
class GenericView : public View { class GenericView : public View {

10
juci/terminal.cc

@ -51,6 +51,10 @@ Terminal::View::View(){
Terminal::Controller::Controller() { Terminal::Controller::Controller() {
folder_command_ = ""; folder_command_ = "";
view.text_view.signal_size_allocate().connect([this](Gtk::Allocation& allocation){
auto iter=view.text_view.get_buffer()->end();
view.text_view.scroll_to(iter);
});
} }
void Terminal::Controller::SetFolderCommand( boost::filesystem::path void Terminal::Controller::SetFolderCommand( boost::filesystem::path
@ -86,11 +90,7 @@ void Terminal::Controller::Run(std::string executable) {
int Terminal::Controller::print(std::string message){ int Terminal::Controller::print(std::string message){
INFO("Terminal: PrintMessage"); INFO("Terminal: PrintMessage");
view.text_view.get_buffer()->insert(view.text_view.get_buffer()->end(), "> "+message); view.text_view.get_buffer()->insert(view.text_view.get_buffer()->end(), "> "+message);
auto mark_end=view.text_view.get_buffer()->create_mark(view.text_view.get_buffer()->end()); return view.text_view.get_buffer()->end().get_line();
view.text_view.scroll_to(view.text_view.get_buffer()->get_insert());
auto line=mark_end->get_iter().get_line();
view.text_view.get_buffer()->delete_mark(mark_end);
return line;
} }
void Terminal::Controller::print(int line_nr, std::string message){ void Terminal::Controller::print(int line_nr, std::string message){

Loading…
Cancel
Save