Skip to content

Commit

Permalink
Add a more precise function to add group
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Nov 21, 2009
1 parent edfd098 commit 09bef3e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
12 changes: 12 additions & 0 deletions libanjuta/anjuta-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ anjuta_project_node_append (AnjutaProjectNode *parent, AnjutaProjectNode *node)
return g_node_append (parent, node);
}

AnjutaProjectNode *
anjuta_project_node_insert_before (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNode *node)
{
return g_node_insert_before (parent, sibling, node);
}

AnjutaProjectNode *
anjuta_project_node_insert_after (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNode *node)
{
return g_node_insert_after (parent, sibling, node);
}

AnjutaProjectNode *
anjuta_project_node_prepend (AnjutaProjectNode *parent, AnjutaProjectNode *node)
{
Expand Down
2 changes: 2 additions & 0 deletions libanjuta/anjuta-project.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void anjuta_project_node_all_foreach (AnjutaProjectNode *node, AnjutaProjectNode
void anjuta_project_node_children_foreach (AnjutaProjectNode *node, AnjutaProjectNodeFunc func, gpointer data);

AnjutaProjectNode *anjuta_project_node_append (AnjutaProjectNode *parent, AnjutaProjectNode *node);
AnjutaProjectNode *anjuta_project_node_insert_before (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNode *node);
AnjutaProjectNode *anjuta_project_node_insert_after (AnjutaProjectNode *parent, AnjutaProjectNode *sibling, AnjutaProjectNode *node);
AnjutaProjectNode *anjuta_project_node_prepend (AnjutaProjectNode *parent, AnjutaProjectNode *node);

AnjutaProjectNodeType anjuta_project_node_get_type (const AnjutaProjectNode *node);
Expand Down
41 changes: 34 additions & 7 deletions src/am-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,12 +1674,13 @@ amp_project_get_token_location (AmpProject *project, AnjutaTokenFileLocation *lo
return FALSE;
}


AmpGroup*
amp_project_add_group (AmpProject *project,
AmpGroup *parent,
const gchar *name,
GError **error)
AmpGroup*
amp_project_add_sibling_group (AmpProject *project,
AmpGroup *parent,
const gchar *name,
gboolean after,
AmpGroup *sibling,
GError **error)
{
AmpGroup *last;
AmpGroup *child;
Expand Down Expand Up @@ -1722,6 +1723,15 @@ amp_project_add_group (AmpProject *project,
directory = g_file_get_child (AMP_GROUP_DATA (parent)->base.directory, name);
uri = g_file_get_uri (directory);
if (g_hash_table_lookup (project->groups, uri) != NULL)
{
g_free (uri);
error_set (error, IANJUTA_PROJECT_ERROR_VALIDATION_FAILED,
_("Sibling group has not the same parent"));
return NULL;
}

/* If a sibling is used, check that the parent is right */
if ((sibling != NULL) && (parent != anjuta_project_node_parent (sibling)))
{
g_free (uri);
error_set (error, IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
Expand All @@ -1733,7 +1743,14 @@ amp_project_add_group (AmpProject *project,
child = amp_group_new (directory, FALSE);
g_hash_table_insert (project->groups, uri, child);
g_object_unref (directory);
anjuta_project_node_append (parent, child);
if (after)
{
anjuta_project_node_insert_after (parent, sibling, child);
}
else
{
anjuta_project_node_insert_before (parent, sibling, child);
}

/* Create directory */
g_file_make_directory (directory, NULL, NULL);
Expand Down Expand Up @@ -1853,6 +1870,16 @@ amp_project_add_group (AmpProject *project,
return child;
}


AmpGroup*
amp_project_add_group (AmpProject *project,
AmpGroup *parent,
const gchar *name,
GError **error)
{
return amp_project_add_sibling_group (project, parent, name, TRUE, NULL, error);
}

void
amp_project_remove_group (AmpProject *project,
AmpGroup *group,
Expand Down
1 change: 1 addition & 0 deletions src/am-project.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ gchar * amp_project_get_uri (AmpProject *project);
GFile* amp_project_get_file (AmpProject *project);

AmpGroup* amp_project_add_group (AmpProject *project, AmpGroup *parent, const gchar *name, GError **error);
AmpGroup* amp_project_add_sibling_group (AmpProject *project, AmpGroup *parent, const gchar *name, gboolean after, AmpGroup *sibling, GError **error);
void amp_project_remove_group (AmpProject *project, AmpGroup *group, GError **error);

AmpTarget* amp_project_add_target (AmpProject *project, AmpGroup *parent, const gchar *name, AnjutaProjectTargetType type, GError **error);
Expand Down
2 changes: 1 addition & 1 deletion src/am-scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ amp_am_scanner_parse_token (AmpAmScanner *scanner, AnjutaToken *token, GError **
AnjutaTokenStream *stream;

stream = anjuta_token_stream_push (scanner->stream, token);
first = anjuta_token_stream_get_root (scanner->stream);

if (scanner->stream != NULL)
{
/* Parse an included file or a expanded variable */

first = anjuta_token_stream_get_root (scanner->stream);
scanner->stream = stream;
yypush_buffer_state(yy_create_buffer(NULL, YY_BUF_SIZE, scanner->scanner), scanner->scanner);
}
Expand Down
18 changes: 17 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ main(int argc, char *argv[])
{
IAnjutaProject *project;
AnjutaProjectNode *node;
AnjutaProjectNode *sibling;
char **command;
GOptionContext *context;
GError *error = NULL;
Expand Down Expand Up @@ -381,7 +382,22 @@ main(int argc, char *argv[])
node = get_node (project, command[2]);
if (g_ascii_strcasecmp (command[1], "group") == 0)
{
ianjuta_project_add_group (project, node, command[3], NULL);
if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "before") == 0))
{
sibling = get_node (project, command[5]);
amp_project_add_sibling_group (project, node, command[3], FALSE, sibling, NULL);
command += 2;
}
else if ((command[4] != NULL) && (g_ascii_strcasecmp (command[4], "after") == 0))
{
sibling = get_node (project, command[5]);
amp_project_add_sibling_group (project, node, command[3], TRUE, sibling, NULL);
command += 2;
}
else
{
ianjuta_project_add_group (project, node, command[3], NULL);
}
}
else if (g_ascii_strcasecmp (command[1], "target") == 0)
{
Expand Down

0 comments on commit 09bef3e

Please sign in to comment.