Browse Source

Small cleanup, and fixed potential segmentation/assertion fault. Tooltips now also get hidden when using mouse scroll.

merge-requests/365/head
eidheim 11 years ago
parent
commit
f13ca76ad3
  1. 62
      juci/source.cc
  2. 3
      juci/source.h
  3. 2
      juci/window.cc

62
juci/source.cc

@ -185,9 +185,9 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
update_syntax(extract_tokens(0, get_source_buffer()->get_text().size()));
update_diagnostics();
update_types();
clang_updated=true;
parsing_in_progress->done("done");
INFO("Syntax updated");
clang_tokens_ready=true;
}
else {
parse_thread_go=true;
@ -216,7 +216,7 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
get_source_buffer()->signal_changed().connect([this]() {
parse_thread_mapped=false;
clang_tokens_ready=false;
clang_updated=false;
parse_thread_go=true;
});
@ -224,6 +224,7 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
signal_key_release_event().connect(sigc::mem_fun(*this, &Source::ClangView::on_key_release), false);
signal_motion_notify_event().connect(sigc::mem_fun(*this, &Source::ClangView::clangview_on_motion_notify_event), false);
signal_focus_out_event().connect(sigc::mem_fun(*this, &Source::ClangView::clangview_on_focus_out_event), false);
signal_scroll_event().connect(sigc::mem_fun(*this, &Source::ClangView::clangview_on_scroll_event), false);
get_buffer()->signal_mark_set().connect(sigc::mem_fun(*this, &Source::ClangView::clangview_on_mark_set), false);
}
@ -408,11 +409,9 @@ void Source::ClangView::update_types() {
auto get_tooltip_buffer=[this, c]() {
auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table());
tooltip_buffer->insert_at_cursor("Type: "+(*clang_tokens)[c].type);
if(clang_tokens_ready) {
auto brief_comment=clang_tokens->get_brief_comment(c);
if(brief_comment!="")
tooltip_buffer->insert_at_cursor("\n\n"+brief_comment);
}
auto brief_comment=clang_tokens->get_brief_comment(c);
if(brief_comment!="")
tooltip_buffer->insert_at_cursor("\n\n"+brief_comment);
return tooltip_buffer;
};
@ -423,34 +422,53 @@ void Source::ClangView::update_types() {
}
bool Source::ClangView::clangview_on_motion_notify_event(GdkEventMotion* event) {
Gdk::Rectangle rectangle(event->x, event->y, 1, 1);
diagnostic_tooltips.init();
type_tooltips.show(rectangle);
diagnostic_tooltips.show(rectangle);
if(clang_updated) {
Gdk::Rectangle rectangle(event->x, event->y, 1, 1);
diagnostic_tooltips.init();
type_tooltips.show(rectangle);
diagnostic_tooltips.show(rectangle);
}
else {
type_tooltips.hide();
diagnostic_tooltips.hide();
}
return false;
}
void Source::ClangView::clangview_on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark) {
if(mark->get_name()=="insert") {
Gdk::Rectangle rectangle;
get_iter_location(iterator, rectangle);
int location_window_x, location_window_y;
buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, rectangle.get_x(), rectangle.get_y(), location_window_x, location_window_y);
rectangle.set_x(location_window_x-2);
rectangle.set_y(location_window_y);
rectangle.set_width(4);
diagnostic_tooltips.init();
type_tooltips.show(rectangle);
diagnostic_tooltips.show(rectangle);
if(clang_updated) {
Gdk::Rectangle rectangle;
get_iter_location(iterator, rectangle);
int location_window_x, location_window_y;
buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, rectangle.get_x(), rectangle.get_y(), location_window_x, location_window_y);
rectangle.set_x(location_window_x-2);
rectangle.set_y(location_window_y);
rectangle.set_width(4);
diagnostic_tooltips.init();
type_tooltips.show(rectangle);
diagnostic_tooltips.show(rectangle);
}
else {
type_tooltips.hide();
diagnostic_tooltips.hide();
}
}
}
bool Source::ClangView::clangview_on_focus_out_event(GdkEventFocus* event) {
diagnostic_tooltips.hide();
type_tooltips.hide();
diagnostic_tooltips.hide();
return false;
}
bool Source::ClangView::clangview_on_scroll_event(GdkEventScroll* event) {
type_tooltips.hide();
diagnostic_tooltips.hide();
return false;
}
void Source::ClangView::
highlight_cursor(clang::Token *token,
std::vector<Source::Range> *source_ranges) {

3
juci/source.h

@ -102,6 +102,7 @@ namespace Source {
bool clangview_on_motion_notify_event(GdkEventMotion* event);
void clangview_on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark);
bool clangview_on_focus_out_event(GdkEventFocus* event);
bool clangview_on_scroll_event(GdkEventScroll* event);
static clang::Index clang_index;
std::map<std::string, std::string> get_buffer_map() const;
@ -109,7 +110,7 @@ namespace Source {
private:
std::unique_ptr<clang::TranslationUnit> clang_tu;
std::unique_ptr<clang::Tokens> clang_tokens;
bool clang_tokens_ready=false;
bool clang_updated=false;
void highlight_token(clang::Token *token,
std::vector<Range> *source_ranges,
int token_kind);

2
juci/window.cc

@ -13,7 +13,7 @@ Window::Window() :
INFO("Create Window");
set_title("juCi++");
set_default_size(600, 400);
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK);
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
add(window_box_);
keybindings.action_group_menu()->add(Gtk::Action::create("FileQuit",
"Quit juCi++"),

Loading…
Cancel
Save