Removed all files using cvs remove since setup is quite old and hasn't been
[geda-gaf/whiteaudio.git] / geda / src / m_project.c
blobfeb591312971e46efe8a4363b0ed02305f9ce85e
1 /* $Id$ */
3 /*******************************************************************************/
4 /* */
5 /* gEDA Suite Project Manager */
6 /* */
7 /* Copyright (C) 2002 Piotr Miarecki, sp9rve@eter.ariadna.pl */
8 /* */
9 /* This program is free software; you can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation version 2. */
12 /* */
13 /* This program is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with this program; if not, write to the Free Software */
20 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* */
22 /*******************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #define GTK_ENABLE_BROKEN
29 #include <gtk/gtk.h>
30 #include <stdlib.h>
32 #ifdef HAVE_STRING_H
33 #include <string.h>
34 #endif
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
40 #include "doc.h"
41 #include "filechoose.h"
42 #include "filetool.h"
43 #include "global.h"
44 #include "interface.h"
45 #include "m_action.h"
46 #include "m_project.h"
47 #include "msgbox.h"
48 #include "project.h"
49 #include "support.h"
53 void ProjectWidgetsHide(void);
54 void ProjectWidgetsShow(void);
58 /*******************************************************************************
60 Static variables and functions, definitions
62 *******************************************************************************/
64 static void ProjectPropertiesCreate(void);
65 static void ProjectPropertiesDestroy(void);
66 static BOOL ProjectPropertiesValid(void);
70 /*******************************************************************************
72 MENU : Project -> New
74 *******************************************************************************/
76 /* callback from menu */
77 void ProjectNew_MenuActivation(GtkMenuItem *pMenuItem, gpointer pUserData)
79 int iResult;
80 char szProjectFileName[TEXTLEN];
82 // strcpy(szProjectFileName, "unnamed.prj");
84 chdir(pDefaultProjectDir);
86 iResult = ProjectProperties(TRUE);
87 if (iResult == SUCCESS)
89 strcpy(szProjectFileName, Project.szDir);
90 strcat(szProjectFileName, "/");
91 strcat(szProjectFileName, Project.szName);
92 strcat(szProjectFileName, ".");
93 strcat(szProjectFileName, Project.szExt);
95 ProjectNew(szProjectFileName);
101 /*******************************************************************************
103 MENU : Project -> Open
105 *******************************************************************************/
107 /* callback from menu */
108 void ProjectOpen_MenuActivation(GtkMenuItem *pMenuItem, gpointer pUserData)
110 int iResult;
111 char szProjectFileName[TEXTLEN];
113 chdir(pDefaultProjectDir);
115 /* ask for project name */
116 strcpy(szProjectFileName, DEF_PRJNAME);
117 iResult = FileChoose(DEF_PRJEXT, szProjectFileName);
118 if (iResult != SUCCESS)
120 strcpy(szProjectFileName, "");
121 return;
124 ProjectOpen(szProjectFileName);
129 /*******************************************************************************
131 MENU : Project -> Properties
133 *******************************************************************************/
135 static GtkWindow *pWindow = NULL;
136 static BOOL bUpdateDir = FALSE;
137 static BOOL bUpdateBlock = FALSE;
138 static BOOL bCanceled = FALSE;
139 static BOOL bCompleted = FALSE;
142 /* callback from menu */
143 void ProjectProperties_MenuActivation(GtkMenuItem *pMenuItem, gpointer pUserData)
145 ProjectProperties(FALSE);
149 /* openning project properties window */
150 int ProjectProperties(BOOL bIsNew)
152 GtkEntry *pEntryName = NULL, *pEntryDir = NULL, *pEntryAuthor = NULL;
153 GtkText *pTextDescription;
154 gint x;
156 bUpdateDir = FALSE;
157 bUpdateBlock = FALSE;
159 /* default values for new project */
160 if (bIsNew)
162 strcpy(Project.szName, pDefaultProjectName);
163 strcpy(Project.szExt, pDefaultProjectExt);
165 strcpy(Project.szDir, pDefaultProjectDir);
166 strcat(Project.szDir, G_DIR_SEPARATOR_S);
167 strcat(Project.szDir, Project.szName);
169 strcpy(Project.szAuthor, getenv("USER"));
170 strcpy(Project.szDesc, "");
173 /* project editing loop */
174 bCanceled = FALSE;
175 bCompleted = FALSE;
176 while (!bCanceled && !bCompleted)
178 ProjectPropertiesCreate();
180 pEntryName = GTK_ENTRY(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesEntryName"));
181 if (pEntryName == NULL)
182 FatalError(__FILE__, __LINE__, __DATE__);
184 pEntryDir = GTK_ENTRY(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesEntryDir"));
185 if (pEntryDir == NULL)
186 FatalError(__FILE__, __LINE__, __DATE__);
188 pEntryAuthor = GTK_ENTRY(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesEntryAuthor"));
189 if (pEntryAuthor == NULL)
190 FatalError(__FILE__, __LINE__, __DATE__);
192 pTextDescription = GTK_TEXT(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesTextDescription"));
193 if (pTextDescription == NULL)
194 FatalError(__FILE__, __LINE__, __DATE__);
196 if (!bIsNew)
198 gtk_entry_set_editable(pEntryName, FALSE);
199 gtk_widget_set_sensitive(GTK_WIDGET(pEntryName), FALSE);
201 gtk_entry_set_editable(pEntryDir, FALSE);
202 gtk_widget_set_sensitive(GTK_WIDGET(pEntryDir), FALSE);
204 bUpdateDir = TRUE;
207 gtk_entry_set_text(pEntryName, Project.szName);
208 bUpdateBlock = TRUE, gtk_entry_set_text(pEntryDir, Project.szDir), bUpdateBlock = FALSE;
209 gtk_entry_set_text(pEntryAuthor, Project.szAuthor);
210 gtk_editable_delete_text(GTK_EDITABLE(pTextDescription), 0, -1), x = 0,
211 gtk_editable_insert_text(GTK_EDITABLE(pTextDescription), Project.szDesc, strlen(Project.szDesc), &x);
213 while (!bCanceled && !bCompleted)
214 g_main_iteration(FALSE);
216 if (bCompleted)
218 strcpy(Project.szName, FileGetName(gtk_entry_get_text(pEntryName)));
219 strcpy(Project.szExt,
220 strlen(FileGetExt(gtk_entry_get_text(pEntryName))) > 0
221 ? FileGetExt(gtk_entry_get_text(pEntryName))
222 : pDefaultProjectExt
224 strcpy(Project.szDir, gtk_entry_get_text(pEntryDir));
225 if (strcmp(FileGetName(gtk_entry_get_text(pEntryDir)), Project.szName))
227 strcat(Project.szDir, G_DIR_SEPARATOR_S);
228 strcat(Project.szDir, Project.szName);
230 strcpy(Project.szAuthor, gtk_entry_get_text(pEntryAuthor));
231 strcpy(Project.szDesc, gtk_editable_get_chars(GTK_EDITABLE(pTextDescription), 0, -1));
233 ProjectSave();
236 ProjectPropertiesDestroy();
238 if (bCompleted && !ProjectPropertiesValid())
239 bCompleted = FALSE;
242 return bCompleted
243 ? SUCCESS
244 : FAILURE;
248 static void ProjectPropertiesCreate(void)
250 pWindow = GTK_WINDOW(create_ProjectProperties());
251 if (pWindow == NULL)
252 FatalError(__FILE__, __LINE__, __DATE__);
254 gtk_window_set_transient_for(GTK_WINDOW(pWindow), GTK_WINDOW(pWindowMain));
255 gtk_window_set_policy(GTK_WINDOW(pWindow), FALSE, FALSE, FALSE);
256 gtk_widget_show(GTK_WIDGET(pWindow));
258 while (g_main_iteration(FALSE)) ;
262 static void ProjectPropertiesDestroy(void)
264 gtk_widget_destroy(GTK_WIDGET(pWindow));
268 static BOOL ProjectPropertiesValid(void)
270 /* TODO: validation of project parameters */
271 return TRUE;
275 void ProjectProperties_ButtonClicked(GtkButton *pButtonClicked, gpointer pUserData)
277 GtkButton *pOk = NULL, *pCancel = NULL;
279 pOk = GTK_BUTTON(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesButtonOk"));
280 if (pOk == NULL)
281 FatalError(__FILE__, __LINE__, __DATE__);
283 pCancel = GTK_BUTTON(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesButtonCancel"));
284 if (pCancel == NULL)
285 FatalError(__FILE__, __LINE__, __DATE__);
287 if (pButtonClicked == pOk)
288 bCompleted = TRUE;
290 else if (pButtonClicked == pCancel)
291 bCanceled = TRUE;
295 void ProjectProperties_NameChanged(GtkEditable *pEditable, GdkEventKey *pEvent, gpointer pUserData)
297 GtkEntry *pEntryName = NULL, *pEntryDir = NULL;
299 pEntryName = GTK_ENTRY(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesEntryName"));
300 if (pEntryName == NULL)
301 FatalError(__FILE__, __LINE__, __DATE__);
303 pEntryDir = GTK_ENTRY(lookup_widget(GTK_WIDGET(pWindow), "pProjectPropertiesEntryDir"));
304 if (pEntryDir == NULL)
305 FatalError(__FILE__, __LINE__, __DATE__);
307 if (!bUpdateDir)
309 strcpy(Project.szDir, pDefaultProjectDir);
310 strcat(Project.szDir, "/");
311 strcat(Project.szDir, gtk_entry_get_text(pEntryName));
313 bUpdateBlock = TRUE;
314 gtk_entry_set_text(pEntryDir, Project.szDir);
315 bUpdateBlock = FALSE;
320 void ProjectProperties_DirChanged(GtkEditable *pEditable, gint pStartPos, gint pEndPos, gpointer pUserData)
322 if (bUpdateBlock)
323 return;
325 bUpdateDir = TRUE;
330 /*******************************************************************************
332 MENU : Project -> Close
334 *******************************************************************************/
336 /* callback from menu */
337 void ProjectClose_MenuActivation(GtkMenuItem *pMenuItem, gpointer pUserData)
339 int iResult;
340 char szFileName[TEXTLEN], szValue[TEXTLEN];
342 /* unload files */
343 iResult = SUCCESS;
344 strcpy(szFileName, "");
345 while (iResult == SUCCESS)
347 iResult = DocGetProperty(DOC_NEXT, szFileName, (void *) szValue);
348 if (iResult != SUCCESS)
349 break;
350 DocDestroy(szValue);
353 /* unload project */
354 strcpy(Project.szName, "");
355 ProjectWidgetsHide();
356 ProjectTitle();
361 /*******************************************************************************
363 MENU : Project -> Exit
365 *******************************************************************************/
367 /* callback from menu */
368 void ProjectExit_MenuActivation(GtkMenuItem *pMenuItem, gpointer pUserData)
370 ProjectClose_MenuActivation(pMenuItem, pUserData);
371 /* no gtk_main_loop(), so not gtk_main_quit(); */
372 bRunning = FALSE;