Browse Source

Added menu item Source->Go to Type Declaration

merge-requests/365/head
eidheim 8 years ago
parent
commit
4c8695c8fc
  1. 2
      CMakeLists.txt
  2. 2
      libclangmm
  3. 1
      src/files.h
  4. 8
      src/menu.cc
  5. 1
      src/source.h
  6. 21
      src/source_clang.cc
  7. 18
      src/window.cc

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.8.8)
project(juci)
set(JUCI_VERSION "1.3.2.1")
set(JUCI_VERSION "1.3.2.2")
set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

2
libclangmm

@ -1 +1 @@
Subproject commit 8c3f78eb20fd2a5d56791d293bcaddab35cd1ed1
Subproject commit 979a59647aac885049682479d31fcd2a94b3cf17

1
src/files.h

@ -124,6 +124,7 @@ R"RAW(
"source_comments_add_documentation": "<primary><alt>slash",
"source_find_documentation": "<primary><shift>d",
"source_goto_declaration": "<primary>d",
"source_goto_type_declaration": "<alt><shift>d",
"source_goto_implementation": "<primary>i",
"source_goto_usage": "<primary>u",
"source_goto_method": "<primary>m",

8
src/menu.cc

@ -32,6 +32,10 @@ const Glib::ustring menu_xml= R"RAW(<interface>
<attribute name='label' translatable='yes'>_Go _to _Declaration</attribute>
<attribute name='action'>app.source_goto_declaration</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go _to _Type _Declaration</attribute>
<attribute name='action'>app.source_goto_type_declaration</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go _to _Implementation</attribute>
<attribute name='action'>app.source_goto_implementation</attribute>
@ -293,6 +297,10 @@ const Glib::ustring menu_xml= R"RAW(<interface>
<attribute name='label' translatable='yes'>_Go to Declaration</attribute>
<attribute name='action'>app.source_goto_declaration</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go to _Type _Declaration</attribute>
<attribute name='action'>app.source_goto_type_declaration</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go to Implementation</attribute>
<attribute name='action'>app.source_goto_implementation</attribute>

1
src/source.h

@ -70,6 +70,7 @@ namespace Source {
std::function<void()> non_interactive_completion;
std::function<void(bool)> format_style;
std::function<Offset()> get_declaration_location;
std::function<Offset()> get_type_declaration_location;
std::function<std::vector<Offset>()> get_implementation_locations;
std::function<std::vector<Offset>()> get_declaration_or_implementation_locations;
std::function<std::vector<std::pair<Offset, std::string> >()> get_usages;

21
src/source_clang.cc

@ -1062,6 +1062,27 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
return offset;
};
get_type_declaration_location=[this](){
if(!parsed) {
Info::get().print("Buffer is parsing");
return Offset();
}
auto identifier=get_identifier();
if(identifier) {
auto type_cursor=identifier.cursor.get_type().get_cursor();
if(type_cursor) {
auto source_location=type_cursor.get_source_location();
auto path=source_location.get_path();
if(!path.empty()) {
auto location_offset=source_location.get_offset();
return Offset(location_offset.line-1, location_offset.index-1, path);
}
}
}
Info::get().print("No type declaration found");
return Offset();
};
auto implementation_locations=[this](const Identifier &identifier) {
std::vector<Offset> offsets;
if(identifier) {

18
src/window.cc

@ -827,6 +827,23 @@ void Window::set_menu_actions() {
}
}
});
menu.add_action("source_goto_type_declaration", [this]() {
if(auto view=Notebook::get().get_current_view()) {
if(view->get_type_declaration_location) {
auto location=view->get_type_declaration_location();
if(location) {
if(!boost::filesystem::is_regular_file(location.file_path))
return;
Notebook::get().open(location.file_path);
auto view=Notebook::get().get_current_view();
auto line=static_cast<int>(location.line);
auto index=static_cast<int>(location.index);
view->place_cursor_at_line_index(line, index);
view->scroll_to_cursor_delayed(view, true, false);
}
}
}
});
auto goto_selected_location=[](Source::View *view, const std::vector<Source::Offset> &locations) {
if(!locations.empty()) {
auto dialog_iter=view->get_iter_for_dialog();
@ -1306,6 +1323,7 @@ void Window::activate_menu_items() {
menu.actions["source_comments_add_documentation"]->set_enabled(view && view->get_documentation_template);
menu.actions["source_find_documentation"]->set_enabled(view && view->get_token_data);
menu.actions["source_goto_declaration"]->set_enabled(view && view->get_declaration_location);
menu.actions["source_goto_type_declaration"]->set_enabled(view && view->get_type_declaration_location);
menu.actions["source_goto_implementation"]->set_enabled(view && view->get_implementation_locations);
menu.actions["source_goto_declaration_or_implementation"]->set_enabled(view && view->get_declaration_or_implementation_locations);
menu.actions["source_goto_usage"]->set_enabled(view && view->get_usages);

Loading…
Cancel
Save