1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-16 18:13:43 +02:00

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



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5922 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-04-20 01:11:45 +00:00
parent e24b9de387
commit 8cd9b7b514
7 changed files with 82 additions and 10 deletions

2
dump.c
View File

@ -536,7 +536,7 @@ int dump(FILE *file)
{ {
struct frame *frame; struct frame *frame;
fprintf(file, "/* MACHINE-GENERATED ! */\n\n"); fprintf(file, "%s\n", MACHINE_GENERATED);
for (frame = frames; frame; frame = frame->next) for (frame = frames; frame; frame = frame->next)
frame->dumped = 0; frame->dumped = 0;
for (frame = frames; frame; frame = frame->next) { for (frame = frames; frame; frame = frame->next) {

7
dump.h
View File

@ -1,8 +1,8 @@
/* /*
* dump.h - Dump objects in the native FPD format * dump.h - Dump objects in the native FPD format
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,6 +19,9 @@
#include "obj.h" #include "obj.h"
#define MACHINE_GENERATED "/* MACHINE-GENERATED ! */\n"
/* /*
* vec obj * vec obj
* -------------------------------------------------------------- * --------------------------------------------------------------

5
file.c
View File

@ -20,12 +20,9 @@
#include "dump.h" #include "dump.h"
#include "kicad.h" #include "kicad.h"
#include "postscript.h" #include "postscript.h"
#include "util.h" #include "util.h"
#include "file.h" #include "file.h"
#include "fped.h"
extern char *save_file_name;
/* ----- general helper functions ------------------------------------------ */ /* ----- general helper functions ------------------------------------------ */

20
fped.c
View File

@ -14,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "cpp.h" #include "cpp.h"
#include "util.h" #include "util.h"
@ -21,20 +22,37 @@
#include "obj.h" #include "obj.h"
#include "inst.h" #include "inst.h"
#include "file.h" #include "file.h"
#include "dump.h"
#include "gui.h" #include "gui.h"
#include "delete.h" #include "delete.h"
#include "fpd.h" #include "fpd.h"
#include "fped.h"
char *save_file_name = NULL; char *save_file_name = NULL;
int no_save = 0;
static void load_file(const char *name) 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; reporter = report_parse_error;
run_cpp_on_file(name); run_cpp_on_file(name);
} else { } else {
if (errno != ENOENT) {
perror(name);
exit(1);
}
scan_empty(); scan_empty();
} }
(void) yyparse(); (void) yyparse();

20
fped.h Normal file
View File

@ -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 */

32
gui.c
View File

@ -23,6 +23,7 @@
#include "gui_tool.h" #include "gui_tool.h"
#include "gui_frame.h" #include "gui_frame.h"
#include "gui.h" #include "gui.h"
#include "fped.h"
#include "icons/stuff.xpm" #include "icons/stuff.xpm"
#include "icons/stuff_off.xpm" #include "icons/stuff_off.xpm"
@ -50,6 +51,33 @@ static GtkWidget *bright_image[2];
static void do_build_frames(void); 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 ---------------------------------------------------- */ /* ----- view callbacks ---------------------------------------------------- */
@ -68,6 +96,7 @@ static void swap_var_code(void)
static GtkItemFactoryEntry menu_entries[] = { static GtkItemFactoryEntry menu_entries[] = {
{ "/File", NULL, NULL, 0, "<Branch>" }, { "/File", NULL, NULL, 0, "<Branch>" },
{ "/File/Save", NULL, save_fpd, 0, "<Item>" }, { "/File/Save", NULL, save_fpd, 0, "<Item>" },
{ "/File/Save as", NULL, save_as_fpd, 0, "<Item>" },
{ "/File/sep1", NULL, NULL, 0, "<Separator>" }, { "/File/sep1", NULL, NULL, 0, "<Separator>" },
{ "/File/Write KiCad", NULL, write_kicad, 0, "<Item>" }, { "/File/Write KiCad", NULL, write_kicad, 0, "<Item>" },
{ "/File/Write Postscript", { "/File/Write Postscript",
@ -95,6 +124,9 @@ static void make_menu_bar(GtkWidget *hbox)
bar = gtk_item_factory_get_widget(factory, "<FpedMenu>"); bar = gtk_item_factory_get_widget(factory, "<FpedMenu>");
gtk_box_pack_start(GTK_BOX(hbox), bar, TRUE, TRUE, 0); 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);
} }

6
gui.h
View File

@ -1,8 +1,8 @@
/* /*
* gui.h - Editor GUI core * gui.h - Editor GUI core
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -23,6 +23,8 @@ extern int show_stuff;
extern int show_meas; extern int show_meas;
extern int show_bright; extern int show_bright;
extern int no_save;
/* update everything after a model change */ /* update everything after a model change */
void change_world(void); void change_world(void);