[anjuta] am-project: Add object node
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] am-project: Add object node
- Date: Sat, 4 Jun 2011 15:06:54 +0000 (UTC)
commit 113e0167a31ae5dc62c2e43f5d86063b441d3d6c
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sat Jun 4 16:15:21 2011 +0200
am-project: Add object node
plugins/am-project/Makefile.am | 2 +
plugins/am-project/am-project-private.h | 4 +
plugins/am-project/am-project.c | 66 +++++++++++--
plugins/am-project/am-project.h | 4 +-
plugins/am-project/amp-node.c | 5 +
plugins/am-project/amp-object.c | 157 +++++++++++++++++++++++++++++++
plugins/am-project/amp-object.h | 56 +++++++++++
plugins/am-project/plugin.c | 5 +-
plugins/am-project/projectparser.c | 2 +-
plugins/am-project/tests/anjuta.lst | 5 +-
10 files changed, 294 insertions(+), 12 deletions(-)
---
diff --git a/plugins/am-project/Makefile.am b/plugins/am-project/Makefile.am
index 18e78e3..1fe39c6 100644
--- a/plugins/am-project/Makefile.am
+++ b/plugins/am-project/Makefile.am
@@ -61,6 +61,8 @@ libam_project_la_SOURCES = \
amp-target.c \
amp-source.h \
amp-source.c \
+ amp-object.c \
+ amp-object.h \
command-queue.c \
command-queue.h
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index 38ff395..080eef6 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -24,6 +24,7 @@
#include "am-project.h"
#include "command-queue.h"
+#include <libanjuta/interfaces/ianjuta-language.h>
G_BEGIN_DECLS
@@ -76,6 +77,9 @@ struct _AmpProject {
/* Command queue */
PmCommandQueue *queue;
+
+ /* Language Manager */
+ IAnjutaLanguage *lang_manager;
};
typedef struct _AmpNodeInfo AmpNodeInfo;
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index bd77ed0..32f6038 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -950,10 +950,10 @@ project_load_target (AmpProject *project, AnjutaProjectNode *parent, AnjutaToken
}
static AnjutaToken*
-project_load_sources (AmpProject *project, AnjutaProjectNode *parent, AnjutaToken *variable, GHashTable *orphan_properties)
+project_load_sources (AmpProject *project, AnjutaProjectNode *group, AnjutaToken *variable, GHashTable *orphan_properties)
{
AnjutaToken *arg;
- GFile *parent_file = g_object_ref (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)));
+ GFile *group_file = g_object_ref (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (group)));
gchar *target_id = NULL;
target_id = anjuta_token_evaluate (anjuta_token_first_word (variable));
@@ -973,7 +973,7 @@ project_load_sources (AmpProject *project, AnjutaProjectNode *parent, AnjutaToke
find = target_id;
DEBUG_PRINT ("search for canonical %s", target_id);
- anjuta_project_node_children_traverse (parent, find_canonical_target, &find);
+ anjuta_project_node_children_traverse (group, find_canonical_target, &find);
target = (gchar *)find != target_id ? (AnjutaProjectNode *)find : NULL;
/* Get orphan buffer if there is no target */
@@ -1002,14 +1002,54 @@ project_load_sources (AmpProject *project, AnjutaProjectNode *parent, AnjutaToke
{
gchar *value;
AnjutaProjectNode *source;
+ AnjutaProjectNode *parent = target;
GFile *src_file;
+ GFileInfo* file_info;
value = anjuta_token_evaluate (arg);
if (value == NULL) continue;
+ src_file = g_file_get_child (group_file, value);
+ if (project->lang_manager != NULL)
+ {
+ file_info = g_file_query_info (src_file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (file_info)
+ {
+ gint id = ianjuta_language_get_from_mime_type (project->lang_manager,
+ g_file_info_get_content_type (file_info),
+ NULL);
+ if (id > 0)
+ {
+ const gchar *obj_ext = ianjuta_language_get_make_target (project->lang_manager, id, NULL);
+ if (obj_ext != NULL)
+ {
+ /* Create object node */
+ gchar *object_name;
+ gchar *ext;
+ GFile *obj_file;
+ AnjutaProjectNode *object;
+
+ ext = strrchr (value, '.');
+ if ((ext != NULL) && (ext != value)) *ext = '\0';
+ object_name = g_strconcat (value, obj_ext, NULL);
+ obj_file = g_file_get_child (group_file, object_name);
+ g_free (object_name);
+ object = amp_node_new_valid (group, ANJUTA_PROJECT_OBJECT | ANJUTA_PROJECT_PROJECT, obj_file, NULL, NULL);
+ g_object_unref (obj_file);
+ anjuta_project_node_append (parent, object);
+ parent = object;
+ }
+ }
+ g_object_unref (file_info);
+ }
+ }
+
/* Create source */
- src_file = g_file_get_child (parent_file, value);
- source = amp_node_new_valid (parent, ANJUTA_PROJECT_SOURCE | ANJUTA_PROJECT_PROJECT, src_file, NULL, NULL);
+ source = amp_node_new_valid (group, ANJUTA_PROJECT_SOURCE | ANJUTA_PROJECT_PROJECT, src_file, NULL, NULL);
g_object_unref (src_file);
if (source != NULL)
{
@@ -1017,14 +1057,14 @@ project_load_sources (AmpProject *project, AnjutaProjectNode *parent, AnjutaToke
DEBUG_PRINT ("add target child %p", target);
/* Add as target child */
- anjuta_project_node_append (target, source);
+ anjuta_project_node_append (parent, source);
}
g_free (value);
}
}
- g_object_unref (parent_file);
+ g_object_unref (group_file);
return NULL;
}
@@ -1524,6 +1564,11 @@ amp_project_duplicate_node (AnjutaProjectNode *old_node)
// the value will be overwritten with the new node empty value.
amp_package_node_add_token (AMP_PACKAGE_NODE (new_node), amp_package_node_get_token (AMP_PACKAGE_NODE (old_node)));
}
+ if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_ROOT)
+ {
+ // FIXME: It would be better to write a duplicate function to avoid this code
+ ((AmpProject *)new_node)->lang_manager = (((AmpProject *)old_node)->lang_manager != NULL) ? g_object_ref (((AmpProject *)old_node)->lang_manager) : NULL;
+ }
/* Keep old parent, Needed for source node to find project root node */
new_node->parent = old_node->parent;
@@ -1887,7 +1932,7 @@ amp_project_dump (AmpProject *project, AnjutaProjectNode *node)
AmpProject *
-amp_project_new (GFile *file, GError **error)
+amp_project_new (GFile *file, IAnjutaLanguage *language, GError **error)
{
AmpProject *project;
GFile *new_file;
@@ -1896,6 +1941,8 @@ amp_project_new (GFile *file, GError **error)
new_file = g_file_dup (file);
amp_root_node_set_file (AMP_ROOT_NODE (project), new_file);
g_object_unref (new_file);
+
+ project->lang_manager = (language != NULL) ? g_object_ref (language) : NULL;
return project;
}
@@ -2399,6 +2446,9 @@ amp_project_dispose (GObject *object)
if (project->monitor) g_object_unref (project->monitor);
project->monitor = NULL;
+ if (project->lang_manager) g_object_unref (project->lang_manager);
+ project->lang_manager = NULL;
+
G_OBJECT_CLASS (parent_class)->dispose (object);
}
diff --git a/plugins/am-project/am-project.h b/plugins/am-project/am-project.h
index 00a4423..775a924 100644
--- a/plugins/am-project/am-project.h
+++ b/plugins/am-project/am-project.h
@@ -30,6 +30,7 @@
#include <libanjuta/anjuta-token.h>
#include <libanjuta/anjuta-token-file.h>
#include <libanjuta/anjuta-token-list.h>
+#include <libanjuta/interfaces/ianjuta-language.h>
G_BEGIN_DECLS
@@ -46,6 +47,7 @@ typedef struct _AmpModuleNode AmpModuleNode;
typedef struct _AmpPackageNode AmpPackageNode;
typedef struct _AmpGroupNode AmpGroupNode;
typedef struct _AmpTargetNode AmpTargetNode;
+typedef struct _AmpObjectNode AmpObjectNode;
typedef struct _AmpSourceNode AmpSourceNode;
struct _AmpProjectClass {
@@ -55,7 +57,7 @@ struct _AmpProjectClass {
typedef struct _AmpProperty AmpProperty;
GType amp_project_get_type (void);
-AmpProject *amp_project_new (GFile *file, GError **error);
+AmpProject *amp_project_new (GFile *file, IAnjutaLanguage *language, GError **error);
void amp_project_register (GTypeModule *module);
diff --git a/plugins/am-project/amp-node.c b/plugins/am-project/amp-node.c
index 2008d07..596720a 100644
--- a/plugins/am-project/amp-node.c
+++ b/plugins/am-project/amp-node.c
@@ -31,6 +31,7 @@
#include "amp-package.h"
#include "amp-group.h"
#include "amp-target.h"
+#include "amp-object.h"
#include "amp-source.h"
#include <libanjuta/anjuta-debug.h>
@@ -70,6 +71,9 @@ amp_node_new_valid(AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile
case ANJUTA_PROJECT_TARGET:
node = ANJUTA_PROJECT_NODE (amp_target_node_new_valid (name, type, NULL, 0, error));
break;
+ case ANJUTA_PROJECT_OBJECT:
+ node = ANJUTA_PROJECT_NODE (amp_object_node_new_valid (file, error));
+ break;
case ANJUTA_PROJECT_SOURCE:
/* Look for parent */
if (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_TARGET)
@@ -296,5 +300,6 @@ amp_node_register (GTypeModule *module)
amp_package_node_register (module);
amp_group_node_register (module);
amp_target_node_register (module);
+ amp_object_node_register (module);
amp_source_node_register (module);
}
diff --git a/plugins/am-project/amp-object.c b/plugins/am-project/amp-object.c
new file mode 100644
index 0000000..ad9f489
--- /dev/null
+++ b/plugins/am-project/amp-object.c
@@ -0,0 +1,157 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4; coding: utf-8 -*- */
+/* am-object.c
+ *
+ * Copyright (C) 2011 Sébastien Granjoux
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "amp-object.h"
+
+#include "amp-node.h"
+#include "am-scanner.h"
+#include "am-properties.h"
+#include "am-writer.h"
+
+
+#include <libanjuta/interfaces/ianjuta-project.h>
+
+#include <libanjuta/anjuta-debug.h>
+
+#include <glib/gi18n.h>
+
+#include <memory.h>
+#include <string.h>
+#include <ctype.h>
+
+/* Types
+ *---------------------------------------------------------------------------*/
+
+struct _AmpObjectNode {
+ AnjutaProjectNode base;
+};
+
+
+
+
+/* Object object
+ *---------------------------------------------------------------------------*/
+
+AnjutaProjectNode*
+amp_object_node_new (GFile *file)
+{
+ AmpObjectNode *node = NULL;
+
+ node = g_object_new (AMP_TYPE_OBJECT_NODE, NULL);
+ node->base.file = g_object_ref (file);
+
+ return ANJUTA_PROJECT_NODE (node);
+}
+
+AnjutaProjectNode*
+amp_object_node_new_valid (GFile *file, GError **error)
+{
+ return amp_object_node_new (file);
+}
+
+void
+amp_object_node_free (AmpObjectNode *node)
+{
+ g_object_unref (G_OBJECT (node));
+}
+
+/* AmpNode implementation
+ *---------------------------------------------------------------------------*/
+
+static gboolean
+amp_object_node_update (AmpNode *node, AmpNode *new_node)
+{
+
+ return TRUE;
+}
+
+static gboolean
+amp_object_node_write (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
+{
+ return TRUE;
+}
+
+static gboolean
+amp_object_node_erase (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
+{
+ return TRUE;
+}
+
+
+
+
+/* GObjet implementation
+ *---------------------------------------------------------------------------*/
+
+typedef struct _AmpObjectNodeClass AmpObjectNodeClass;
+
+struct _AmpObjectNodeClass {
+ AmpNodeClass parent_class;
+};
+
+G_DEFINE_DYNAMIC_TYPE (AmpObjectNode, amp_object_node, AMP_TYPE_NODE);
+
+static void
+amp_object_node_init (AmpObjectNode *node)
+{
+ node->base.type = ANJUTA_PROJECT_OBJECT;
+ node->base.native_properties = NULL;
+ node->base.state = 0;
+}
+
+static void
+amp_object_node_finalize (GObject *object)
+{
+ AmpObjectNode *node = AMP_OBJECT_NODE (object);
+
+ G_OBJECT_CLASS (amp_object_node_parent_class)->finalize (object);
+}
+
+static void
+amp_object_node_class_init (AmpObjectNodeClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+ AmpNodeClass* node_class;
+
+ object_class->finalize = amp_object_node_finalize;
+
+ node_class = AMP_NODE_CLASS (klass);
+ node_class->update = amp_object_node_update;
+ node_class->write = amp_object_node_write;
+ node_class->erase = amp_object_node_erase;
+}
+
+static void
+amp_object_node_class_finalize (AmpObjectNodeClass *klass)
+{
+}
+
+void
+amp_object_node_register (GTypeModule *module)
+{
+ amp_object_node_register_type (module);
+}
+
diff --git a/plugins/am-project/amp-object.h b/plugins/am-project/amp-object.h
new file mode 100644
index 0000000..deda26b
--- /dev/null
+++ b/plugins/am-project/amp-object.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4; coding: utf-8 -*- */
+/* amp-object.h
+ *
+ * Copyright (C) 2011 Sébastien Granjoux
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _AMP_OBJECT_H_
+#define _AMP_OBJECT_H_
+
+#include "am-project-private.h"
+#include "am-scanner.h"
+
+#include <glib-object.h>
+
+#include <libanjuta/anjuta-project.h>
+#include <libanjuta/anjuta-token.h>
+#include <libanjuta/anjuta-token-file.h>
+
+G_BEGIN_DECLS
+
+/* Type macros
+ *---------------------------------------------------------------------------*/
+
+#define AMP_TYPE_OBJECT_NODE (amp_object_node_get_type ())
+#define AMP_OBJECT_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AMP_TYPE_OBJECT_NODE, AmpObjectNode))
+
+GType amp_object_node_get_type (void) G_GNUC_CONST;
+
+
+
+void amp_object_node_register (GTypeModule *module);
+
+AnjutaProjectNode* amp_object_node_new (GFile *file);
+AnjutaProjectNode* amp_object_node_new_valid (GFile *file, GError **error);
+
+void amp_object_node_free (AmpObjectNode *node);
+
+
+G_END_DECLS
+
+#endif /* _AMP_OBJECT_H_ */
diff --git a/plugins/am-project/plugin.c b/plugins/am-project/plugin.c
index f0c3377..0b3fc87 100644
--- a/plugins/am-project/plugin.c
+++ b/plugins/am-project/plugin.c
@@ -54,9 +54,12 @@ static IAnjutaProject*
iproject_backend_new_project (IAnjutaProjectBackend* backend, GFile *file, GError** err)
{
IAnjutaProject *project;
+ IAnjutaLanguage* langman;
+
DEBUG_PRINT("create new amp project");
- project = (IAnjutaProject *)amp_project_new (file, err);
+ langman = anjuta_shell_get_interface (ANJUTA_PLUGIN (backend)->shell, IAnjutaLanguage, NULL);
+ project = (IAnjutaProject *)amp_project_new (file, langman, err);
return project;
}
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 73db339..9ea17f5 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -535,7 +535,7 @@ main(int argc, char *argv[])
}
else
{
- project = IANJUTA_PROJECT (amp_project_new (file, NULL));
+ project = IANJUTA_PROJECT (amp_project_new (file, NULL, NULL));
}
}
diff --git a/plugins/am-project/tests/anjuta.lst b/plugins/am-project/tests/anjuta.lst
index 3980c79..33ef0d8 100644
--- a/plugins/am-project/tests/anjuta.lst
+++ b/plugins/am-project/tests/anjuta.lst
@@ -267,10 +267,11 @@ PROPERTY (URL): http://www.anjuta.org/
PROPERTY (Installation directory): idldir
SOURCE (): libanjuta/interfaces/libanjuta.idl
GROUP (): tests
+ PROPERTY (C preprocessor flags): $(WARN_CFLAGS) $(DEPRECATED_FLAGS) $(GDA_CFLAGS) $(LIBANJUTA_CFLAGS)
TARGET (): anjuta-tabber-test
PROPERTY (Do not install): true
PROPERTY (C compiler flags): $(LIBANJUTA_CFLAGS)
- PROPERTY (Libraries): $(LIBANJUTA_LIBS)
+ PROPERTY (Libraries): $(LIBANJUTA_LIBS) $(ANJUTA_LIBS)
SOURCE (): libanjuta/tests/anjuta-tabber-test.c
TARGET (): libanjuta-3.la
PROPERTY (Installation directory): libdir
@@ -495,6 +496,8 @@ PROPERTY (URL): http://www.anjuta.org/
SOURCE (): plugins/am-project/amp-target.c
SOURCE (): plugins/am-project/amp-source.h
SOURCE (): plugins/am-project/amp-source.c
+ SOURCE (): plugins/am-project/amp-object.c
+ SOURCE (): plugins/am-project/amp-object.h
SOURCE (): plugins/am-project/command-queue.c
SOURCE (): plugins/am-project/command-queue.h
TARGET (): projectparser
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]