示例#1
0
int FindBar::highlight_all(const unicode& string, std::vector<Gtk::TextBuffer::iterator>& start_iters) {
    auto buf = window_.current_buffer()->buffer();
    auto start = buf->begin();
    auto end_of_file = buf->end();
    auto end = start;

    bool case_sensitive = case_sensitive_->get_active();

    //Remove any existing highlights
    buf->remove_tag_by_name(SEARCH_HIGHLIGHT_TAG, start, end_of_file);

    if(string.empty()) {
        return 0;
    }

    int highlighted = 0;
    while(start.forward_search(
              string.encode(), (case_sensitive) ? Gtk::TextSearchFlags(0) : Gtk::TEXT_SEARCH_CASE_INSENSITIVE,
              start, end)) {
        start_iters.push_back(start);
        buf->apply_tag_by_name(SEARCH_HIGHLIGHT_TAG, start, end);
        start = buf->get_iter_at_offset(end.get_offset());
        ++highlighted;
    }
    return highlighted;
}
示例#2
0
void AwesomeBar::populate(const unicode &text) {
    //Clear the listing
    for(auto child: list_.get_children()) {
        list_.remove(*child);
    }
    list_revealer_.set_reveal_child(false);

    if(text.starts_with(":") && text.length() > 1) {
        try {
            unicode number_text = text.lstrip(":");
            int line_number = number_text.to_int();

            window_.current_buffer()->scroll_to_line(line_number);
        } catch(std::exception& e) {
            return;
        }
    } else if(!text.empty()) {
        filter_task_ = std::make_shared<std::future<std::vector<unicode>>>(
            std::async(std::launch::async, std::bind(&AwesomeBar::filter_project_files, this, text, ++filter_task_id_))
        );

        auto copy = filter_task_;
        Glib::signal_idle().connect([&, copy]() -> bool {
            if(!filter_task_ || filter_task_.get() != copy.get()) {
                //A new task was submitted or the task was cancelled
                return false;
            }

            if(filter_task_->wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
                populate_results(filter_task_->get());
                filter_task_.reset();
                return false;
            }

            return true;
        });
    }
}