[anjuta] language-support-cpp-java: clean preferences and remove choices preference



commit e7ff570b851bd2777f78f9bf8de14d477fd7933a
Author: Johannes Schmid <jhs gnome org>
Date:   Wed Mar 3 21:33:16 2010 +0100

    language-support-cpp-java: clean preferences and remove choices preference

 .../anjuta-language-cpp-java.ui                    |  119 +++++++++-----------
 .../language-support-cpp-java/cpp-java-assist.c    |  101 ++++++-----------
 plugins/language-support-cpp-java/plugin.c         |   32 +++++-
 plugins/language-support-cpp-java/plugin.h         |    3 +
 4 files changed, 120 insertions(+), 135 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
index ba46a4a..8d647c1 100644
--- a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
+++ b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
@@ -8,14 +8,14 @@
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="adjustment2">
-    <property name="value">4</property>
     <property name="upper">100</property>
+    <property name="value">4</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
   <object class="GtkAdjustment" id="adjustment3">
-    <property name="value">10</property>
     <property name="upper">50</property>
+    <property name="value">10</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
@@ -34,6 +34,7 @@
             <child>
               <object class="GtkVBox" id="vbox1111">
                 <property name="visible">True</property>
+                <property name="orientation">vertical</property>
                 <property name="spacing">5</property>
                 <child>
                   <object class="GtkTable" id="table15">
@@ -281,6 +282,7 @@
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="orientation">vertical</property>
             <child>
               <object class="GtkFrame" id="frame45">
                 <property name="visible">True</property>
@@ -291,47 +293,9 @@
                 <child>
                   <object class="GtkVBox" id="vbox1118">
                     <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
                     <property name="spacing">5</property>
                     <child>
-                      <object class="GtkHBox" id="hbox1122">
-                        <property name="visible">True</property>
-                        <property name="border_width">5</property>
-                        <property name="spacing">5</property>
-                        <child>
-                          <object class="GtkSpinButton" id="preferences_spin:int:10:0:language.cpp.code.completion.choices">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="adjustment">adjustment3</property>
-                            <property name="climb_rate">1</property>
-                            <property name="numeric">True</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label1295">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="yalign">0</property>
-                            <property name="label" translatable="yes">Autocompletion pop up choices</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:language.cpp.code.completion.enable">
                         <property name="label" translatable="yes">Enable code completion</property>
                         <property name="visible">True</property>
@@ -344,35 +308,60 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:language.cpp.code.completion.space.after.func">
-                        <property name="label" translatable="yes">Add a space after function call autocompletion</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                        <property name="border_width">5</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="position">2</property>
+                        <property name="position">0</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:language.cpp.code.completion.brace.after.func">
-                        <property name="label" translatable="yes">Add '(' after function call autocompletion</property>
+                      <object class="GtkFrame" id="frame3">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                        <property name="border_width">5</property>
-                        <property name="draw_indicator">True</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">none</property>
+                        <child>
+                          <object class="GtkAlignment" id="alignment3">
+                            <property name="visible">True</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <object class="GtkVBox" id="vbox3">
+                                <property name="visible">True</property>
+                                <property name="orientation">vertical</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:language.cpp.code.completion.space.after.func">
+                                    <property name="label" translatable="yes">Add a space after function call autocompletion</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                    <property name="border_width">5</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:language.cpp.code.completion.brace.after.func">
+                                    <property name="label" translatable="yes">Add '(' after function call autocompletion</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                    <property name="border_width">5</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="label_item">
+                          <placeholder/>
+                        </child>
                       </object>
                       <packing>
-                        <property name="position">3</property>
+                        <property name="position">1</property>
                       </packing>
                     </child>
                     <child>
@@ -386,7 +375,7 @@
                         <property name="draw_indicator">True</property>
                       </object>
                       <packing>
-                        <property name="position">4</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                   </object>
diff --git a/plugins/language-support-cpp-java/cpp-java-assist.c b/plugins/language-support-cpp-java/cpp-java-assist.c
index bbcd120..0cc1de0 100644
--- a/plugins/language-support-cpp-java/cpp-java-assist.c
+++ b/plugins/language-support-cpp-java/cpp-java-assist.c
@@ -40,7 +40,6 @@
 #include "cpp-java-utils.h"
 
 #define PREF_AUTOCOMPLETE_ENABLE "language.cpp.code.completion.enable"
-#define PREF_AUTOCOMPLETE_CHOICES "language.cpp.code.completion.choices"
 #define PREF_AUTOCOMPLETE_SPACE_AFTER_FUNC "language.cpp.code.completion.space.after.func"
 #define PREF_AUTOCOMPLETE_BRACE_AFTER_FUNC "language.cpp.code.completion.brace.after.func"
 #define PREF_CALLTIP_ENABLE "language.cpp.code.calltip.enable"
@@ -363,12 +362,11 @@ static void free_proposal (IAnjutaEditorAssistProposal* proposal)
 static void
 cpp_java_assist_update_autocomplete (CppJavaAssist *assist)
 {
-	gint max_completions, length;
+	gint length;
 	GList *completion_list;
+	GList *node, *suggestions = NULL;
 
 	gboolean queries_active = (assist->priv->async_file || assist->priv->async_project || assist->priv->async_system);
-
-	// DEBUG_PRINT ("Queries active: %d", queries_active);
 	
 	if (assist->priv->completion_cache == NULL)
 	{
@@ -387,11 +385,6 @@ cpp_java_assist_update_autocomplete (CppJavaAssist *assist)
 	{
 		completion_list = assist->priv->completion_cache->items;
 	}
-		
-	max_completions =
-		anjuta_preferences_get_int_with_default (assist->priv->preferences,
-												 PREF_AUTOCOMPLETE_CHOICES,
-												 MAX_COMPLETIONS);
 
 	length = g_list_length (completion_list);
 
@@ -406,50 +399,31 @@ cpp_java_assist_update_autocomplete (CppJavaAssist *assist)
 			ianjuta_editor_assist_proposals (assist->priv->iassist, IANJUTA_PROVIDER(assist),
 		                                 NULL, !queries_active, NULL);
 		}
-	}
-	
-	if (length <= max_completions)
-	{
-		GList *node, *suggestions = NULL;
-			
-		for (node = completion_list; node != NULL; node = g_list_next (node))
-		{
-			CppJavaAssistTag *tag = node->data;
-			IAnjutaEditorAssistProposal* proposal = g_new0(IAnjutaEditorAssistProposal, 1);
-				
-			if (tag->is_func)
-				proposal->label = g_strdup_printf ("%s()", tag->name);
-			else
-				proposal->label = g_strdup(tag->name);
-				
-			proposal->data = tag;
-			proposal->icon = tag->icon;
-			suggestions = g_list_prepend (suggestions, proposal);
-		}
-		suggestions = g_list_reverse (suggestions);
-		ianjuta_editor_assist_proposals (assist->priv->iassist, IANJUTA_PROVIDER(assist),
-		                                 suggestions, !queries_active, NULL);
-		g_list_foreach (suggestions, (GFunc) free_proposal, NULL);
-		g_list_free (suggestions);
-	}
-	else
+	}	
+	for (node = completion_list; node != NULL; node = g_list_next (node))
 	{
-		ianjuta_editor_assist_proposals (assist->priv->iassist, IANJUTA_PROVIDER(assist),
-		                                 NULL, !queries_active, NULL);
-		return;
+		CppJavaAssistTag *tag = node->data;
+		IAnjutaEditorAssistProposal* proposal = g_new0(IAnjutaEditorAssistProposal, 1);
+
+		if (tag->is_func)
+			proposal->label = g_strdup_printf ("%s()", tag->name);
+		else
+			proposal->label = g_strdup(tag->name);
+
+		proposal->data = tag;
+		proposal->icon = tag->icon;
+		suggestions = g_list_prepend (suggestions, proposal);
 	}
+	suggestions = g_list_reverse (suggestions);
+	ianjuta_editor_assist_proposals (assist->priv->iassist, IANJUTA_PROVIDER(assist),
+	                                 suggestions, !queries_active, NULL);
+	g_list_foreach (suggestions, (GFunc) free_proposal, NULL);
+	g_list_free (suggestions);
 }
 
 static void
 cpp_java_assist_create_word_completion_cache (CppJavaAssist *assist)
-{
-	gint max_completions;
-
-	max_completions =
-		anjuta_preferences_get_int_with_default (assist->priv->preferences,
-												 PREF_AUTOCOMPLETE_CHOICES,
-												 MAX_COMPLETIONS);
-	
+{	
 	cpp_java_assist_destroy_completion_cache (assist);
 	if (!assist->priv->pre_word || strlen(assist->priv->pre_word) < 3)
 		return;
@@ -616,12 +590,6 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
 							  IAnjutaIterable *position_iter)
 {	
 	GList *tips = NULL;
-	gint max_completions;
-	
-	max_completions =
-		anjuta_preferences_get_int_with_default (assist->priv->preferences,
-												 PREF_AUTOCOMPLETE_CHOICES,
-												 MAX_COMPLETIONS);
 
 	/* Search file */
 	if (IANJUTA_IS_FILE (assist->priv->itip))
@@ -630,17 +598,18 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
 
 		if (file != NULL)
 		{
-			IAnjutaIterable* iter_file = ianjuta_symbol_manager_search_file (assist->priv->isymbol_manager,
-																			 IANJUTA_SYMBOL_TYPE_PROTOTYPE|
-																			 IANJUTA_SYMBOL_TYPE_FUNCTION|
-																			 IANJUTA_SYMBOL_TYPE_METHOD|
-																			 IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
-																			 TRUE, 
-																			 IANJUTA_SYMBOL_FIELD_SIMPLE|
-			                                          						 IANJUTA_SYMBOL_FIELD_TYPE|
-			                                          						 IANJUTA_SYMBOL_FIELD_ACCESS|
-			                                          						 IANJUTA_SYMBOL_FIELD_KIND,
-																			 call_context, file, max_completions, -1, NULL);
+			IAnjutaIterable* iter_file = 
+				ianjuta_symbol_manager_search_file (assist->priv->isymbol_manager,
+				                                    IANJUTA_SYMBOL_TYPE_PROTOTYPE|
+				                                    IANJUTA_SYMBOL_TYPE_FUNCTION|
+				                                    IANJUTA_SYMBOL_TYPE_METHOD|
+				                                    IANJUTA_SYMBOL_TYPE_MACRO_WITH_ARG,
+				                                    TRUE, 
+				                                    IANJUTA_SYMBOL_FIELD_SIMPLE|
+				                                    IANJUTA_SYMBOL_FIELD_TYPE|
+				                                    IANJUTA_SYMBOL_FIELD_ACCESS|
+				                                    IANJUTA_SYMBOL_FIELD_KIND,
+				                                    call_context, file, -1, -1, NULL);
 												 
 			if (iter_file) 
 			{
@@ -664,7 +633,7 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
 			                           IANJUTA_SYMBOL_FIELD_ACCESS|
 			                           IANJUTA_SYMBOL_FIELD_KIND,
 									   call_context, IANJUTA_SYMBOL_MANAGER_SEARCH_FS_PUBLIC,
-									   max_completions, -1, NULL);
+									   -1, -1, NULL);
 	if (iter_project)
 	{
 		tips = g_list_concat (tips, cpp_java_assist_create_calltips (iter_project));
@@ -684,7 +653,7 @@ cpp_java_assist_show_calltip (CppJavaAssist *assist, gchar *call_context,
 			                           IANJUTA_SYMBOL_FIELD_ACCESS|
 			                           IANJUTA_SYMBOL_FIELD_KIND,		    
 									   call_context, IANJUTA_SYMBOL_MANAGER_SEARCH_FS_PUBLIC,
-									   max_completions, -1, NULL);
+									   -1, -1, NULL);
 	if (iter_global)
 	{
 		tips = g_list_concat (tips, cpp_java_assist_create_calltips (iter_global));
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index 4d10279..7e55659 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -2008,30 +2008,54 @@ cpp_java_plugin_class_init (GObjectClass *klass)
 	klass->dispose = cpp_java_plugin_dispose;
 }
 
+#define PREF_WIDGET_SPACE "preferences_toggle:bool:1:1:language.cpp.code.completion.space.after.func"
+#define PREF_WIDGET_BRACE "preferences_toggle:bool:1:1:language.cpp.code.completion.brace.after.func"
+#define PREF_WIDGET_AUTO "preferences_toggle:bool:1:1:language.cpp.code.completion.enable"
+
+static void
+on_autocompletion_toggled (GtkToggleButton* button,
+                           GtkBuilder* bxml)
+{
+	GtkWidget* widget;
+	gboolean sensitive = gtk_toggle_button_get_active (button);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (bxml, PREF_WIDGET_SPACE));
+	gtk_widget_set_sensitive (widget, sensitive);
+	widget = GTK_WIDGET (gtk_builder_get_object (bxml, PREF_WIDGET_BRACE));
+	gtk_widget_set_sensitive (widget, sensitive);
+}
+
 static void
 ipreferences_merge (IAnjutaPreferences* ipref, AnjutaPreferences* prefs,
 					GError** e)
 {
 	GError* error = NULL;
-	GtkBuilder* bxml = gtk_builder_new ();
+	CppJavaPlugin* plugin = ANJUTA_PLUGIN_CPP_JAVA (ipref);
+	plugin->bxml = gtk_builder_new ();
+	GtkWidget* toggle;
 		
 	/* Add preferences */
-	if (!gtk_builder_add_from_file (bxml, PREFS_BUILDER, &error))
+	if (!gtk_builder_add_from_file (plugin->bxml, PREFS_BUILDER, &error))
 	{
 		g_warning ("Couldn't load builder file: %s", error->message);
 		g_error_free (error);
 	}
 	anjuta_preferences_add_from_builder (prefs,
-								 bxml, "preferences", _("C/C++/Java/Vala"),
+								 plugin->bxml, "preferences", _("C/C++/Java/Vala"),
 								 ICON_FILE);
-	g_object_unref (bxml);
+	toggle = GTK_WIDGET (gtk_builder_get_object (plugin->bxml, PREF_WIDGET_AUTO));
+	g_signal_connect (toggle, "toggled", G_CALLBACK (on_autocompletion_toggled),
+	                  plugin->bxml);
+	on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle), plugin->bxml);
 }
 
 static void
 ipreferences_unmerge (IAnjutaPreferences* ipref, AnjutaPreferences* prefs,
 					  GError** e)
 {
+	CppJavaPlugin* plugin = ANJUTA_PLUGIN_CPP_JAVA (ipref);
 	anjuta_preferences_remove_page(prefs, _("C/C++/Java/Vala"));
+	g_object_unref (plugin->bxml);
 }
 
 static void
diff --git a/plugins/language-support-cpp-java/plugin.h b/plugins/language-support-cpp-java/plugin.h
index 6f9b7bf..140f8ad 100644
--- a/plugins/language-support-cpp-java/plugin.h
+++ b/plugins/language-support-cpp-java/plugin.h
@@ -57,6 +57,9 @@ struct _CppJavaPlugin {
 	
 	/* Assist */
 	CppJavaAssist *assist;
+
+	/* Preferences */
+	GtkBuilder* bxml;
 };
 
 struct _CppJavaPluginClass {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]