[anjuta] class-gen: bgo#672892 - Class generator should respect project's indent settings
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] class-gen: bgo#672892 - Class generator should respect project's indent settings
- Date: Mon, 30 Apr 2012 19:09:54 +0000 (UTC)
commit a4255f44d10cb58b7fecf6705cf8a9dd7597e3c9
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sun Apr 29 23:07:21 2012 +0200
class-gen: bgo#672892 - Class generator should respect project's indent settings
plugins/class-gen/plugin.c | 28 +++++++++++
plugins/class-gen/templates/cc-header.tpl | 7 ++-
plugins/class-gen/templates/cc-source.tpl | 7 ++-
plugins/class-gen/templates/go-header.tpl | 7 ++-
plugins/class-gen/templates/go-source.tpl | 7 ++-
plugins/class-gen/templates/js-source.tpl | 55 ++++++++++++-----------
plugins/class-gen/templates/py-source.tpl | 21 +++++----
plugins/class-gen/templates/vala-source.tpl | 65 ++++++++++++++-------------
8 files changed, 123 insertions(+), 74 deletions(-)
---
diff --git a/plugins/class-gen/plugin.c b/plugins/class-gen/plugin.c
index 36c1898..746437d 100644
--- a/plugins/class-gen/plugin.c
+++ b/plugins/class-gen/plugin.c
@@ -27,6 +27,7 @@
#include <libanjuta/interfaces/ianjuta-project-manager.h>
#include <libanjuta/interfaces/ianjuta-file-loader.h>
#include <libanjuta/interfaces/ianjuta-vcs.h>
+#include <libanjuta/interfaces/ianjuta-editor.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
@@ -37,6 +38,14 @@
#define ICON_FILE "anjuta-class-gen-plugin-48.png"
+/* Common editor preferences */
+#define ANJUTA_PREF_SCHEMA_PREFIX "org.gnome.anjuta."
+
+/* Indentation template variables */
+#define INDENT_WIDTH_PROPERTY "IndentWidth"
+#define TAB_WIDTH_PROPERTY "TabWidth"
+#define USE_TABS_PROPERTY "UseTabs"
+
static gpointer parent_class;
static void
@@ -413,6 +422,10 @@ cg_plugin_window_response_cb (G_GNUC_UNUSED GtkDialog *dialog,
if (result == TRUE)
{
+ GSettings *settings;
+ gboolean flag;
+ gint i;
+
values = cg_window_create_value_heap (plugin->window);
manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
@@ -431,6 +444,21 @@ cg_plugin_window_response_cb (G_GNUC_UNUSED GtkDialog *dialog,
g_hash_table_insert (values, "ProjectName", name);
}
+ /* Set indentation settings */
+ /* Add use-tabs property */
+ settings = g_settings_new (ANJUTA_PREF_SCHEMA_PREFIX IANJUTA_EDITOR_PREF_SCHEMA);
+ flag = g_settings_get_boolean (settings, IANJUTA_EDITOR_USE_TABS_KEY);
+ g_hash_table_insert (values, USE_TABS_PROPERTY, g_strdup (flag ? "1" : "0"));
+
+ /* Add tab-width property */
+ i = g_settings_get_int (settings, IANJUTA_EDITOR_TAB_WIDTH_KEY);
+ g_hash_table_insert (values, TAB_WIDTH_PROPERTY, g_strdup_printf("%d", i));
+
+ /* Add indent-width property */
+ i = g_settings_get_int (settings, IANJUTA_EDITOR_INDENT_WIDTH_KEY);
+ g_hash_table_insert (values, INDENT_WIDTH_PROPERTY, g_strdup_printf("%d", i));
+ g_object_unref (settings);
+
plugin->generator = cg_generator_new (
cg_window_get_header_template(plugin->window),
cg_window_get_source_template(plugin->window),
diff --git a/plugins/class-gen/templates/cc-header.tpl b/plugins/class-gen/templates/cc-header.tpl
index aeef283..304cf92 100644
--- a/plugins/class-gen/templates/cc-header.tpl
+++ b/plugins/class-gen/templates/cc-header.tpl
@@ -1,8 +1,10 @@
[+ autogen5 template +]
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+[+INCLUDE (string-append "indent.tpl") \+]
+/* [+INVOKE EMACS-MODELINE MODE="C" \+] */
+[+INVOKE START-INDENT\+]
/*
* [+ProjectName+][+IF (=(get "Headings") "1")+]
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -38,3 +40,4 @@ class [+ClassName+][+IF (not (=(get "BaseClass") ""))+]: [+Inheritance+] [+BaseC
ENDFOR+]};
#endif // _[+ (string-upcase(string->c-name!(get "HeaderFile"))) +]_
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/cc-source.tpl b/plugins/class-gen/templates/cc-source.tpl
index c61693a..c62c678 100644
--- a/plugins/class-gen/templates/cc-source.tpl
+++ b/plugins/class-gen/templates/cc-source.tpl
@@ -1,8 +1,10 @@
[+ autogen5 template +]
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+[+INCLUDE (string-append "indent.tpl") \+]
+/* [+INVOKE EMACS-MODELINE MODE="C" \+] */
+[+INVOKE START-INDENT\+]
/*
* [+ProjectName+][+IF (=(get "Headings") "1")+]
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -30,3 +32,4 @@
ENDFOR+][+
ENDFOR+][+
ENDIF+]
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/go-header.tpl b/plugins/class-gen/templates/go-header.tpl
index 8e896d1..47b9c98 100644
--- a/plugins/class-gen/templates/go-header.tpl
+++ b/plugins/class-gen/templates/go-header.tpl
@@ -1,8 +1,10 @@
[+ autogen5 template +]
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+[+INCLUDE (string-append "indent.tpl") \+]
+/* [+INVOKE EMACS-MODELINE MODE="C" \+] */
+[+INVOKE START-INDENT\+]
/*
* [+ProjectName+][+IF (=(get "Headings") "1")+]
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -81,3 +83,4 @@ ENDIF+]
G_END_DECLS
#endif /* _[+ (string-upcase(string->c-name!(get "HeaderFile"))) +]_ */
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/go-source.tpl b/plugins/class-gen/templates/go-source.tpl
index c26e6e4..2a19899 100644
--- a/plugins/class-gen/templates/go-source.tpl
+++ b/plugins/class-gen/templates/go-source.tpl
@@ -1,8 +1,10 @@
[+ autogen5 template +]
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+[+INCLUDE (string-append "indent.tpl") \+]
+/* [+INVOKE EMACS-MODELINE MODE="C" \+] */
+[+INVOKE START-INDENT\+]
/*
* [+ProjectName+][+IF (=(get "Headings") "1")+]
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -314,3 +316,4 @@ FOR Members+][+
ENDIF+][+
ENDIF+][+
ENDFOR+]
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/js-source.tpl b/plugins/class-gen/templates/js-source.tpl
index 32c3658..055e10b 100644
--- a/plugins/class-gen/templates/js-source.tpl
+++ b/plugins/class-gen/templates/js-source.tpl
@@ -17,10 +17,12 @@
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+]
-/* -*- Mode: javascript; js-basic-offset: 4; indent-tabs-mode: nil -*-
+[+INCLUDE (string-append "indent.tpl") \+]
+[+INVOKE START-INDENT\+]
+/* [+INVOKE EMACS-MODELINE MODE="javascript" \+] */
*
* [+ProjectName+][+IF (=(get "Headings") "1")+]
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -29,52 +31,53 @@
[+ESAC+] */
[+
FOR Imports +][+
- IF (not (=(get "Name") "")) +]
+ IF (not (=(get "Name") "")) +]
const [+Name+] = imports.[+Module+];[+
- IF (last-for?) +]
+ IF (last-for?) +]
[+
- ENDIF+][+
- ENDIF+][+
+ ENDIF+][+
+ ENDIF+][+
ENDFOR+][+
IF (not (=(get "BaseClass") "")) +]
function [+BaseClass+]([+Initargs+]){
- this._init([+Initargs+]);
+ this._init([+Initargs+]);
}
[+BaseClass+].prototype = {
- _init: function([+Initargs+]) {
- // The Base class.
- }
+ _init: function([+Initargs+]) {
+ // The Base class.
+ }
};[+
ENDIF+]
function [+ClassName+]() {
- this._init([+Initargs+]);
+ this._init([+Initargs+]);
}
[+ClassName+].prototype = {[+
IF (not (=(get "BaseClass") "")) +]
- __proto__ : [+BaseClass+].prototype,
+ __proto__ : [+BaseClass+].prototype,
[+
ENDIF+]
- _init: function([+Initargs+]) {[+
+ _init: function([+Initargs+]) {[+
FOR Variables +][+
- IF (not (=(get "Name") "")) +]
- this.[+Name+] = [+Value+];[+
- ENDIF+][+
+ IF (not (=(get "Name") "")) +]
+ this.[+Name+] = [+Value+];[+
+ ENDIF+][+
ENDFOR+]
- },
+ },
[+
FOR Methods +][+
- IF (not (=(get "Name") "")) +]
- [+Name+] : function[+Arguments+] {
- // TODO: Delete this line and add something useful[+
- IF (last-for?) +]
- }[+
- ELSE+]
- },
+ IF (not (=(get "Name") "")) +]
+ [+Name+] : function[+Arguments+] {
+ // TODO: Delete this line and add something useful[+
+ IF (last-for?) +]
+ }[+
+ ELSE+]
+ },
[+
- ENDIF+][+
- ENDIF+][+
+ ENDIF+][+
+ ENDIF+][+
ENDFOR+]
};
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/py-source.tpl b/plugins/class-gen/templates/py-source.tpl
index 4bfa8e1..2c780a4 100644
--- a/plugins/class-gen/templates/py-source.tpl
+++ b/plugins/class-gen/templates/py-source.tpl
@@ -17,10 +17,12 @@
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+]
-# -*- Mode: Python; Coding: utf-8; tab-width: 4 -*-
+[+INCLUDE (string-append "indent.tpl") \+]
+[+INVOKE START-INDENT\+]
+# [+INVOKE EMACS-MODELINE MODE="Python" \+]
#
# [+ProjectName+][+IF (=(get "Headings") "1")+]
-# Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+# Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
#
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") "# ")+]
@@ -30,14 +32,15 @@
class [+ClassName+]([+IF (not (=(get "BaseClass") ""))+][+BaseClass+][+ENDIF+]):[+
FOR Constvars +][+
- IF (not (=(get "Name") "")) +]
- [+Name+] = [+Value+][+
- ENDIF +][+
+ IF (not (=(get "Name") "")) +]
+ [+Name+] = [+Value+][+
+ ENDIF +][+
ENDFOR +][+
FOR Methods +][+
- IF (not (=(get "Name") "")) +]
- def [+Name+][+Arguments+]:
- pass
+ IF (not (=(get "Name") "")) +]
+ def [+Name+][+Arguments+]:
+ pass
[+
- ENDIF +][+
+ ENDIF +][+
ENDFOR +]
+[+INVOKE END-INDENT\+]
diff --git a/plugins/class-gen/templates/vala-source.tpl b/plugins/class-gen/templates/vala-source.tpl
index 9b98d14..03becbc 100644
--- a/plugins/class-gen/templates/vala-source.tpl
+++ b/plugins/class-gen/templates/vala-source.tpl
@@ -17,10 +17,12 @@
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+]
-/* -*- Mode: vala; tab-width: 4; intend-tabs-mode: t -*- */
+[+INCLUDE (string-append "indent.tpl") \+]
+[+INVOKE START-INDENT\+]
+/* [+INVOKE EMACS-MODELINE MODE="vala" \+] */
/* [+ProjectName+][+IF (=(get "Headings") "1")+]
*
- * Copyright (C) [+AuthorName+] [+(shell "date +%Y")+] <[+AuthorEmail+]>[+ENDIF+]
+ * Copyright (C) [+(shell "date +%Y")+] [+AuthorName+] <[+AuthorEmail+]>[+ENDIF+]
*
[+CASE (get "License") +]
[+ == "BSD" +][+(bsd (get "ProjectName") (get "AuthorName") " * ")+]
@@ -30,43 +32,44 @@
[+ClassScope+] class [+ClassName+] : [+BaseClass+] {[+
FOR Properties+][+
- IF (=(get "Automatic") "Yes") +]
- [+Scope+] [+Type+] [+Name+] { get; set; }[+
- ELSE+]
- private [+Type+] _[+Name+] = [+Value+];[+
- ENDIF+][+
- IF (last-for?) +]
+ IF (=(get "Automatic") "Yes") +]
+ [+Scope+] [+Type+] [+Name+] { get; set; }[+
+ ELSE+]
+ private [+Type+] _[+Name+] = [+Value+];[+
+ ENDIF+][+
+ IF (last-for?) +]
[+
- ENDIF+][+
+ ENDIF+][+
ENDFOR+][+
FOR Properties+][+
- IF (=(get "Automatic") "No") +]
- [+Scope+] [+Type+] [+Name+] {[+
- IF (=(get "Getter") "YES")+]
- get { return _[+Name+] }[+
- ENDIF+][+
- IF (=(get "Setter") "YES")+]
- set { _[+Name+] = value }[+
- ENDIF+]
- }[+
- ENDIF+][+
+ IF (=(get "Automatic") "No") +]
+ [+Scope+] [+Type+] [+Name+] {[+
+ IF (=(get "Getter") "YES")+]
+ get { return _[+Name+] }[+
+ ENDIF+][+
+ IF (=(get "Setter") "YES")+]
+ set { _[+Name+] = value }[+
+ ENDIF+]
+ }[+
+ ENDIF+][+
ENDFOR+][+
FOR Signals+][+
- IF (first-for?) +]
- /* Signal definitions */[+ENDIF+]
- [+Scope+] signal void [+Name+] [+Arguments+];[+
+ IF (first-for?) +]
+ /* Signal definitions */[+ENDIF+]
+ [+Scope+] signal void [+Name+] [+Arguments+];[+
ENDFOR+]
- // Constructor
- public [+ClassName+] () {
-
- }
+ // Constructor
+ public [+ClassName+] () {
+
+ }
[+
FOR Methods+][+
- IF (first-for?) +]
- /* Method definitions */[+ENDIF+]
- [+Scope+] [+Type+] [+Name+] [+Arguments+] {
- // TODO: Add implementation here.
- }[+
+ IF (first-for?) +]
+ /* Method definitions */[+ENDIF+]
+ [+Scope+] [+Type+] [+Name+] [+Arguments+] {
+ // TODO: Add implementation here.
+ }[+
ENDFOR+]
}
+[+INVOKE END-INDENT\+]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]