From fa2f76390ff307b0ecdfad5e7d05facbb6ee4032 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 9 Sep 2015 21:34:45 +0200 Subject: [PATCH] Added info at bottom left line, showing line and line offset as well as number of warnings and errors. --- src/notebook.cc | 17 +++++++++++++---- src/singletons.cc | 6 ++++++ src/singletons.h | 2 ++ src/source.cc | 35 +++++++++++++++++++++++++++++++++-- src/source.h | 8 +++++--- src/tooltips.cc | 4 ++-- src/window.cc | 18 ++++++++++++------ src/window.h | 2 +- 8 files changed, 74 insertions(+), 18 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 4c382e9..37bcefd 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -83,6 +83,18 @@ void Notebook::open(const boost::filesystem::path &file_path) { } else source_views.emplace_back(new Source::GenericView(file_path, language)); + + source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) { + if(get_current_page()!=-1 && get_current_view()==view) + Singleton::status()->set_text(status+" "); + }; + source_views.back()->on_update_info=[this](Source::View* view, const std::string &info) { + if(get_current_page()!=-1 && get_current_view()==view) { + auto iter=get_current_view()->get_buffer()->get_insert()->get_iter(); + auto positions=std::to_string(iter.get_line()+1)+":"+std::to_string(iter.get_line_offset()+1); + Singleton::info()->set_text(" "+positions+" "+info); + } + }; scrolled_windows.emplace_back(new Gtk::ScrolledWindow()); hboxes.emplace_back(new Gtk::HBox()); @@ -90,6 +102,7 @@ void Notebook::open(const boost::filesystem::path &file_path) { hboxes.back()->pack_start(*scrolled_windows.back(), true, true); std::string title=file_path.filename().string(); + append_page(*hboxes.back(), title); set_tab_reorderable(*hboxes.back(), true); show_all_children(); @@ -114,10 +127,6 @@ void Notebook::open(const boost::filesystem::path &file_path) { set_tab_label_text(*(get_nth_page(page)), title); }); - get_current_view()->on_update_status=[this](Source::View* view, const std::string &status) { - if(get_current_page()!=-1 && get_current_view()==view) - Singleton::status()->set_text(status); - }; DEBUG("end"); } diff --git a/src/singletons.cc b/src/singletons.cc index dd9d926..4633763 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -17,3 +17,9 @@ Gtk::Label *Singleton::status() { status_=std::unique_ptr(new Gtk::Label()); return status_.get(); } +std::unique_ptr Singleton::info_=std::unique_ptr(); +Gtk::Label *Singleton::info() { + if(!info_) + info_=std::unique_ptr(new Gtk::Label()); + return info_.get(); +} diff --git a/src/singletons.h b/src/singletons.h index de07113..8fa6a86 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -31,9 +31,11 @@ public: static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static Terminal *terminal(); static Gtk::Label *status(); + static Gtk::Label *info(); private: static std::unique_ptr terminal_; static std::unique_ptr status_; + static std::unique_ptr info_; }; #endif // JUCI_SINGLETONS_H_ diff --git a/src/source.cc b/src/source.cc index 1bb3654..ae3e1d3 100644 --- a/src/source.cc +++ b/src/source.cc @@ -265,6 +265,10 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtrsignal_changed().connect([this](){ + set_info(info); + }); + set_tooltip_events(); } @@ -316,6 +320,7 @@ void Source::View::set_tooltip_events() { }, 500); type_tooltips.hide(); diagnostic_tooltips.hide(); + set_info(info); } }); @@ -530,6 +535,12 @@ void Source::View::set_status(const std::string &status) { on_update_status(this, status); } +void Source::View::set_info(const std::string &info) { + this->info=info; + if(on_update_info) + on_update_info(this, this->info); +} + std::string Source::View::get_line(const Gtk::TextIter &iter) { auto line_start_it = get_buffer()->get_iter_at_line(iter.get_line()); auto line_end_it = iter; @@ -1185,6 +1196,8 @@ void Source::ClangViewParse::update_diagnostics() { get_buffer()->remove_tag_by_name("def:warning_underline", get_buffer()->begin(), get_buffer()->end()); get_buffer()->remove_tag_by_name("def:error_underline", get_buffer()->begin(), get_buffer()->end()); auto diagnostics=clang_tu->get_diagnostics(); + size_t warnings=0; + size_t errors=0; for(auto &diagnostic: diagnostics) { if(diagnostic.path==file_path.string()) { auto start_line=get_line(diagnostic.offsets.first.line-1); //index is sometimes off the line @@ -1206,10 +1219,14 @@ void Source::ClangViewParse::update_diagnostics() { auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, start_line_index); auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, end_line_index); std::string diagnostic_tag_name; - if(diagnostic.severity<=CXDiagnostic_Warning) + if(diagnostic.severity<=CXDiagnostic_Warning) { diagnostic_tag_name="def:warning"; - else + warnings++; + } + else { diagnostic_tag_name="def:error"; + errors++; + } auto spelling=diagnostic.spelling; auto severity_spelling=diagnostic.severity_spelling; @@ -1230,6 +1247,20 @@ void Source::ClangViewParse::update_diagnostics() { } } } + std::string diagnostic_info; + if(warnings>0) { + diagnostic_info+=std::to_string(warnings)+" warning"; + if(warnings>1) + diagnostic_info+='s'; + } + if(errors>0) { + if(warnings>0) + diagnostic_info+=", "; + diagnostic_info+=std::to_string(errors)+" error"; + if(errors>1) + diagnostic_info+='s'; + } + set_info(" "+diagnostic_info); } void Source::ClangViewParse::update_types() { diff --git a/src/source.h b/src/source.h index 2d80aad..8fd6409 100644 --- a/src/source.h +++ b/src/source.h @@ -75,7 +75,11 @@ namespace Source { std::function rename_similar_tokens; std::function on_update_status; + std::function on_update_info; + void set_status(const std::string &status); + void set_info(const std::string &info); std::string status; + std::string info; protected: bool source_readable; Tooltips diagnostic_tooltips; @@ -84,9 +88,7 @@ namespace Source { gdouble on_motion_last_y; sigc::connection delayed_tooltips_connection; void set_tooltip_events(); - - void set_status(const std::string &status); - + std::string get_line(const Gtk::TextIter &iter); std::string get_line(Glib::RefPtr mark); std::string get_line(int line_nr); diff --git a/src/tooltips.cc b/src/tooltips.cc index 113ce64..f5082d9 100644 --- a/src/tooltips.cc +++ b/src/tooltips.cc @@ -1,8 +1,8 @@ #include "tooltips.h" #include "singletons.h" -#include -using namespace std; +#include //TODO: remove +using namespace std; //TODO: remove namespace sigc { #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE diff --git a/src/window.cc b/src/window.cc index 3b09318..3164382 100644 --- a/src/window.cc +++ b/src/window.cc @@ -54,8 +54,9 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil terminal_scrolled_window.add(*Singleton::terminal()); terminal_vbox.pack_start(terminal_scrolled_window); - status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK); - terminal_vbox.pack_end(status_hbox, Gtk::PACK_SHRINK); + info_and_status_hbox.pack_start(*Singleton::info(), Gtk::PACK_SHRINK); + info_and_status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK); + terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK); vpaned.pack2(terminal_vbox, true, true); box.pack_end(vpaned); @@ -110,7 +111,8 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil } } - Singleton::status()->set_text(notebook.get_current_view()->status); + notebook.get_current_view()->set_status(notebook.get_current_view()->status); + notebook.get_current_view()->set_info(notebook.get_current_view()->info); } }); notebook.signal_page_removed().connect([this](Gtk::Widget* page, guint page_num) { @@ -322,10 +324,14 @@ void Window::create_menu() { }); menu.action_group->add(Gtk::Action::create("WindowCloseTab", "Close Tab"), Gtk::AccelKey(menu.key_map["close_tab"]), [this]() { notebook.close_current_page(); - if(notebook.get_current_page()!=-1) - Singleton::status()->set_text(notebook.get_current_view()->status); - else + if(notebook.get_current_page()!=-1) { + notebook.get_current_view()->set_status(notebook.get_current_view()->status); + notebook.get_current_view()->set_info(notebook.get_current_view()->info); + } + else { Singleton::status()->set_text(""); + Singleton::info()->set_text(""); + } }); menu.action_group->add(Gtk::Action::create("HelpAbout", "About"), [this] () { about.show(); diff --git a/src/window.h b/src/window.h index 693b526..5c8b349 100644 --- a/src/window.h +++ b/src/window.h @@ -33,7 +33,7 @@ private: Gtk::VBox notebook_vbox; Gtk::VBox terminal_vbox; Gtk::ScrolledWindow terminal_scrolled_window; - Gtk::HBox status_hbox; + Gtk::HBox info_and_status_hbox; Gtk::AboutDialog about; EntryBox entry_box; Menu menu;