Skip to content

Commit

Permalink
projectorganizer: Use gchar** instead of GPtrArray to simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed May 7, 2023
1 parent 6130bbe commit f822e69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
1 change: 0 additions & 1 deletion projectorganizer/src/prjorg-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config,
prjorg_sidebar_update_full(TRUE, arr);
prjorg_sidebar_activate(TRUE);
prjorg_menu_activate_menu_items(TRUE);
g_strfreev(arr);
}
}

Expand Down
12 changes: 3 additions & 9 deletions projectorganizer/src/prjorg-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,11 @@ static void update_project(

static void save_expanded_paths(GKeyFile * key_file)
{
GPtrArray *expanded_paths = prjorg_sidebar_get_expanded_paths();
gchar **expanded_paths_v = g_new (gchar *, expanded_paths->len + 1);
guint i;
gchar **expanded_paths = prjorg_sidebar_get_expanded_paths();

for (i = 0; i < expanded_paths->len; i++)
expanded_paths_v[i] = expanded_paths->pdata[i];
expanded_paths_v[expanded_paths->len] = NULL;
g_key_file_set_string_list(key_file, "prjorg", "expanded_paths",
(const gchar**) expanded_paths_v, g_strv_length(expanded_paths_v));
g_free(expanded_paths_v);
g_ptr_array_free(expanded_paths, TRUE);
(const gchar**) expanded_paths, g_strv_length(expanded_paths));
g_strfreev(expanded_paths);
}


Expand Down
28 changes: 10 additions & 18 deletions projectorganizer/src/prjorg-sidebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef enum
typedef struct
{
GeanyProject *project;
GPtrArray *expanded_paths;
gchar **expanded_paths;
gchar *selected_path;
} ExpandData;

Expand Down Expand Up @@ -1496,12 +1496,10 @@ static gboolean expand_on_idle(ExpandData *expand_data)
if (geany_data->app->project == expand_data->project &&
expand_data->expanded_paths)
{
gchar *item;
guint i;

foreach_ptr_array(item, i, expand_data->expanded_paths)
expand_path(item, FALSE);
g_ptr_array_free(expand_data->expanded_paths, TRUE);
gchar **item;
foreach_strv(item, expand_data->expanded_paths)
expand_path(*item, FALSE);
g_strfreev(expand_data->expanded_paths);
}

if (expand_data->selected_path)
Expand Down Expand Up @@ -1556,14 +1554,15 @@ static void on_map_expanded(GtkTreeView *tree_view, GtkTreePath *tree_path, GPtr
}


GPtrArray *prjorg_sidebar_get_expanded_paths(void)
gchar **prjorg_sidebar_get_expanded_paths(void)
{
GPtrArray *expanded_paths = g_ptr_array_new_with_free_func(g_free);
GPtrArray *expanded_paths = g_ptr_array_new();

gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(s_file_view),
(GtkTreeViewMappingFunc)on_map_expanded, expanded_paths);
g_ptr_array_add(expanded_paths, NULL);

return expanded_paths;
return g_ptr_array_free(expanded_paths, FALSE);
}


Expand Down Expand Up @@ -1591,15 +1590,8 @@ void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths)
GtkTreeSelection *treesel;
GtkTreeIter iter;
GtkTreeModel *model;
gchar **path;
GPtrArray *exp_paths_arr = g_ptr_array_new();

foreach_strv (path, expanded_paths)
{
g_ptr_array_add(exp_paths_arr, g_strdup(*path));
}

expand_data->expanded_paths = expanded_paths != NULL ? exp_paths_arr : prjorg_sidebar_get_expanded_paths();
expand_data->expanded_paths = expanded_paths != NULL ? expanded_paths : prjorg_sidebar_get_expanded_paths();
expand_data->selected_path = get_selected_path();

load_project();
Expand Down
2 changes: 1 addition & 1 deletion projectorganizer/src/prjorg-sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths);

void prjorg_sidebar_focus_project_tab(void);

GPtrArray *prjorg_sidebar_get_expanded_paths(void);
gchar **prjorg_sidebar_get_expanded_paths(void);

void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data);
void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data);
Expand Down

0 comments on commit f822e69

Please sign in to comment.