Browse Source

Added info at bottom left line, showing line and line offset as well as number of warnings and errors.

merge-requests/365/head
eidheim 10 years ago
parent
commit
fa2f76390f
  1. 17
      src/notebook.cc
  2. 6
      src/singletons.cc
  3. 2
      src/singletons.h
  4. 35
      src/source.cc
  5. 8
      src/source.h
  6. 4
      src/tooltips.cc
  7. 18
      src/window.cc
  8. 2
      src/window.h

17
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");
}

6
src/singletons.cc

@ -17,3 +17,9 @@ Gtk::Label *Singleton::status() {
status_=std::unique_ptr<Gtk::Label>(new Gtk::Label());
return status_.get();
}
std::unique_ptr<Gtk::Label> Singleton::info_=std::unique_ptr<Gtk::Label>();
Gtk::Label *Singleton::info() {
if(!info_)
info_=std::unique_ptr<Gtk::Label>(new Gtk::Label());
return info_.get();
}

2
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> terminal_;
static std::unique_ptr<Gtk::Label> status_;
static std::unique_ptr<Gtk::Label> info_;
};
#endif // JUCI_SINGLETONS_H_

35
src/source.cc

@ -265,6 +265,10 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
});
}
get_buffer()->signal_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() {

8
src/source.h

@ -75,7 +75,11 @@ namespace Source {
std::function<size_t(const std::string &token, const std::string &text)> rename_similar_tokens;
std::function<void(View* view, const std::string &status)> on_update_status;
std::function<void(View* view, const std::string &info)> 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<Gtk::TextBuffer::Mark> mark);
std::string get_line(int line_nr);

4
src/tooltips.cc

@ -1,8 +1,8 @@
#include "tooltips.h"
#include "singletons.h"
#include <iostream>
using namespace std;
#include <iostream> //TODO: remove
using namespace std; //TODO: remove
namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE

18
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();

2
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;

Loading…
Cancel
Save