1 /*
2  *      build.h - this file is part of Geany, a fast and lightweight IDE
3  *
4  *      Copyright 2005 The Geany contributors
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License along
17  *      with this program; if not, write to the Free Software Foundation, Inc.,
18  *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 /** @file build.h Interface to the Build menu functionality. */
22 
23 #ifndef GEANY_BUILD_H
24 #define GEANY_BUILD_H 1
25 
26 #include "document.h"
27 #include "filetypes.h"
28 
29 #include "gtkcompat.h"
30 
31 G_BEGIN_DECLS
32 
33 /** Groups of Build menu items. */
34 typedef enum
35 {
36 	GEANY_GBG_FT,		/**< filetype items */
37 	GEANY_GBG_NON_FT,	/**< non filetype items.*/
38 	GEANY_GBG_EXEC,		/**< execute items */
39 	GEANY_GBG_COUNT		/**< count of groups. */
40 } GeanyBuildGroup;
41 
42 /** Build menu item sources in increasing priority */
43 typedef enum
44 {
45 	GEANY_BCS_DEF,		/**< Default values. */
46 	GEANY_BCS_FT,		/**< System filetype values. */
47 	GEANY_BCS_HOME_FT,	/**< Filetypes in ~/.config/geany/filedefs */
48 	GEANY_BCS_PREF,		/**< Preferences file ~/.config/geany/geany.conf */
49 	GEANY_BCS_PROJ_FT,	/**< Project file filetype command */
50 	GEANY_BCS_PROJ,		/**< Project file if open. */
51 	GEANY_BCS_COUNT		/**< Count of sources. */
52 } GeanyBuildSource;
53 
54 /** The entries of a command for a menu item */
55 typedef enum GeanyBuildCmdEntries
56 {
57 	GEANY_BC_LABEL,				/**< The menu item label, _ marks mnemonic */
58 	GEANY_BC_COMMAND,			/**< The command to run. */
59 	GEANY_BC_WORKING_DIR,		/**< The directory to run in */
60 	GEANY_BC_CMDENTRIES_COUNT	/**< Count of entries */
61 } GeanyBuildCmdEntries;
62 
63 void build_activate_menu_item(const GeanyBuildGroup grp, const guint cmd);
64 
65 const gchar *build_get_current_menu_item(const GeanyBuildGroup grp, const guint cmd,
66                                          const GeanyBuildCmdEntries field);
67 
68 void build_remove_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const gint cmd);
69 
70 void build_set_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp,
71                          const guint cmd, const GeanyBuildCmdEntries field, const gchar *value);
72 
73 guint build_get_group_count(const GeanyBuildGroup grp);
74 
75 
76 #ifdef GEANY_PRIVATE
77 
78 /* include the fixed widgets in an array indexed by groups */
79 #define GBG_FIXED GEANY_GBG_COUNT
80 
81 enum GeanyBuildFixedMenuItems
82 {
83 	GBF_NEXT_ERROR,
84 	GBF_PREV_ERROR,
85 	GBF_COMMANDS,
86 	GBF_SEP_1,
87 	GBF_SEP_2,
88 	GBF_SEP_3,
89 	GBF_SEP_4,
90 	GBF_COUNT
91 };
92 
93 typedef struct GeanyBuildInfo
94 {
95 	GeanyBuildGroup	 grp;
96 	guint			 cmd;
97 	GPid			 pid;	/* process id of the spawned process */
98 	gchar			*dir;
99 	guint			 file_type_id;
100 	gchar			*custom_target;
101 	gint			 message_count;
102 } GeanyBuildInfo;
103 
104 extern GeanyBuildInfo build_info;
105 
106 /* * The command for a menu item. */
107 typedef struct GeanyBuildCommand
108 {
109 	/* * Pointers to g_string values of the command entries.
110 	 * Must be freed if the pointer is changed. */
111 	gchar 		*label;						/* *< Menu item label */
112 	gchar		*command;					/* *< Command to run */
113 	gchar		*working_dir;				/* *< working directory */
114 	gboolean	 exists;					/* *< If the entries have valid values. */
115 	gboolean	 changed;					/* *< Save on exit if @c changed, remove if not @c exist. */
116 	gboolean	 old;						/* *< Converted from old format. */
117 } GeanyBuildCommand;
118 
119 typedef struct BuildMenuItems
120 {
121 	GtkWidget		*menu;
122 	GtkWidget		**menu_item[GEANY_GBG_COUNT + 1];  /* +1 for fixed items */
123 } BuildMenuItems;
124 
125 /* a structure defining the destinations for a set of groups of commands & regex */
126 typedef struct BuildDestination
127 {
128 	GeanyBuildCommand	**dst[GEANY_GBG_COUNT];
129 	gchar				**fileregexstr;
130 	gchar				**nonfileregexstr;
131 } BuildDestination;
132 
133 /* opaque pointers returned from build functions and passed back to them */
134 typedef struct BuildTableFields *BuildTableData;
135 
136 
137 void build_init(void);
138 
139 void build_finalize(void);
140 
141 /* menu configuration dialog functions */
142 GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, BuildTableData *data, GeanyFiletype *ft);
143 
144 void build_read_project(GeanyFiletype *ft, BuildTableData build_properties);
145 
146 void build_free_fields(BuildTableData data);
147 
148 /* build response decode assistance function */
149 gboolean build_parse_make_dir(const gchar *string, gchar **prefix);
150 
151 /* build menu functions */
152 
153 void build_menu_update(GeanyDocument *doc);
154 
155 void build_toolbutton_build_clicked(GtkAction *action, gpointer user_data);
156 
157 GeanyBuildCommand *build_get_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const guint cmd);
158 
159 BuildMenuItems *build_get_menu_items(gint filetype_idx);
160 
161 /* load and store menu configuration */
162 void build_load_menu(GKeyFile *config, GeanyBuildSource dst, gpointer ptr);
163 
164 void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src);
165 
166 void build_set_group_count(GeanyBuildGroup grp, gint count);
167 
168 gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, guint *from);
169 
170 gboolean build_keybinding(guint key_id);
171 
172 #endif /* GEANY_PRIVATE */
173 
174 G_END_DECLS
175 
176 #endif /* GEANY_BUILD_H */
177