r5922 - trunk/eda/fped
werner at docs.openmoko.org
werner at docs.openmoko.org
Tue Apr 20 03:11:45 CEST 2010
Author: werner
Date: 2010-04-20 03:11:45 +0200 (Tue, 20 Apr 2010)
New Revision: 5922
Added:
trunk/eda/fped/fped.h
Modified:
trunk/eda/fped/dump.c
trunk/eda/fped/dump.h
trunk/eda/fped/file.c
trunk/eda/fped/fped.c
trunk/eda/fped/gui.c
trunk/eda/fped/gui.h
Log:
Added a "Save as" dialog and made fped disable "Save" if working on a manually
created file. This is a precaution against accidently saving to a manual work,
which would change the structure and remove all comments.
- fped.h, fped.c, file.c: moved declaration of save_file_name into shared
header
- dump.h, dump.c (MACHINE_GENERATED): moved header marking machine-generated
files into shared macro
- gui.c (save_as_fpd): added "Save as" dialog
- fped.h, fped.c (load_file), gui.c: disable "Save" if editing a file that
doesn't have the machine-generated header
Modified: trunk/eda/fped/dump.c
===================================================================
--- trunk/eda/fped/dump.c 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/dump.c 2010-04-20 01:11:45 UTC (rev 5922)
@@ -536,7 +536,7 @@
{
struct frame *frame;
- fprintf(file, "/* MACHINE-GENERATED ! */\n\n");
+ fprintf(file, "%s\n", MACHINE_GENERATED);
for (frame = frames; frame; frame = frame->next)
frame->dumped = 0;
for (frame = frames; frame; frame = frame->next) {
Modified: trunk/eda/fped/dump.h
===================================================================
--- trunk/eda/fped/dump.h 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/dump.h 2010-04-20 01:11:45 UTC (rev 5922)
@@ -1,8 +1,8 @@
/*
* dump.h - Dump objects in the native FPD format
*
- * Written 2009 by Werner Almesberger
- * Copyright 2009 by Werner Almesberger
+ * Written 2009, 2010 by Werner Almesberger
+ * Copyright 2009, 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +19,9 @@
#include "obj.h"
+#define MACHINE_GENERATED "/* MACHINE-GENERATED ! */\n"
+
+
/*
* vec obj
* --------------------------------------------------------------
Modified: trunk/eda/fped/file.c
===================================================================
--- trunk/eda/fped/file.c 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/file.c 2010-04-20 01:11:45 UTC (rev 5922)
@@ -20,14 +20,11 @@
#include "dump.h"
#include "kicad.h"
#include "postscript.h"
-
#include "util.h"
#include "file.h"
+#include "fped.h"
-extern char *save_file_name;
-
-
/* ----- general helper functions ------------------------------------------ */
Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/fped.c 2010-04-20 01:11:45 UTC (rev 5922)
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <errno.h>
#include "cpp.h"
#include "util.h"
@@ -21,20 +22,37 @@
#include "obj.h"
#include "inst.h"
#include "file.h"
+#include "dump.h"
#include "gui.h"
#include "delete.h"
#include "fpd.h"
+#include "fped.h"
char *save_file_name = NULL;
+int no_save = 0;
static void load_file(const char *name)
{
- if (file_exists(name) == 1) {
+ FILE *file;
+ char line[sizeof(MACHINE_GENERATED)];
+
+ file = fopen(name, "r");
+ if (file) {
+ if (!fgets(line, sizeof(line), file)) {
+ perror(name);
+ exit(1);
+ }
+ no_save = strcmp(line, MACHINE_GENERATED);
+ fclose(file);
reporter = report_parse_error;
run_cpp_on_file(name);
} else {
+ if (errno != ENOENT) {
+ perror(name);
+ exit(1);
+ }
scan_empty();
}
(void) yyparse();
Added: trunk/eda/fped/fped.h
===================================================================
--- trunk/eda/fped/fped.h (rev 0)
+++ trunk/eda/fped/fped.h 2010-04-20 01:11:45 UTC (rev 5922)
@@ -0,0 +1,20 @@
+/*
+ * fped.h - Things fped.c exports
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef FPED_H
+#define FPED_H
+
+extern char *save_file_name;
+extern int no_save;
+
+#endif /* !FPED_H */
Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/gui.c 2010-04-20 01:11:45 UTC (rev 5922)
@@ -23,6 +23,7 @@
#include "gui_tool.h"
#include "gui_frame.h"
#include "gui.h"
+#include "fped.h"
#include "icons/stuff.xpm"
#include "icons/stuff_off.xpm"
@@ -50,6 +51,33 @@
static void do_build_frames(void);
+/* ----- save callbacks ---------------------------------------------------- */
+
+
+static void save_as_fpd(void)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_file_chooser_dialog_new("Save File",
+ NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
+ gtk_file_chooser_set_do_overwrite_confirmation(
+ GTK_FILE_CHOOSER(dialog), TRUE);
+ if (save_file_name)
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
+ save_file_name);
+ if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+ save_file_name =
+ gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ save_fpd();
+ /* @@@ we may leak save_file_name */
+ no_save = 0;
+ }
+ gtk_widget_destroy(dialog);
+}
+
+
/* ----- view callbacks ---------------------------------------------------- */
@@ -68,6 +96,7 @@
static GtkItemFactoryEntry menu_entries[] = {
{ "/File", NULL, NULL, 0, "<Branch>" },
{ "/File/Save", NULL, save_fpd, 0, "<Item>" },
+ { "/File/Save as", NULL, save_as_fpd, 0, "<Item>" },
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
{ "/File/Write KiCad", NULL, write_kicad, 0, "<Item>" },
{ "/File/Write Postscript",
@@ -95,6 +124,9 @@
bar = gtk_item_factory_get_widget(factory, "<FpedMenu>");
gtk_box_pack_start(GTK_BOX(hbox), bar, TRUE, TRUE, 0);
+
+ gtk_widget_set_sensitive(
+ gtk_item_factory_get_item(factory, "/File/Save"), !no_save);
}
Modified: trunk/eda/fped/gui.h
===================================================================
--- trunk/eda/fped/gui.h 2010-04-19 22:57:51 UTC (rev 5921)
+++ trunk/eda/fped/gui.h 2010-04-20 01:11:45 UTC (rev 5922)
@@ -1,8 +1,8 @@
/*
* gui.h - Editor GUI core
*
- * Written 2009 by Werner Almesberger
- * Copyright 2009 by Werner Almesberger
+ * Written 2009, 2010 by Werner Almesberger
+ * Copyright 2009, 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,9 @@
extern int show_meas;
extern int show_bright;
+extern int no_save;
+
/* update everything after a model change */
void change_world(void);
More information about the commitlog
mailing list