From a10a0dc3c078417ad3f3062687af86ad29fe9b2c Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 21 Jun 2015 16:08:24 +0200 Subject: [PATCH] Fixed marking of changed tabs that are not saved. --- juci/notebook.cc | 7 +++---- juci/source.cc | 22 +++++++++++++--------- juci/source.h | 1 + 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 2d4166f..0f55682 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -301,18 +301,16 @@ Gtk::Box& Notebook::Controller::entry_view() { void Notebook::Controller::OnNewPage(std::string name) { INFO("Notebook Generate new page"); OnCreatePage(); - text_vec_.back()->on_new_empty_file(); Notebook().append_page(*editor_vec_.back(), name); Notebook().show_all_children(); Notebook().set_current_page(Pages()-1); Notebook().set_focus_child(text_vec_.at(Pages()-1)->view); - + text_vec_.back()->on_new_empty_file(); } void Notebook::Controller::OnOpenFile(std::string path) { INFO("Notebook open file"); OnCreatePage(); - text_vec_.back()->on_open_file(path); size_t pos = path.find_last_of("/\\"); std::string filename=path; if(pos!=std::string::npos) @@ -321,6 +319,7 @@ void Notebook::Controller::OnOpenFile(std::string path) { Notebook().show_all_children(); Notebook().set_current_page(Pages()-1); Notebook().set_focus_child(text_vec_.back()->view); + text_vec_.back()->on_open_file(path); } void Notebook::Controller::OnCreatePage() { @@ -339,7 +338,7 @@ void Notebook::Controller::OnCreatePage() { std::string filename=path; if(pos!=std::string::npos) filename=path.substr(pos+1); - Notebook().set_tab_label_text(*Notebook().get_nth_page(CurrentPage()), filename+"*"); + Notebook().set_tab_label_text(*(Notebook().get_nth_page(CurrentPage())), filename+"*"); } }; } diff --git a/juci/source.cc b/juci/source.cc index cd9eab4..d8442e7 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -183,7 +183,7 @@ highlight_token(clang::Token *token, // Constructor for Controller Source::Controller::Controller(const Source::Config &config, const std::vector > &controllers) : - config(config), parser(controllers), parse_thread_go(false), parse_thread_mapped(false), parse_thread_stop(false) { + config(config), parser(controllers), parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) { INFO("Source Controller with childs constructed"); view.signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::on_key_press), false); view.set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); @@ -194,13 +194,6 @@ Source::Controller::Controller(const Source::Config &config, for (auto &item : config.tags) { buffer()->create_tag(item.first)->property_foreground() = item.second; } - buffer()->signal_changed().connect([this]() { - if(signal_buffer_changed) - signal_buffer_changed(is_saved); - is_saved=false; - parse_thread_mapped=false; - parse_thread_go=true; - }); } Source::Controller::~Controller() { @@ -238,12 +231,23 @@ void Source::Controller::update_syntax(const std::vector &ranges) } } +void Source::Controller::set_handlers() { + buffer()->signal_changed().connect([this]() { + if(signal_buffer_changed) + signal_buffer_changed(is_saved); + is_saved=false; + parse_thread_mapped=false; + parse_thread_go=true; + }); +} + void Source::Controller::on_new_empty_file() { string filename("/tmp/untitled"); sourcefile s(filename); parser.file_path=filename; parser.project_path=filename; s.save(""); + set_handlers(); } void Source::Controller::on_open_file(const string &filepath) { @@ -253,8 +257,8 @@ void Source::Controller::on_open_file(const string &filepath) { buffer_map[filepath] = s.get_content(); buffer()->get_undo_manager()->begin_not_undoable_action(); buffer()->set_text(s.get_content()); - is_saved=true; buffer()->get_undo_manager()->end_not_undoable_action(); + set_handlers(); int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); if (config.legal_extension(filepath.substr(filepath.find_last_of(".") + 1))) { diff --git a/juci/source.h b/juci/source.h index 99ede6b..6469915 100644 --- a/juci/source.h +++ b/juci/source.h @@ -107,6 +107,7 @@ namespace Source { const std::vector > &controllers); ~Controller(); void update_syntax(const std::vector &locations); + void set_handlers(); void on_new_empty_file(); void on_open_file(const std::string &filename); Glib::RefPtr buffer();