[geany/geany-plugins] d46cef: workbench: import Geany project data

LarsDW223 git-noreply at xxxxx
Wed Oct 18 20:10:43 UTC 2017


Branch:      refs/heads/master
Author:      LarsDW223 <lars_paulsen at web.de>
Committer:   LarsDW223 <lars_paulsen at web.de>
Date:        Wed, 18 Oct 2017 20:10:43 UTC
Commit:      d46ceff2d8dc07d4a75ea39753fc7809ec126a1d
             https://github.com/geany/geany-plugins/commit/d46ceff2d8dc07d4a75ea39753fc7809ec126a1d

Log Message:
-----------
workbench: import Geany project data

The workbench plugin now imports the "base_path" and "file_patterns" from Geany's project settings
as an workbench project directory. That directory is then treated as the project's base dir.

In the config file all settings related to the project's base dir are prefixed with "Prj-"
instead of e.g. "Dir1-". On loading of a workbench's project, the plugin checks if there
is a "base_path" in the "project" section but no "Prj-BaseDir" in the "Workbench" section.
In that case the data from the Geany project is imported. That means, the import happens only once.
On import, the project is marked as changed (a '*' is displayed after the project's name).

The project's base dir is always labeled "Base dir" and has a specific icon to show that it differ's
from the other directories. Also, it is always listed first/on top of the tree.


Modified Paths:
--------------
    workbench/icons/16x16/Makefile.am
    workbench/icons/16x16/workbench-basedir.png
    workbench/icons/24x24/Makefile.am
    workbench/icons/24x24/workbench-basedir.png
    workbench/icons/32x32/Makefile.am
    workbench/icons/32x32/workbench-basedir.png
    workbench/icons/48x48/Makefile.am
    workbench/icons/48x48/workbench-basedir.png
    workbench/icons/scalable/Makefile.am
    workbench/icons/scalable/workbench-basedir.svg
    workbench/src/sidebar.c
    workbench/src/wb_project.c
    workbench/src/wb_project.h

Modified: workbench/icons/16x16/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -2,6 +2,7 @@ iconsdir = $(datadir)/icons/hicolor/16x16
 icons_appsdir = $(iconsdir)/apps
 
 dist_icons_apps_DATA =							\
+	workbench-basedir.png						\
 	workbench-bookmark.png						\
 	workbench-dir.png							\
 	workbench-nodirs.png						\


Modified: workbench/icons/16x16/workbench-basedir.png
0 lines changed, 0 insertions(+), 0 deletions(-)
===================================================================
No diff available, check online


Modified: workbench/icons/24x24/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -2,6 +2,7 @@ iconsdir = $(datadir)/icons/hicolor/24x24
 icons_appsdir = $(iconsdir)/apps
 
 dist_icons_apps_DATA =							\
+	workbench-basedir.png						\
 	workbench-bookmark.png						\
 	workbench-dir.png							\
 	workbench-nodirs.png						\


Modified: workbench/icons/24x24/workbench-basedir.png
0 lines changed, 0 insertions(+), 0 deletions(-)
===================================================================
No diff available, check online


Modified: workbench/icons/32x32/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -2,6 +2,7 @@ iconsdir = $(datadir)/icons/hicolor/32x32
 icons_appsdir = $(iconsdir)/apps
 
 dist_icons_apps_DATA =							\
+	workbench-basedir.png						\
 	workbench-bookmark.png						\
 	workbench-dir.png							\
 	workbench-nodirs.png						\


Modified: workbench/icons/32x32/workbench-basedir.png
0 lines changed, 0 insertions(+), 0 deletions(-)
===================================================================
No diff available, check online


Modified: workbench/icons/48x48/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -2,6 +2,7 @@ iconsdir = $(datadir)/icons/hicolor/48x48
 icons_appsdir = $(iconsdir)/apps
 
 dist_icons_apps_DATA =							\
+	workbench-basedir.png						\
 	workbench-bookmark.png						\
 	workbench-dir.png							\
 	workbench-nodirs.png						\


Modified: workbench/icons/48x48/workbench-basedir.png
0 lines changed, 0 insertions(+), 0 deletions(-)
===================================================================
No diff available, check online


Modified: workbench/icons/scalable/Makefile.am
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -2,6 +2,7 @@ iconsdir = $(datadir)/icons/hicolor/scalable
 icons_appsdir = $(iconsdir)/apps
 
 dist_icons_apps_DATA =							\
+	workbench-basedir.svg						\
 	workbench-bookmark.svg						\
 	workbench-dir.svg							\
 	workbench-nodirs.svg						\


Modified: workbench/icons/scalable/workbench-basedir.svg
25 lines changed, 25 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg id="svg7384" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16.013" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <metadata id="metadata90">
+  <rdf:RDF>
+   <cc:Work rdf:about="">
+    <dc:format>image/svg+xml</dc:format>
+    <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+    <dc:title>Gnome Symbolic Icon Theme</dc:title>
+   </cc:Work>
+  </rdf:RDF>
+ </metadata>
+ <title id="title9167">Gnome Symbolic Icon Theme</title>
+ <g id="layer13" transform="translate(-562.99 -175)">
+  <g id="g5388" transform="translate(405.62 -584.9)">
+   <title id="title5390">go-home</title>
+   <g id="g5392" style="fill:#bebebe" transform="matrix(.026036 0 0 .026036 345.97 902.08)"></g>
+  </g>
+  <path id="path5414" style="block-progression:tb;text-indent:0;color:#000000;text-transform:none;fill:#bebebe" d="m565.78 180a1.0001 1.0001 0 0 0 -0.78 1v7a1.0001 1.0001 0 0 0 1 1h10a1.0001 1.0001 0 0 0 1 -1v-7a1.0001 1.0001 0 1 0 -2 0v6h-8v-6a1.0001 1.0001 0 0 0 -1.2188 -1z"/>
+  <path id="path6184" style="block-progression:tb;text-indent:0;color:#000000;text-transform:none;fill:#bebebe" d="m570.91 176a1.0001 1.0001 0 0 0 -0.5 0.1875l-7 5a1.0063 1.0063 0 1 0 1.1875 1.625l6.4-4.57 6.4062 4.5625a1.0063 1.0063 0 1 0 1.1875 -1.625l-7-5a1.0001 1.0001 0 0 0 -0.69 -0.18z"/>
+  <rect id="rect6261" style="color:#bebebe;fill:#bebebe" height="6" width="3" y="183" x="569"/>
+  <rect id="rect8452-7" style="fill:#bebebe" rx="0" ry="1" transform="scale(-1,1)" width="1" y="182" x="-579" height="1"/>
+  <rect id="rect8452-8" style="fill:#bebebe" rx="0" ry="1" transform="scale(-1,1)" width="1" y="182" x="-564" height="1"/>
+ </g>
+</svg>


Modified: workbench/src/sidebar.c
39 lines changed, 32 insertions(+), 7 deletions(-)
===================================================================
@@ -237,6 +237,7 @@ static void sidebar_insert_project_directory(WB_PROJECT *prj, WB_PROJECT_DIR *di
 
 	g_hash_table_iter_init(&iter, wb_project_dir_get_file_table(directory));
 	abs_base_dir = get_combined_path(wb_project_get_filename(prj), wb_project_dir_get_base_dir(directory));
+
 	while (g_hash_table_iter_next(&iter, &key, &value))
 	{
 		gchar *path = get_relative_path(abs_base_dir, key);
@@ -266,7 +267,7 @@ static void sidebar_insert_project_directory(WB_PROJECT *prj, WB_PROJECT_DIR *di
 static void sidebar_insert_project_directories (WB_PROJECT *project, GtkTreeIter *parent, gint *position)
 {
 	GtkTreeIter iter;
-	GIcon *icon;
+	GIcon *icon, *icon_dir, *icon_base;
 	GSList *elem = NULL, *dirs;
 
 	if (project == NULL)
@@ -277,19 +278,42 @@ static void sidebar_insert_project_directories (WB_PROJECT *project, GtkTreeIter
 	dirs = wb_project_get_directories(project);
 	if (dirs != NULL)
 	{
-		icon = g_icon_new_for_string("workbench-dir", NULL);
+		const gchar *name;
+
+		icon_dir = g_icon_new_for_string("workbench-dir", NULL);
+		icon_base = g_icon_new_for_string("workbench-basedir", NULL);
 
 		foreach_slist (elem, dirs)
 		{
+			if (wb_project_dir_get_is_prj_base_dir(elem->data) == TRUE)
+			{
+				icon = icon_base;
+				name = _("Base dir");
+			}
+			else
+			{
+				icon = icon_dir;
+				name = wb_project_dir_get_name(elem->data);
+			}
+
 			gtk_tree_store_insert_with_values(sidebar.file_store, &iter, parent, *position,
 				FILEVIEW_COLUMN_ICON, icon,
-				FILEVIEW_COLUMN_NAME, wb_project_dir_get_name(elem->data),
+				FILEVIEW_COLUMN_NAME, name,
 				FILEVIEW_COLUMN_DATA_ID, DATA_ID_DIRECTORY,
 				FILEVIEW_COLUMN_ASSIGNED_DATA_POINTER, elem->data,
 				-1);
 			(*position)++;
 			sidebar_insert_project_directory(project, elem->data, &iter);
 		}
+
+		if (icon_dir != NULL)
+		{
+			g_object_unref(icon_dir);
+		}
+		if (icon_base != NULL)
+		{
+			g_object_unref(icon_base);
+		}
 	}
 	else
 	{
@@ -301,10 +325,11 @@ static void sidebar_insert_project_directories (WB_PROJECT *project, GtkTreeIter
 			FILEVIEW_COLUMN_DATA_ID, DATA_ID_NO_DIRS,
 			-1);
 		(*position)++;
-	}
-	if (icon != NULL)
-	{
-		g_object_unref(icon);
+
+		if (icon != NULL)
+		{
+			g_object_unref(icon);
+		}
 	}
 }
 


Modified: workbench/src/wb_project.c
165 lines changed, 144 insertions(+), 21 deletions(-)
===================================================================
@@ -56,6 +56,7 @@ struct S_WB_PROJECT_DIR
 	guint file_count;
 	guint folder_count;
 	GHashTable *file_table; /* contains all file names within base_dir, maps file_name->TMSourceFile */
+	gboolean is_prj_base_dir;
 };
 
 struct S_WB_PROJECT
@@ -248,6 +249,7 @@ static WB_PROJECT_DIR *wb_project_dir_new(const gchar *utf8_base_dir)
 		offset++;
 	}
 	dir->name = g_strdup(&(dir->base_dir[offset]));
+	dir->is_prj_base_dir = FALSE;
 	return dir;
 }
 
@@ -262,6 +264,38 @@ static void wb_project_dir_collect_source_files(G_GNUC_UNUSED gchar *filename, T
 }
 
 
+/** Set "is project base dir" of a project dir.
+ *
+ * @param directory The project dir
+ * @param value     TRUE:  directory is the base dir of the project
+ *                  FALSE: directory is another dir
+ * 
+ **/
+void wb_project_dir_set_is_prj_base_dir (WB_PROJECT_DIR *directory, gboolean value)
+{
+	if (directory != NULL)
+	{
+		directory->is_prj_base_dir = value;
+	}
+}
+
+
+/** Get "is project base dir" of a project dir.
+ *
+ * @param directory The project dir
+ * @return TRUE:  directory is the base dir of the project
+ *         FALSE: directory is another dir
+ *
+ **/
+gboolean wb_project_dir_get_is_prj_base_dir (WB_PROJECT_DIR *directory)
+{
+	if (directory != NULL)
+	{
+		return directory->is_prj_base_dir;
+	}
+	return FALSE;
+}
+
 /** Get the name of a project dir.
  *
  * @param directory The project dir
@@ -999,25 +1033,44 @@ static void wb_project_save_directories (gpointer data, gpointer user_data)
 	tmp = (WB_PROJECT_ON_SAVE_USER_DATA *)user_data;
 	dir = (WB_PROJECT_DIR *)data;
 
-	g_snprintf(key, sizeof(key), "Dir%u-BaseDir", tmp->dir_count);
-	g_key_file_set_string(tmp->kf, "Workbench", key, dir->base_dir);
+	if (wb_project_dir_get_is_prj_base_dir(dir) == TRUE)
+	{
+		g_key_file_set_string(tmp->kf, "Workbench", "Prj-BaseDir", dir->base_dir);
+
+		str = g_strjoinv(";", dir->file_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", "Prj-FilePatterns", str);
+		g_free(str);
+
+		str = g_strjoinv(";", dir->ignored_dirs_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", "Prj-IgnoredDirsPatterns", str);
+		g_free(str);
+
+		str = g_strjoinv(";", dir->ignored_file_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", "Prj-IgnoredFilePatterns", str);
+		g_free(str);
+	}
+	else
+	{
+		g_snprintf(key, sizeof(key), "Dir%u-BaseDir", tmp->dir_count);
+		g_key_file_set_string(tmp->kf, "Workbench", key, dir->base_dir);
 
-	g_snprintf(key, sizeof(key), "Dir%u-FilePatterns", tmp->dir_count);
-	str = g_strjoinv(";", dir->file_patterns);
-	g_key_file_set_string(tmp->kf, "Workbench", key, str);
-	g_free(str);
+		g_snprintf(key, sizeof(key), "Dir%u-FilePatterns", tmp->dir_count);
+		str = g_strjoinv(";", dir->file_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", key, str);
+		g_free(str);
 
-	g_snprintf(key, sizeof(key), "Dir%u-IgnoredDirsPatterns", tmp->dir_count);
-	str = g_strjoinv(";", dir->ignored_dirs_patterns);
-	g_key_file_set_string(tmp->kf, "Workbench", key, str);
-	g_free(str);
+		g_snprintf(key, sizeof(key), "Dir%u-IgnoredDirsPatterns", tmp->dir_count);
+		str = g_strjoinv(";", dir->ignored_dirs_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", key, str);
+		g_free(str);
 
-	g_snprintf(key, sizeof(key), "Dir%u-IgnoredFilePatterns", tmp->dir_count);
-	str = g_strjoinv(";", dir->ignored_file_patterns);
-	g_key_file_set_string(tmp->kf, "Workbench", key, str);
-	g_free(str);
+		g_snprintf(key, sizeof(key), "Dir%u-IgnoredFilePatterns", tmp->dir_count);
+		str = g_strjoinv(";", dir->ignored_file_patterns);
+		g_key_file_set_string(tmp->kf, "Workbench", key, str);
+		g_free(str);
 
-	tmp->dir_count++;
+		tmp->dir_count++;
+	}
 }
 
 
@@ -1236,10 +1289,12 @@ gboolean wb_project_load(WB_PROJECT *prj, gchar *filename, GError **error)
 {
 	GKeyFile *kf;
 	guint	 index;
-	gchar    *contents;
-	gchar    key[100];
-	gsize    length;
+	gchar	 *contents, *str;
+	gchar	 **splitv;
+	gchar	 key[100];
+	gsize	 length;
 	gboolean success = FALSE;
+	WB_PROJECT_DIR *new_dir;
 
 	g_return_val_if_fail(prj, FALSE);
 
@@ -1259,11 +1314,44 @@ gboolean wb_project_load(WB_PROJECT *prj, gchar *filename, GError **error)
 		return FALSE;
 	}
 
+	/* Import project's base path and file patterns, if not done yet.
+	   (from Geany's standard project configuration) */
+	if (g_key_file_has_group (kf, "project")
+		&& !g_key_file_has_key(kf, "Workbench", "Prj-BaseDir", NULL))
+	{
+		gchar *base_path;
+
+		base_path = g_key_file_get_string(kf, "project", "base_path", NULL);
+		if (base_path != NULL)
+		{
+			gchar *reldirname;
+
+			/* Convert dirname to path relative to the project file */
+			reldirname = get_any_relative_path(prj->filename, base_path);
+
+			new_dir = wb_project_add_directory_int(prj, reldirname, FALSE);
+			if (new_dir != NULL)
+			{
+				wb_project_set_modified(prj, TRUE);
+				wb_project_dir_set_is_prj_base_dir(new_dir, TRUE);
+				str = g_key_file_get_string(kf, "project", "file_patterns", NULL);
+				if (str != NULL)
+				{
+					splitv = g_strsplit (str, ";", -1);
+					wb_project_dir_set_file_patterns(new_dir, splitv);
+					g_strfreev(splitv);
+				}
+				g_free(str);
+			}
+
+			g_free(reldirname);
+			g_free(base_path);
+		}
+	}
+
 	if (g_key_file_has_group (kf, "Workbench"))
 	{
-		WB_PROJECT_DIR *new_dir;
-		gchar *str;
-		gchar **splitv, **bookmarks_strings;
+		gchar **bookmarks_strings;
 
 		/* Load project bookmarks from string list */
 		bookmarks_strings = g_key_file_get_string_list (kf, "Workbench", "Bookmarks", NULL, error);
@@ -1285,6 +1373,41 @@ gboolean wb_project_load(WB_PROJECT *prj, gchar *filename, GError **error)
 			g_strfreev(bookmarks_strings);
 		}
 
+		/* Load project base dir. */
+		str = g_key_file_get_string(kf, "Workbench", "Prj-BaseDir", NULL);
+		if (str != NULL)
+		{
+			new_dir = wb_project_add_directory_int(prj, str, FALSE);
+			if (new_dir != NULL)
+			{
+				wb_project_dir_set_is_prj_base_dir(new_dir, TRUE);
+
+				str = g_key_file_get_string(kf, "Workbench", "Prj-FilePatterns", NULL);
+				if (str != NULL)
+				{
+					splitv = g_strsplit (str, ";", -1);
+					wb_project_dir_set_file_patterns(new_dir, splitv);
+				}
+				g_free(str);
+
+				str = g_key_file_get_string(kf, "Workbench", "Prj-IgnoredDirsPatterns", NULL);
+				if (str != NULL)
+				{
+					splitv = g_strsplit (str, ";", -1);
+					wb_project_dir_set_ignored_dirs_patterns(new_dir, splitv);
+				}
+				g_free(str);
+
+				str = g_key_file_get_string(kf, "Workbench", "Prj-IgnoredFilePatterns", NULL);
+				if (str != NULL)
+				{
+					splitv = g_strsplit (str, ";", -1);
+					wb_project_dir_set_ignored_file_patterns(new_dir, splitv);
+				}
+				g_free(str);
+			}
+		}
+
 		/* Load project dirs */
 		for (index = 1 ; index < 1025 ; index++)
 		{


Modified: workbench/src/wb_project.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -41,6 +41,8 @@ gboolean wb_project_file_is_included(WB_PROJECT *prj, const gchar *filename);
 void wb_project_add_single_tm_file(WB_PROJECT *prj, const gchar *filename);
 void wb_project_remove_single_tm_file(WB_PROJECT *prj, const gchar *filename);
 
+void wb_project_dir_set_is_prj_base_dir (WB_PROJECT_DIR *directory, gboolean value);
+gboolean wb_project_dir_get_is_prj_base_dir (WB_PROJECT_DIR *directory);
 const gchar *wb_project_dir_get_name (WB_PROJECT_DIR *directory);
 GHashTable *wb_project_dir_get_file_table (WB_PROJECT_DIR *directory);
 gchar *wb_project_dir_get_base_dir (WB_PROJECT_DIR *directory);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list