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; }
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; }
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(); }
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); } } }
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(); }
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); }
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; }
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(); }
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; }
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; }
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; }
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; }); } }
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; }
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(); }
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()); } }
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); }
void DocumentView::open_file(const unicode& filename) { auto file = Gio::File::create_for_path(filename.encode()); set_file(file); }
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(); }
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(); }
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(); }
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(); }