Browse Source

Fixes to #317: Use primary-left click to move to implementation or declaration

merge-requests/365/head
eidheim 9 years ago
parent
commit
cfeef6c618
  1. 23
      src/source.cc
  2. 2
      src/source.h
  3. 42
      src/source_clang.cc

23
src/source.cc

@ -2213,6 +2213,7 @@ bool Source::View::on_key_press_event_smart_inserts(GdkEventKey *key) {
}
bool Source::View::on_button_press_event(GdkEventButton *event) {
// Select range when double clicking
if(event->type==GDK_2BUTTON_PRESS) {
Gtk::TextIter start, end;
get_buffer()->get_selection_bounds(start, end);
@ -2230,14 +2231,32 @@ bool Source::View::on_button_press_event(GdkEventButton *event) {
return true;
}
// Go to implementation or declaration
if((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){
if(event->state & GDK_CONTROL_MASK) {
hide_tooltips();
#ifdef __APPLE__
GdkModifierType mask=GDK_MOD2_MASK;
#else
GdkModifierType mask=GDK_CONTROL_MASK;
#endif
if(event->state & mask) {
int x, y;
window_to_buffer_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, event->x, event->y, x, y);
Gtk::TextIter iter;
get_iter_at_location(iter, x, y);
if(iter)
get_buffer()->place_cursor(iter);
if(is_implementation_location) {
if(is_implementation_location())
Menu::get().actions["source_goto_declaration"]->activate();
else
Menu::get().actions["source_goto_implementation"]->activate();
return true;
}
}
}
// Open right click menu
if((event->type == GDK_BUTTON_PRESS) && (event->button == 3)){
hide_tooltips();
if(!get_buffer()->get_has_selection()){

2
src/source.h

@ -68,7 +68,7 @@ namespace Source {
std::function<void()> non_interactive_completion;
std::function<void()> format_style;
std::function<Offset()> get_declaration_location;
std::function<bool()> is_implementation;
std::function<bool()> is_implementation_location;
std::function<std::vector<Offset>(const std::vector<Source::View*> &views)> get_implementation_locations;
std::function<std::vector<std::pair<Offset, std::string> >(const std::vector<Source::View*> &views)> get_usages;
std::function<std::string()> get_method;

42
src/source_clang.cc

@ -1012,18 +1012,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
}
});
get_declaration_location=[this](){
if(!parsed) {
Info::get().print("Buffer is parsing");
return Offset();
}
auto identifier=get_identifier();
if(identifier) {
auto source_location=identifier.cursor.get_canonical().get_source_location();
auto offset=source_location.get_offset();
return Offset(offset.line-1, offset.index-1, source_location.get_path());
}
else {
auto get_header_location=[this]() {
// If cursor is at an include line, return offset to included file
const static std::regex include_regex("^[ \t]*#[ \t]*include[ \t]*[<\"](.+)[>\"][ \t]*$");
std::smatch sm;
@ -1073,12 +1062,30 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
if(!client_data.found_include.empty())
return Offset(0, 0, client_data.found_include);
}
return Offset();
};
get_declaration_location=[this, get_header_location](){
if(!parsed) {
Info::get().print("Buffer is parsing");
return Offset();
}
auto identifier=get_identifier();
if(identifier) {
auto source_location=identifier.cursor.get_canonical().get_source_location();
auto offset=source_location.get_offset();
return Offset(offset.line-1, offset.index-1, source_location.get_path());
}
else {
auto location=get_header_location();
if(location)
return location;
}
Info::get().print("No declaration found");
return Offset();
};
is_implementation=[this]() {
is_implementation_location=[this]() {
if(!parsed)
return false;
auto iter=get_buffer()->get_insert()->get_iter();
@ -1093,7 +1100,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
return false;
};
get_implementation_locations=[this](const std::vector<Source::View*> &views){
get_implementation_locations=[this, get_header_location](const std::vector<Source::View*> &views){
std::vector<Offset> locations;
if(!parsed) {
Info::get().print("Buffer is parsing");
@ -1163,6 +1170,13 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
return locations;
}
}
else {
auto location=get_header_location();
if(location) {
locations.emplace_back(location);
return locations;
}
}
Info::get().print("No implementation found");
return locations;
};

Loading…
Cancel
Save