Browse Source

Show usages: now sets dialog cursor on the current usage

merge-requests/365/head
eidheim 10 years ago
parent
commit
e54c396bfa
  1. 15
      src/selectiondialog.cc
  2. 1
      src/selectiondialog.h
  3. 18
      src/window.cc

15
src/selectiondialog.cc

@ -115,9 +115,24 @@ void SelectionDialogBase::show() {
window->show_all();
if(list_view_text.get_model()->children().size()>0) {
if(!list_view_text.get_selection()->get_selected()) {
list_view_text.set_cursor(list_view_text.get_model()->get_path(list_view_text.get_model()->children().begin()));
cursor_changed();
}
else if(list_view_text.get_model()->children().begin()!=list_view_text.get_selection()->get_selected()) {
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5);
}
}
}
void SelectionDialogBase::set_cursor_at_last_row() {
auto children=list_view_text.get_model()->children();
if(children.size()>0) {
list_view_text.set_cursor(list_view_text.get_model()->get_path(children[children.size()-1]));
cursor_changed();
}
}
void SelectionDialogBase::hide() {

1
src/selectiondialog.h

@ -28,6 +28,7 @@ public:
SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup);
~SelectionDialogBase();
void add_row(const std::string& row);
void set_cursor_at_last_row();
void show();
void hide();
void move();

18
src/window.cc

@ -488,18 +488,28 @@ void Window::set_menu_actions() {
if(view->get_usages) {
auto usages=view->get_usages(Notebook::get().get_views());
if(!usages.empty()) {
auto iter=view->get_iter_for_dialog();
view->selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*view, view->get_buffer()->create_mark(iter), true, true));
auto dialog_iter=view->get_iter_for_dialog();
view->selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*view, view->get_buffer()->create_mark(dialog_iter), true, true));
auto rows=std::make_shared<std::unordered_map<std::string, Source::Offset> >();
auto iter=view->get_buffer()->get_insert()->get_iter();
for(auto &usage: usages) {
std::string row;
//add file name if usage is not in current tab
if(view->file_path!=usage.first.file_path)
bool current_page=true;
//add file name if usage is not in current page
if(view->file_path!=usage.first.file_path) {
row=usage.first.file_path.filename().string()+":";
current_page=false;
}
row+=std::to_string(usage.first.line+1)+": "+usage.second;
(*rows)[row]=usage.first;
view->selection_dialog->add_row(row);
//Set dialog cursor to the last row if the textview cursor is at the same line
if(current_page) {
if(iter.get_line()==static_cast<int>(usage.first.line) && iter.get_line_index()>=static_cast<int>(usage.first.index))
view->selection_dialog->set_cursor_at_last_row();
}
}
if(rows->size()==0)

Loading…
Cancel
Save