Plugins can override project patterns. In that case the "file patterns"
field is made inactive in the Project tab of the project properties
dialog.
Signed-off-by: Jiří Techet <[email protected]>
---
plugins/geanyfunctions.h | 2 +
src/plugindata.h | 9 +++++++
src/plugins.c | 8 +++++-
src/project.c | 57 +++++++++++++++++++++++++++++----------------
src/project.h | 1 +
5 files changed, 56 insertions(+), 21 deletions(-)
diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h
index 8e85467..892a0e6 100644
--- a/plugins/geanyfunctions.h
+++ b/plugins/geanyfunctions.h
@@ -66,6 +66,8 @@
geany_functions->p_document->document_get_basename_for_display
#define document_get_notebook_page \
geany_functions->p_document->document_get_notebook_page
+#define project_override_file_patterns \
+ geany_functions->p_project->project_override_file_patterns
#define editor_get_indent_prefs \
geany_functions->p_editor->editor_get_indent_prefs
#define editor_create_widget \
diff --git a/src/plugindata.h b/src/plugindata.h
index 8e44da5..f650ed7 100644
--- a/src/plugindata.h
+++ b/src/plugindata.h
@@ -263,6 +263,7 @@ typedef struct GeanyFunctions
struct MsgWinFuncs *p_msgwin; /**< See msgwindow.h */
struct StashFuncs *p_stash; /**< See stash.h */
struct SymbolsFuncs *p_symbols; /**< See symbols.h */
+ struct ProjectFuncs *p_project; /**< See project.h */
}
GeanyFunctions;
@@ -301,6 +302,14 @@ typedef struct DocumentFuncs
DocumentFuncs;
+/* See project.h */
+typedef struct ProjectFuncs
+{
+ void (*project_override_file_patterns) (gchar **patterns);
+}
+ProjectFuncs;
+
+
struct _ScintillaObject;
/** See http://scintilla.org for the full documentation. */
diff --git a/src/plugins.c b/src/plugins.c
index dac0c8e..9afe687 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -39,6 +39,7 @@
#include "support.h"
#include "utils.h"
#include "document.h"
+#include "project.h"
#include "filetypes.h"
#include "templates.h"
#include "sciwrappers.h"
@@ -111,6 +112,10 @@ static DocumentFuncs doc_funcs = {
&document_get_notebook_page
};
+static ProjectFuncs project_funcs = {
+ &project_override_file_patterns
+};
+
static EditorFuncs editor_funcs = {
&editor_get_indent_prefs,
&editor_create_widget,
@@ -355,7 +360,8 @@ static GeanyFunctions geany_functions = {
&scintilla_funcs,
&msgwin_funcs,
&stash_funcs,
- &symbols_funcs
+ &symbols_funcs,
+ &project_funcs
};
static GeanyData geany_data;
diff --git a/src/project.c b/src/project.c
index 7a8d59b..3f43c37 100644
--- a/src/project.c
+++ b/src/project.c
@@ -65,6 +65,7 @@ static struct
static gboolean entries_modified;
+static gboolean patterns_overridden;
/* simple struct to keep references to the elements of the properties dialog */
typedef struct _PropertyDialogElements
@@ -503,7 +504,6 @@ static void create_properties_dialog(PropertyDialogElements *e)
g_signal_connect(ui_lookup_widget(e->dialog, "radio_long_line_custom"), "toggled",
G_CALLBACK(on_radio_long_line_custom_toggled), ui_lookup_widget(e->dialog, "spin_long_line"));
-#if 0
label = gtk_label_new(_("File patterns:"));
/* <small>Separate multiple patterns by a new line</small> */
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 6, 7,
@@ -512,6 +512,10 @@ static void create_properties_dialog(PropertyDialogElements *e)
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
e->patterns = gtk_text_view_new();
+ ui_widget_set_tooltip_text(e->patterns,
+ _("Space separated list of file patterns used for the find in files dialog "
+ "(e.g. *.c *.h)"));
+ gtk_widget_set_sensitive(e->patterns, !patterns_overridden);
swin = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_size_request(swin, -1, 80);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
@@ -520,7 +524,6 @@ static void create_properties_dialog(PropertyDialogElements *e)
gtk_table_attach(GTK_TABLE(table), swin, 1, 2, 6, 7,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
-#endif
label = gtk_label_new(_("Project"));
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), table, label, 0);
@@ -567,26 +570,15 @@ static void show_project_properties(gboolean show_build)
gtk_text_buffer_set_text(buffer, p->description, -1);
}
-#if 0
if (p->file_patterns != NULL)
{ /* set the file patterns */
- gint i;
- gint len = g_strv_length(p->file_patterns);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->patterns));
- GString *str = g_string_sized_new(len * 4);
+ gchar *str;
- for (i = 0; i < len; i++)
- {
- if (p->file_patterns[i] != NULL)
- {
- g_string_append(str, p->file_patterns[i]);
- g_string_append_c(str, '\n');
- }
- }
- gtk_text_buffer_set_text(buffer, str->str, -1);
- g_string_free(str, TRUE);
+ str = g_strjoinv(" ", p->file_patterns);
+ gtk_text_buffer_set_text(buffer, str, -1);
+ g_free(str);
}
-#endif
widget = ui_lookup_widget(e->dialog, "project_notebook");
g_signal_emit_by_name(geany_object, "project-dialog-create", widget);
@@ -659,6 +651,9 @@ static GeanyProject *create_project(void)
priv.indentation = &indentation;
project->priv = &priv;
+ project->file_patterns = NULL;
+ patterns_overridden = FALSE;
+
project->long_line_behaviour = 1 /* use global settings */;
project->long_line_column = editor_prefs.long_line_global_column;
@@ -770,6 +765,8 @@ static gboolean update_config(const PropertyDialogElements *e)
GeanyBuildCommand *oldvalue;
GeanyFiletype *ft = doc ? doc->file_type : NULL;
GtkWidget *widget;
+ gchar *tmp;
+ GString *str;
/* get and set the project description */
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
@@ -807,16 +804,18 @@ static gboolean update_config(const PropertyDialogElements *e)
p->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
apply_editor_prefs();
-#if 0
/* get and set the project file patterns */
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->patterns));
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
g_strfreev(p->file_patterns);
- p->file_patterns = g_strsplit(tmp, "\n", -1);
+ g_strstrip(tmp);
+ str = g_string_new(tmp);
+ do {} while (utils_string_replace_all(str, " ", " "));
+ p->file_patterns = g_strsplit(str->str, " ", -1);
+ g_string_free(str, TRUE);
g_free(tmp);
-#endif
}
update_ui();
@@ -825,6 +824,24 @@ static gboolean update_config(const PropertyDialogElements *e)
}
+/**
+ * Overrides file patterns by a plugin.
+ *
+ * @param patterns The new patterns.
+ **/
+void project_override_file_patterns (gchar **patterns)
+{
+ if (app->project && patterns)
+ {
+ if (app->project->file_patterns)
+ g_strfreev(app->project->file_patterns);
+
+ app->project->file_patterns = g_strdupv(patterns);
+ patterns_overridden = TRUE;
+ }
+}
+
+
#ifndef G_OS_WIN32
static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
{
diff --git a/src/project.h b/src/project.h
index 33eb81e..564115f 100644
--- a/src/project.h
+++ b/src/project.h
@@ -60,6 +60,7 @@ typedef struct ProjectPrefs
extern ProjectPrefs project_prefs;
+void project_override_file_patterns (gchar **patterns);
void project_init(void);
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel