diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2009-07-12 15:26:23 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2009-07-12 15:26:23 (GMT) | 
| commit | c9465acd65e197e48da8648eb8d1ef602d6772ed (patch) | |
| tree | fbb5ceaaa683bd1beb0b66d5e5d212b927a9f6b0 /src/editor.c | |
| parent | 5f2cd35c377989e07b241870f89fdf87d851465d (diff) | |
Read and saved projects from and into XML files.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@91 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/editor.c')
| -rw-r--r-- | src/editor.c | 210 | 
1 files changed, 64 insertions, 146 deletions
| diff --git a/src/editor.c b/src/editor.c index ad0373b..2738621 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1,6 +1,6 @@ -/* OpenIDA - Outils de configurations pour le WM Firebox - * editor.c - fichier principal de l'éditeur de configuration +/* OpenIDA - Outil d'analyse de fichiers binaires + * editor.c - fenêtre principale de l'interface graphique   *   * Copyright (C) 2006-2007 Cyrille Bagard   * @@ -22,12 +22,11 @@   */ -#include <locale.h>/* Fonction main() */ -#include <config.h> /* idem */ -#include <stdlib.h> /* ... */ +#include "editor.h" + + -#include <gtk/gtk.h>  /** exemple GTK **/ @@ -47,9 +46,6 @@  #include "gtkext/easygtk.h"  #include "gtkext/gtkbinview.h"  #include "gtkext/gtkdockpanel.h" -#include "format/exe_format.h" -#include "format/mangling/demangler.h" -#include "plugins/pglist.h"  #include "debug/debuggers.h"  #include "panel/panels.h" @@ -74,6 +70,8 @@ GtkWidget *create_editor(void);  void destroy_editor(GtkWidget *, gpointer); +/* Réagit au menu "Fichier -> Ouvrir un projet". */ +void mcb_file_open_project(GtkMenuItem *, gpointer);  /* Réagit au menu "Fichier -> Enregistrer le projet". */  void mcb_file_save_project(GtkMenuItem *, gpointer); @@ -135,72 +133,6 @@ void update_debug_menu_items(GObject *, gboolean); -void open_last_file(GObject *ref); - - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : argc = nombre d'arguments dans la ligne de commande.         * -*                argv = arguments de la ligne de commande.                    * -*                                                                             * -*  Description : Point d'entrée du programme.                                 * -*                                                                             * -*  Retour      : EXIT_SUCCESS si le prgm s'est déroulé sans encombres.        * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -int main(int argc, char **argv) -{ -    GtkWidget *editor;                      /* Fenêtre graphique           */ - -    setlocale(LC_ALL, ""); -    /* -    bindtextdomain(PACKAGE, LOCALE_DIR); -    textdomain(PACKAGE); -    */ - -    /* init threads */ -    g_thread_init(NULL); -    gdk_threads_init(); - -    /* Initialisation de GTK */ -    gtk_set_locale(); -    gtk_init(&argc, &argv); - -    /* -     * this initialize the library and check potential ABI mismatches -     * between the version it was compiled for and the actual shared -     * library used. -     */ -    /*LIBXML_TEST_VERSION*/ - -    add_pixmap_directory(PACKAGE_DATA_DIR); -    add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); - -    /* Initialisation du programme */ -    init_all_processors(); -    init_all_demanglers(); -    init_all_exe_formats(); - -    /* Création de l'interface */ -    editor = create_editor(); -    gtk_widget_show(editor); - -    init_all_plugins(G_OBJECT(editor)); - -    open_last_file(G_OBJECT(editor)); - -    gdk_threads_enter(); -    gtk_main(); -    gdk_threads_leave(); - -    return EXIT_SUCCESS; - -} - @@ -301,6 +233,12 @@ GtkWidget *create_editor(void)      menubar = gtk_menu_new();      gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menubar); +    submenuitem = qck_create_menu_item(NULL, NULL, _("Open project"), G_CALLBACK(mcb_file_open_project), result); +    gtk_container_add(GTK_CONTAINER(menubar), submenuitem); + +    submenuitem = qck_create_menu_separator(); +    gtk_container_add(GTK_CONTAINER(menubar), submenuitem); +      submenuitem = qck_create_menu_item(NULL, NULL, _("Save project"), G_CALLBACK(mcb_file_save_project), result);      gtk_container_add(GTK_CONTAINER(menubar), submenuitem); @@ -422,7 +360,7 @@ GtkWidget *create_editor(void)      load_recent_openida_projects_list(G_OBJECT(result), G_CALLBACK(mcb_open_recent_project)); -    project = /*load_openida_project_from_xml("/tmp/test.oip")*/create_empty_openida_project(); +    project = create_empty_openida_project();      set_current_openida_project(project);      reload_menu_project(G_OBJECT(result)); @@ -615,6 +553,53 @@ void destroy_editor(GtkWidget *widget, gpointer data) + +/****************************************************************************** +*                                                                             * +*  Paramètres  : menuitem = élément de menu sélectionné.                      * +*                data     = adresse de l'espace de référencement global.      * +*                                                                             * +*  Description : Réagit au menu "Fichier -> Ouvrir un projet".                * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void mcb_file_open_project(GtkMenuItem *menuitem, gpointer data) +{ +    GtkWidget *dialog;                      /* Boîte à afficher            */ +    gchar *filename;                        /* Nom du fichier à intégrer   */ +    openida_project *project;               /* Projet chargé               */ + +    dialog = gtk_file_chooser_dialog_new (_("Open a project"), GTK_WINDOW(data), +                                          GTK_FILE_CHOOSER_ACTION_OPEN, +                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, +                                          GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, +                                          NULL); + +    if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) +    { +        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + +        project = g_openida_project_new_from_xml(filename); + +        if (project != NULL) +        { +            set_current_openida_project(project); +            display_openida_project(project, G_OBJECT(data)); +        } + +        g_free(filename); + +    } + +    gtk_widget_destroy(dialog); + +} + +  /******************************************************************************  *                                                                             *  *  Paramètres  : menuitem = élément de menu sélectionné.                      * @@ -635,7 +620,7 @@ void mcb_file_save_project(GtkMenuItem *menuitem, gpointer data)      project = get_current_openida_project();      if (has_storing_filename(project)) -        write_openida_project_to_xml(project, NULL); +        g_openida_project_save(project, NULL);      else          mcb_file_save_project_as(menuitem, data); @@ -671,7 +656,7 @@ void mcb_file_save_project_as(GtkMenuItem *menuitem, gpointer data)      {          filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); -        write_openida_project_to_xml(get_current_openida_project(), filename); +        g_openida_project_save(get_current_openida_project(), filename);          g_free(filename); @@ -704,7 +689,7 @@ void mcb_open_recent_project(GtkMenuItem *menuitem, gpointer data)      caption = gtk_label_get_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem)))); -    project = load_openida_project_from_xml(caption); +    project = NULL/*load_openida_project_from_xml(caption)*/;      if (project != NULL)      { @@ -1198,70 +1183,3 @@ void update_debug_menu_items(GObject *ref, gboolean stopped)      gtk_widget_set_sensitive(submenuitem, stopped);  } - - - - - - - - - -void open_last_file(GObject *ref) -{ - - -    GtkWidget *scrolledwindow; - - -    GtkWidget *snippet; - - - -    GtkDockPanel *dpanel;                   /* Support de panneaux         */ -    GtkDockItem *ditem;                     /* Panneau avec ses infos.     */ - -    openida_binary *binary; - - -    openida_project *project; - -    GtkWidget *view;                        /* Affichage du code binaire   */ -    GtkBinView *binview;                    /* Afficheur effectif de code  */ - - - -    binary = load_binary_file("/tmp/hello"); - -    if (binary == NULL) -    { -        /* TODO : log ... */ -        return; -    } - - -    project = get_current_openida_project(); - -    attach_binary_to_openida_project(project, binary); - -    view = get_view_for_openida_project_binary(project, binary, BVW_BLOCK, &binview); - -    g_object_set_data(ref, "binview", binview); - - - -    dpanel = GTK_DOCK_PANEL(g_object_get_data(ref, "binpanel")); - -    ditem = gtk_dock_item_new(openida_binary_to_string(binary), view); -    gtk_dock_panel_add_item(dpanel, ditem); - - - - -    g_object_set_data(ref, "current_binary", binary); - - -    reload_symbols_panel_content(get_panel(PNT_SYMBOLS), get_openida_binary_format(binary)); - - -} | 
