示例#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
DateTime strptime(const unicode &date_string, const unicode &fmt) {
    std::tm tm;
    ::strptime(date_string.encode().c_str(), fmt.encode().c_str(), &tm);
    auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));

    return tp;
}
示例#3
0
void DocumentView::save(const unicode& path) {
    L_DEBUG("Saving file: " + path.encode());
    trim_trailing_newlines();
    trim_trailing_whitespace();

    Glib::ustring text = buffer()->get_text();

    if(file_->get_path() == path.encode()) {
        //FIXME: Use entity tag arguments to make sure that the file
        //didn't change since the last time we saved
        file_->replace_contents(std::string(text.c_str()), "", file_etag_);
        connect_file_monitor();
    } else {
        auto file = Gio::File::create_for_path(path.encode());
        if(!os::path::exists(path)) {
            file->create_file();
        }
        file->replace_contents(text, "", file_etag_);
        connect_file_monitor();
    }

    buffer()->set_modified(false);

    apply_settings(guess_mimetype()); //Make sure we update the settings when we've saved the file

    window_.rebuild_open_list();
    run_linters_and_stuff();
}
示例#4
0
void Indexer::index_directory(const unicode &dir_path) {
    /*
     *  Recursively indexes the files in a directory
     */

    for(auto file: kfs::path::list_dir(dir_path.encode())) {
        auto full_path = kfs::path::join(dir_path.encode(), file);

        if(kfs::path::is_dir(full_path)) {
            index_directory(full_path);
        } else {
            index_file(full_path);
        }
    }
}
示例#5
0
TextureID ResourceManagerImpl::new_texture_from_file(const unicode& path) {
    //Load the texture
    auto tex = texture(new_texture());
    window().loader_for(path.encode())->into(*tex);
    tex->upload(false, true, true, false);
    return tex->id();
}
示例#6
0
unicode strftime(const DateTime& t, const unicode& fmt) {
    time_t tt = std::chrono::system_clock::to_time_t(t);

    char buffer[256];
    ::strftime(buffer, 256, fmt.encode().c_str(), localtime(&tt));
    return unicode(buffer);
}
示例#7
0
MeshID ResourceManagerImpl::new_mesh_from_file(const unicode& path, bool garbage_collect) {
    //Load the material
    kglt::MeshID mesh_id = new_mesh(garbage_collect);
    window->loader_for(path.encode())->into(mesh(mesh_id));
    MeshManager::mark_as_uncollected(mesh_id);
    return mesh_id;
}
示例#8
0
MaterialID ResourceManagerImpl::new_material_from_file(const unicode& path, bool garbage_collect) {
    //Load the material
    L_INFO(_u("Loading material {0}").format(path));

    auto mat = material(new_material(garbage_collect));
    window->loader_for(path.encode())->into(mat);
    mark_material_as_uncollected(mat->id());
    return mat->id();
}
示例#9
0
MeshID ResourceManagerImpl::new_mesh_from_tmx_file(const unicode& tmx_file, const unicode& layer_name, float tile_render_size, bool garbage_collect) {
    kglt::MeshID mesh_id = new_mesh(garbage_collect);
    window->loader_for(tmx_file.encode())->into(mesh(mesh_id), {
        {"layer", layer_name},
        {"render_size", tile_render_size}
    });
    MeshManager::mark_as_uncollected(mesh_id);
    return mesh_id;
}
示例#10
0
UIStageID UIStageManager::new_ui_stage_from_file(const unicode& rml_file) {
    auto new_ui = new_ui_stage();
    window_->loader_for(rml_file.encode())->into(std::shared_ptr<UIStage>(ui_stage(new_ui)));
    try {

    } catch(...) {
        delete_ui_stage(new_ui);
        throw;
    }

    return new_ui;
}
示例#11
0
OverlayID OverlayManager::new_overlay_from_file(const unicode& rml_file) {
    auto new_ui = new_overlay();
    window_->loader_for(rml_file.encode())->into(std::shared_ptr<Overlay>(overlay(new_ui)));
    try {

    } catch(...) {
        delete_overlay(new_ui);
        throw;
    }

    return new_ui;
}
示例#12
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;
        });
    }
}
示例#13
0
unicode Indexer::guess_type(const unicode& filename) {
    /*
     *  Tries to guess the mimetype of a file
     *
     *  FIXME: Switch to Gio::content_type_guess but try to avoid the cost of
     *  loading file data twice.
     */

    auto ext = kfs::path::split_ext(filename.encode()).second;
    auto it = MIMETYPES.find(ext);
    if(it == MIMETYPES.end()) {
        return "text/plain";
    }

    return (*it).second;
}
示例#14
0
TextureID ResourceManagerImpl::new_texture_from_file(const unicode& path, TextureFlags flags, bool garbage_collect) {
    //Load the texture
    auto tex = texture(new_texture(garbage_collect));
    window->loader_for("texture", path.encode())->into(tex);

    if((flags & TEXTURE_OPTION_FLIP_VERTICALLY) == TEXTURE_OPTION_FLIP_VERTICALLY) {
        tex->flip_vertically();
    }

    tex->upload(
        false,
        (flags & TEXTURE_OPTION_DISABLE_MIPMAPS) != TEXTURE_OPTION_DISABLE_MIPMAPS,
        (flags & TEXTURE_OPTION_CLAMP_TO_EDGE) != TEXTURE_OPTION_CLAMP_TO_EDGE,
        (flags & TEXTURE_OPTION_NEAREST_FILTER) != TEXTURE_OPTION_NEAREST_FILTER
    );

    mark_texture_as_uncollected(tex->id());
    return tex->id();
}
示例#15
0
void FindBar::locate_matches(const unicode& string) {
    matches_.clear();
    last_selected_match_ = -1;

    auto buf = window_.current_buffer()->buffer();
    auto start = buf->begin();
    Gtk::TextIter end;

    bool case_sensitive = case_sensitive_->get_active();

    while(start.forward_search(
              string.encode(), (case_sensitive) ? Gtk::TextSearchFlags(0) : Gtk::TEXT_SEARCH_CASE_INSENSITIVE,
              start, end)) {

        matches_.push_back(std::make_pair(start, end));
        start = buf->get_iter_at_offset(end.get_offset());
    }

}
示例#16
0
std::vector<unicode> AwesomeBar::filter_project_files(const unicode& search_text, uint64_t filter_task_id) {
    unicode lower_text = search_text.lower();

    const int DISPLAY_LIMIT = 15;

    std::vector<unicode> haystack;

    if(this->filter_task_id_ != filter_task_id) {
        return std::vector<unicode>();
    }

    haystack = this->window_.info()->filenames_including(std::vector<char32_t>(lower_text.begin(), lower_text.end()));

    int to_display = std::min(DISPLAY_LIMIT, (int) haystack.size());

    int project_path_length = window_.project_path().length() + 1;

    try {
        if(this->filter_task_id_ != filter_task_id) {
            return std::vector<unicode>();
        }

        std::partial_sort(haystack.begin(), haystack.begin() + to_display, haystack.end(), [=](const unicode& lhs, const unicode& rhs) -> bool {
            if(this->filter_task_id_ != filter_task_id) {
                throw TaskTerminatedError();
            }
            auto lhs_rel = lhs.slice(project_path_length, nullptr).lower();
            auto rhs_rel = rhs.slice(project_path_length, nullptr).lower();
            return rank(lhs_rel, lower_text) > rank(rhs_rel, lower_text);
        });
    } catch(TaskTerminatedError&e ) {
        return std::vector<unicode>();
    }

    return std::vector<unicode>(haystack.begin(), haystack.begin() + to_display);
}
示例#17
0
void DocumentView::open_file(const unicode& filename) {
    auto file = Gio::File::create_for_path(filename.encode());
    set_file(file);
}
示例#18
0
SoundID ResourceManagerImpl::new_sound_from_file(const unicode& path, bool garbage_collect) {
    //Load the sound
    auto snd = sound(new_sound(garbage_collect));
    window->loader_for(path.encode())->into(snd);
    return snd->id();
}
示例#19
0
SoundID ResourceManagerImpl::new_sound_from_file(const unicode& path) {
    //Load the sound
    SoundPtr snd = sound(new_sound()).lock();
    window().loader_for(path.encode())->into(*snd);
    return snd->id();
}
示例#20
0
MeshID ResourceManagerImpl::new_mesh_from_file(const unicode& path) {
    //Load the material
    MeshPtr m = mesh(new_mesh()).lock();
    window().loader_for(path.encode())->into(*m);
    return m->id();
}
示例#21
0
MaterialID ResourceManagerImpl::new_material_from_file(const unicode& path) {
    //Load the material
    auto mat = material(new_material());
    window().loader_for(path.encode())->into(*mat);
    return mat->id();
}