Example #1
0
void FindInFilesPanel::_on_replace_all_clicked() {

	String replace_text = get_replace_text();

	PoolStringArray modified_files;

	for (Map<String, TreeItem *>::Element *E = _file_items.front(); E; E = E->next()) {

		TreeItem *file_item = E->value();
		String fpath = file_item->get_metadata(0);

		Vector<Result> locations;
		for (TreeItem *item = file_item->get_children(); item; item = item->get_next()) {

			if (!item->is_checked(0))
				continue;

			Map<TreeItem *, Result>::Element *F = _result_items.find(item);
			ERR_FAIL_COND(F == NULL);
			locations.push_back(F->value());
		}

		if (locations.size() != 0) {
			// Results are sorted by file, so we can batch replaces
			apply_replaces_in_file(fpath, locations, replace_text);
			modified_files.append(fpath);
		}
	}

	// Hide replace bar so we can't trigger the action twice without doing a new search
	_replace_container->hide();

	emit_signal(SIGNAL_FILES_MODIFIED, modified_files);
}
Example #2
0
void FindInFilesPanel::_on_replace_all_clicked() {

	String replace_text = get_replace_text();
	ERR_FAIL_COND(replace_text.empty());

	String last_fpath;
	PoolIntArray locations;
	PoolStringArray modified_files;

	for (int i = 0; i < _results_display->get_item_count(); ++i) {

		Array meta = _results_display->get_item_metadata(i);

		String fpath = meta[0];

		// Results are sorted by file, so we can batch replaces
		if (fpath != last_fpath) {
			if (locations.size() != 0) {
				apply_replaces_in_file(last_fpath, locations, replace_text);
				modified_files.append(last_fpath);
				locations.resize(0);
			}
		}

		locations.append(meta[1]); // line_number
		locations.append(meta[2]); // begin
		locations.append(meta[3]); // end

		last_fpath = fpath;
	}

	if (locations.size() != 0) {
		apply_replaces_in_file(last_fpath, locations, replace_text);
		modified_files.append(last_fpath);
	}

	// Hide replace bar so we can't trigger the action twice without doing a new search
	set_with_replace(false);

	emit_signal(SIGNAL_FILES_MODIFIED, modified_files);
}