3 /*******************************************************************************/
5 /* gEDA Suite Project Manager */
7 /* Copyright (C) 2002 Piotr Miarecki, sp9rve@eter.ariadna.pl */
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. */
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. */
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. */
22 /*******************************************************************************/
28 #define GTK_ENABLE_BROKEN
41 #include "filechoose.h"
44 #include "interface.h"
46 #include "m_project.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 /*******************************************************************************
74 *******************************************************************************/
76 /* callback from menu */
77 void ProjectNew_MenuActivation(GtkMenuItem
*pMenuItem
, gpointer pUserData
)
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
)
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
, "");
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
;
157 bUpdateBlock
= FALSE
;
159 /* default values for new project */
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 */
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__
);
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
);
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
);
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
))
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));
236 ProjectPropertiesDestroy();
238 if (bCompleted
&& !ProjectPropertiesValid())
248 static void ProjectPropertiesCreate(void)
250 pWindow
= GTK_WINDOW(create_ProjectProperties());
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 */
275 void ProjectProperties_ButtonClicked(GtkButton
*pButtonClicked
, gpointer pUserData
)
277 GtkButton
*pOk
= NULL
, *pCancel
= NULL
;
279 pOk
= GTK_BUTTON(lookup_widget(GTK_WIDGET(pWindow
), "pProjectPropertiesButtonOk"));
281 FatalError(__FILE__
, __LINE__
, __DATE__
);
283 pCancel
= GTK_BUTTON(lookup_widget(GTK_WIDGET(pWindow
), "pProjectPropertiesButtonCancel"));
285 FatalError(__FILE__
, __LINE__
, __DATE__
);
287 if (pButtonClicked
== pOk
)
290 else if (pButtonClicked
== pCancel
)
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__
);
309 strcpy(Project
.szDir
, pDefaultProjectDir
);
310 strcat(Project
.szDir
, "/");
311 strcat(Project
.szDir
, gtk_entry_get_text(pEntryName
));
314 gtk_entry_set_text(pEntryDir
, Project
.szDir
);
315 bUpdateBlock
= FALSE
;
320 void ProjectProperties_DirChanged(GtkEditable
*pEditable
, gint pStartPos
, gint pEndPos
, gpointer pUserData
)
330 /*******************************************************************************
332 MENU : Project -> Close
334 *******************************************************************************/
336 /* callback from menu */
337 void ProjectClose_MenuActivation(GtkMenuItem
*pMenuItem
, gpointer pUserData
)
340 char szFileName
[TEXTLEN
], szValue
[TEXTLEN
];
344 strcpy(szFileName
, "");
345 while (iResult
== SUCCESS
)
347 iResult
= DocGetProperty(DOC_NEXT
, szFileName
, (void *) szValue
);
348 if (iResult
!= SUCCESS
)
354 strcpy(Project
.szName
, "");
355 ProjectWidgetsHide();
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(); */