Skip to content

Commit

Permalink
projectorganizer: Fix for cases when base_path is relative
Browse files Browse the repository at this point in the history
This is necessary at least for now until (if ever) the simplified project
definition patch gets into Geany.
  • Loading branch information
techee committed Mar 29, 2015
1 parent 9de7847 commit b0b5c94
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion projectorganizer/src/prjorg-menu.c
Expand Up @@ -185,7 +185,7 @@ static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_U
static void on_find_in_project(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data)
{
if (geany_data->app->project)
search_show_find_in_files_dialog(geany_data->app->project->base_path);
search_show_find_in_files_dialog(get_project_base_path());
}


Expand Down
2 changes: 1 addition & 1 deletion projectorganizer/src/prjorg-project.c
Expand Up @@ -473,7 +473,7 @@ void prjorg_project_open(GKeyFile * key_file)
}
g_slist_free(ext_list);
/* the project directory is always first */
prj_org->roots = g_slist_prepend(prj_org->roots, create_root(geany_data->app->project->base_path));
prj_org->roots = g_slist_prepend(prj_org->roots, create_root(get_project_base_path()));

update_project(
source_patterns,
Expand Down
16 changes: 8 additions & 8 deletions projectorganizer/src/prjorg-sidebar.c
Expand Up @@ -219,7 +219,7 @@ static gchar *build_path(GtkTreeIter *iter)
gchar *name;

if (!iter)
return g_strdup(geany_data->app->project->base_path);
return g_strdup(get_project_base_path());

node = *iter;
model = GTK_TREE_MODEL(s_file_store);
Expand All @@ -237,7 +237,7 @@ static gchar *build_path(GtkTreeIter *iter)
}

if (topmost_selected(model, &node, TRUE))
SETPTR(path, g_build_filename(geany_data->app->project->base_path, path, NULL));
SETPTR(path, g_build_filename(get_project_base_path(), path, NULL));
else
{
gtk_tree_model_get(model, &node, FILEVIEW_COLUMN_NAME, &name, -1);
Expand Down Expand Up @@ -291,7 +291,7 @@ static void on_add_external(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED
GTK_WINDOW(geany->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("Add"), GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), geany_data->app->project->base_path);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), get_project_base_path());

if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
Expand Down Expand Up @@ -358,7 +358,7 @@ static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboo
gchar *path;

path = build_path(iter);
name = get_relative_path(geany_data->app->project->base_path, path);
name = get_relative_path(get_project_base_path(), path);
g_free(path);
}
else
Expand All @@ -372,7 +372,7 @@ static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboo
gchar *path, *rel_path;

path = build_path(iter);
rel_path = get_relative_path(geany_data->app->project->base_path, path);
rel_path = get_relative_path(get_project_base_path(), path);
msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : path);
g_free(path);
g_free(rel_path);
Expand Down Expand Up @@ -401,7 +401,7 @@ static void find_file(GtkTreeIter *iter)
pattern = g_pattern_spec_new(pattern_str);

msgwin_clear_tab(MSG_MESSAGE);
msgwin_set_messages_dir(geany_data->app->project->base_path);
msgwin_set_messages_dir(get_project_base_path());
find_file_recursive(iter, case_sensitive, full_path, pattern);
msgwin_switch_tab(MSG_MESSAGE, TRUE);
}
Expand Down Expand Up @@ -581,7 +581,7 @@ static void find_tags(const gchar *name, gboolean declaration, gboolean case_sen

pspec = g_pattern_spec_new(name_case);

msgwin_set_messages_dir(geany_data->app->project->base_path);
msgwin_set_messages_dir(get_project_base_path());
msgwin_clear_tab(MSG_MESSAGE);
for (i = 0; i < tags_array->len; i++) /* TODO: binary search */
{
Expand All @@ -592,7 +592,7 @@ static void find_tags(const gchar *name, gboolean declaration, gboolean case_sen
gchar *scopestr = tag->scope ? g_strconcat(tag->scope, "::", NULL) : g_strdup("");
gchar *relpath;

relpath = get_relative_path(geany_data->app->project->base_path, tag->file->file_name);
relpath = get_relative_path(get_project_base_path(), tag->file->file_name);
msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n\t[%s]\t %s%s%s", relpath,
tag->line, tm_tag_type_name(tag), scopestr, tag->name, tag->arglist ? tag->arglist : "");
g_free(scopestr);
Expand Down
25 changes: 25 additions & 0 deletions projectorganizer/src/prjorg-utils.c
Expand Up @@ -116,3 +116,28 @@ gchar *get_selection(void)
else
return editor_get_word_at_pos(doc->editor, -1, wc);
}


gchar *get_project_base_path(void)
{
GeanyProject *project = geany_data->app->project;

if (project && !EMPTY(project->base_path))
{
if (g_path_is_absolute(project->base_path))
return g_strdup(project->base_path);
else
{ /* build base_path out of project file name's dir and base_path */
gchar *path;
gchar *dir = g_path_get_dirname(project->file_name);

if (utils_str_equal(project->base_path, "./"))
return dir;

path = g_build_filename(dir, project->base_path, NULL);
g_free(dir);
return path;
}
}
return NULL;
}
1 change: 1 addition & 0 deletions projectorganizer/src/prjorg-utils.h
Expand Up @@ -26,5 +26,6 @@ GSList *get_precompiled_patterns(gchar **patterns);

void open_file(gchar *utf8_name);
gchar *get_selection(void);
gchar *get_project_base_path(void);

#endif

0 comments on commit b0b5c94

Please sign in to comment.