Ejemplo n.º 1
0
static void on_build_start(GObject *obj, gpointer user_data)
{
	gint i;

	foreach_document(i)
	{
		if (gprj_project_is_in_project(documents[i]->file_name))
			document_save_file(documents[i], FALSE);
	}
}
Ejemplo n.º 2
0
static void on_doc_open(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED GeanyDocument * doc,
	    G_GNUC_UNUSED gpointer user_data)
{
	g_return_if_fail(doc != NULL && doc->file_name != NULL);

	/* tags of open files managed by geany*/
	if (gprj_project_is_in_project(doc->file_name))
		gprj_project_remove_file_tag(doc->file_name);

	gprj_sidebar_update(FALSE);
}
Ejemplo n.º 3
0
static void on_doc_close(G_GNUC_UNUSED GObject * obj, GeanyDocument * doc,
		G_GNUC_UNUSED gpointer user_data)
{
	g_return_if_fail(doc != NULL && doc->file_name != NULL);

	//tags of open files managed by geany - when the file gets closed, we should take care of it
	if (gprj_project_is_in_project(doc->file_name))
		gprj_project_add_file_tag(doc->file_name);

	gprj_sidebar_update(FALSE);
}
Ejemplo n.º 4
0
static gboolean try_swap_header_source(gchar *file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns)
{
	gchar *name_pattern;
	gchar *base_name = NULL;
	GSList *elem;
	GPatternSpec *pattern;
	gboolean found = FALSE;

	name_pattern = g_path_get_basename(file_name);
	setptr(name_pattern, utils_remove_ext_from_filename(name_pattern));
	setptr(name_pattern, g_strconcat(name_pattern, ".*", NULL));
	pattern = g_pattern_spec_new(name_pattern);
	g_free(name_pattern);

	for (elem = file_list; elem != NULL; elem = g_slist_next(elem))
	{
		gchar *full_name = elem->data;
		base_name = g_path_get_basename(full_name);

		if (g_pattern_match_string(pattern, base_name) &&
		    gprj_project_is_in_project(full_name))
		{
			if ((is_header && patterns_match(source_patterns, base_name)) ||
				(!is_header && patterns_match(header_patterns, base_name)))
			{
				open_file(full_name);
				found = TRUE;
				break;
			}
		}
	}

	g_free(base_name);
	g_pattern_spec_free(pattern);
	return found;
}
Ejemplo n.º 5
0
static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data)
{
	GSList *header_patterns, *source_patterns;
	GeanyDocument *doc;
	gboolean known_type = TRUE;
	gboolean is_header;
	gchar *doc_basename;
	doc = document_get_current();

	if (!g_prj || !geany_data->app->project || !doc || !doc->file_name)
		return;

	header_patterns = get_precompiled_patterns(g_prj->header_patterns);
	source_patterns = get_precompiled_patterns(g_prj->source_patterns);

	doc_basename = g_path_get_basename(doc->file_name);

	if (patterns_match(header_patterns, doc_basename))
		is_header = TRUE;
	else if (patterns_match(source_patterns, doc_basename))
		is_header = FALSE;
	else
		known_type = FALSE;

	if (known_type)
	{
		gboolean swapped;
		GSList *elem, *list = NULL;
		gint i;

		foreach_document(i)
		{
			gchar *filename;

			filename = document_index(i)->file_name;
			if (gprj_project_is_in_project(filename))
				list = g_slist_prepend(list, filename);
		}
		swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns);
		g_slist_free(list);
		list = NULL;

		if (!swapped)
		{
			gchar *doc_dir;

			doc_dir = g_path_get_dirname(doc->file_name);
			setptr(doc_dir, utils_get_locale_from_utf8(doc_dir));

			list = utils_get_file_list(doc_dir, NULL, NULL);
			for (elem = list; elem != NULL; elem = g_slist_next(elem))
			{
				gchar *full_name;

				full_name = g_build_filename(doc_dir, elem->data, NULL);
				setptr(full_name, utils_get_utf8_from_locale(full_name));
				setptr(elem->data, full_name);
			}
			swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns);
			g_slist_foreach(list, (GFunc) g_free, NULL);
			g_slist_free(list);
			g_free(doc_dir);
			list = NULL;
		}

		if (!swapped)
		{
			g_hash_table_foreach(g_prj->file_tag_table, (GHFunc) get_project_file_list, &list);
			try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns);
			g_slist_free(list);
		}
	}

	g_free(doc_basename);

	g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL);
	g_slist_free(header_patterns);
	g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL);
	g_slist_free(source_patterns);
}