mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-25 16:19:42 +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:
parent
e24b9de387
commit
8cd9b7b514
2
dump.c
2
dump.c
@ -536,7 +536,7 @@ int dump(FILE *file)
|
||||
{
|
||||
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) {
|
||||
|
7
dump.h
7
dump.h
@ -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
|
||||
* --------------------------------------------------------------
|
||||
|
5
file.c
5
file.c
@ -20,12 +20,9 @@
|
||||
#include "dump.h"
|
||||
#include "kicad.h"
|
||||
#include "postscript.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "file.h"
|
||||
|
||||
|
||||
extern char *save_file_name;
|
||||
#include "fped.h"
|
||||
|
||||
|
||||
/* ----- general helper functions ------------------------------------------ */
|
||||
|
20
fped.c
20
fped.c
@ -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();
|
||||
|
20
fped.h
Normal file
20
fped.h
Normal 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
32
gui.c
@ -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 GtkWidget *bright_image[2];
|
||||
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 void swap_var_code(void)
|
||||
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 @@ static void make_menu_bar(GtkWidget *hbox)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
6
gui.h
6
gui.h
@ -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,6 +23,8 @@ extern int show_stuff;
|
||||
extern int show_meas;
|
||||
extern int show_bright;
|
||||
|
||||
extern int no_save;
|
||||
|
||||
|
||||
/* update everything after a model change */
|
||||
void change_world(void);
|
||||
|
Loading…
Reference in New Issue
Block a user