diff --git a/sql/create-all.sql b/sql/create-all.sql index aa54161..90c5a44 100644 --- a/sql/create-all.sql +++ b/sql/create-all.sql @@ -17,7 +17,7 @@ use GParts; source sql/mysql/create-basic.sql; ---source sql/mysql/create-crystals.sql; +source sql/mysql/create-crystals.sql; source sql/mysql/create-discretes.sql; source sql/mysql/create-passives.sql; source sql/mysql/create-categories.sql; @@ -28,6 +28,7 @@ source tmp/symbols.sql source tmp/parts-bourns.sql; source tmp/parts-vishay-sprague.sql; +source data/epson-crystals.sql; source data/onsemi-switching-diodes.sql; source data/onsemi-transistors.sql; diff --git a/sql/mysql/create-basic.sql b/sql/mysql/create-basic.sql index cfc9246..78b784c 100644 --- a/sql/mysql/create-basic.sql +++ b/sql/mysql/create-basic.sql @@ -237,6 +237,7 @@ CREATE VIEW CategoryV AS -- CREATE VIEW CompanyV AS SELECT + CompanyID, CompanyName FROM Company ORDER BY CompanyName; @@ -248,6 +249,7 @@ CREATE VIEW CompanyV AS -- CREATE VIEW DeviceV AS SELECT + DeviceID, DeviceName FROM Device ORDER BY DeviceName; @@ -259,6 +261,7 @@ CREATE VIEW DeviceV AS -- CREATE VIEW DocumentV AS SELECT + DocumentID, Category, Title, FileLocation @@ -272,6 +275,7 @@ CREATE VIEW DocumentV AS -- CREATE VIEW FootprintV AS SELECT + FootprintID, FootprintName FROM Footprint ORDER BY FootprintName; @@ -283,6 +287,7 @@ CREATE VIEW FootprintV AS -- CREATE VIEW PackageV AS SELECT + PackageID, PackageName, Technology AS 'Tech' FROM Package diff --git a/src/gparts-controller.c b/src/gparts-controller.c index c743c61..d10de93 100644 --- a/src/gparts-controller.c +++ b/src/gparts-controller.c @@ -27,6 +27,18 @@ static void gparts_controller_set_copy_action_base(GPartsController *controller, GtkAction *action); +static void +gparts_controller_set_delete_action_base(GPartsController *controller, GtkAction *action); + +static void +gparts_controller_set_edit_action_base(GPartsController *controller, GtkAction *action); + +static void +gparts_controller_set_insert_action_base(GPartsController *controller, GtkAction *action); + +static void +gparts_controller_set_paste_action_base(GPartsController *controller, GtkAction *action); + static void @@ -34,7 +46,11 @@ gparts_controller_class_init(gpointer g_class, gpointer g_class_data) { GPartsControllerClass *klasse = GPARTS_CONTROLLER_CLASS(g_class); - klasse->set_copy_action = gparts_controller_set_copy_action_base; + klasse->set_copy_action = gparts_controller_set_copy_action_base; + klasse->set_delete_action = gparts_controller_set_delete_action_base; + klasse->set_edit_action = gparts_controller_set_edit_action_base; + klasse->set_insert_action = gparts_controller_set_insert_action_base; + klasse->set_paste_action = gparts_controller_set_paste_action_base; } gchar* @@ -118,7 +134,6 @@ gparts_controller_set_copy_action(GPartsController *controller, GtkAction *actio } } - static void gparts_controller_set_copy_action_base(GPartsController *controller, GtkAction *action) { @@ -130,7 +145,99 @@ gparts_controller_set_copy_action_base(GPartsController *controller, GtkAction * } void -gparts_controller_set_refresh_action(GPartsController *controller, GtkAction *action) +gparts_controller_set_delete_action(GPartsController *controller, GtkAction *action) { + if (controller != NULL) + { + GPartsControllerClass *klasse = GPARTS_CONTROLLER_GET_CLASS(controller); + + if ((klasse != NULL) && (klasse->set_delete_action != NULL)) + { + klasse->set_delete_action(controller, action); + } + } +} + +static void +gparts_controller_set_delete_action_base(GPartsController *controller, GtkAction *action) +{ + if (action != NULL) + { + gtk_action_set_label(action, "Delete"); + gtk_action_set_sensitive(action, FALSE); + } +} + +void +gparts_controller_set_edit_action(GPartsController *controller, GtkAction *action) +{ + if (controller != NULL) + { + GPartsControllerClass *klasse = GPARTS_CONTROLLER_GET_CLASS(controller); + + if ((klasse != NULL) && (klasse->set_edit_action != NULL)) + { + klasse->set_edit_action(controller, action); + } + } +} + +static void +gparts_controller_set_edit_action_base(GPartsController *controller, GtkAction *action) +{ + if (action != NULL) + { + gtk_action_set_label(action, "Edit"); + gtk_action_set_sensitive(action, FALSE); + } +} + + +void +gparts_controller_set_insert_action(GPartsController *controller, GtkAction *action) +{ + if (controller != NULL) + { + GPartsControllerClass *klasse = GPARTS_CONTROLLER_GET_CLASS(controller); + + if ((klasse != NULL) && (klasse->set_insert_action != NULL)) + { + klasse->set_insert_action(controller, action); + } + } +} + +static void +gparts_controller_set_insert_action_base(GPartsController *controller, GtkAction *action) +{ + if (action != NULL) + { + gtk_action_set_label(action, "Insert"); + gtk_action_set_sensitive(action, FALSE); + } +} + +void +gparts_controller_set_paste_action(GPartsController *controller, GtkAction *action) +{ + if (controller != NULL) + { + GPartsControllerClass *klasse = GPARTS_CONTROLLER_GET_CLASS(controller); + + if ((klasse != NULL) && (klasse->set_paste_action != NULL)) + { + klasse->set_paste_action(controller, action); + } + } +} + +static void +gparts_controller_set_paste_action_base(GPartsController *controller, GtkAction *action) +{ + if (action != NULL) + { + gtk_action_set_label(action, "_Paste"); + gtk_action_set_sensitive(action, FALSE); + } } diff --git a/src/gparts-controller.h b/src/gparts-controller.h index 37832b7..dca970e 100644 --- a/src/gparts-controller.h +++ b/src/gparts-controller.h @@ -20,7 +20,25 @@ /*! \file gparts-controller.h * - * \brief A base class for controllers. + * \brief A base class for view controllers. + * + * Two options for implementation of actions deligated to the view controller + * include: + * + * - making the GtkActions properties of the controller and making the + * controller responsible for maintaining the GtkAction state and handling + * signals emitted from the GtkAction. Setting the GtkAction to NULL revokes + * responsibility. This mechanism does not lend itself to actions that + * have one source or 'owner' and many controllers must handle the event. + * + * - making the action's label and sensitivity properties of the controller. + * The application controller responds to the notify signals and updates the + * GtkAction's state. When the GtkAction emits an activate signal, the + * App Controller calls one of this controller's methods. The application + * controller ignores signals from inactive controllers. + * + * Implementation currently uses the former. As implementation progresses, + * the other mechanism may be more suitable. */ #define GPARTS_TYPE_CONTROLLER (gparts_controller_get_type()) @@ -35,6 +53,7 @@ struct _GPartsController GObject parent; }; +/*! \private */ struct _GPartsControllerClass { GObjectClass parent; @@ -43,8 +62,13 @@ struct _GPartsControllerClass GHashTable* (*get_table)(GPartsController *controller); void (*set_copy_action)(GPartsController *controller, GtkAction *action); + void (*set_delete_action)(GPartsController *controller, GtkAction *action); + void (*set_edit_action)(GPartsController *controller, GtkAction *action); + void (*set_insert_action)(GPartsController *controller, GtkAction *action); + void (*set_paste_action)(GPartsController *controller, GtkAction *action); }; +/*! \private */ GType gparts_controller_get_type(void); @@ -62,7 +86,7 @@ gparts_controller_get_field(GPartsController *controller, const gchar *name); GHashTable* gparts_controller_get_table(GPartsController *controller); -/*! \brief Set the copy-action for this controller +/*! \brief Set the \a copy-action for this controller * * When the application controller sets the view controller's \a copy-action * to a GtkAction, the view controller becomes responsible for handling @@ -87,6 +111,43 @@ gparts_controller_get_table(GPartsController *controller); void gparts_controller_set_copy_action(GPartsController *controller, GtkAction *action); +/*! \brief Set the \a delete-action for this controller + * + * See gparts_controller_set_copy_action() for a detailed description. + * + * \param [in] controller A pointer to the controller + * \param [in] action A pointer to the \a delete-action + */ void -gparts_controller_set_refresh_action(GPartsController *controller, GtkAction *action); +gparts_controller_set_delete_action(GPartsController *controller, GtkAction *action); + +/*! \brief Set the \a edit-action for this controller + * + * See gparts_controller_set_copy_action() for a detailed description. + * + * \param [in] controller A pointer to the controller + * \param [in] action A pointer to the \a edit-action + */ +void +gparts_controller_set_edit_action(GPartsController *controller, GtkAction *action); + +/*! \brief Set the \a insert-action for this controller + * + * See gparts_controller_set_copy_action() for a detailed description. + * + * \param [in] controller A pointer to the controller + * \param [in] action A pointer to the \a insert-action + */ +void +gparts_controller_set_insert_action(GPartsController *controller, GtkAction *action); + +/*! \brief Set the \a paste-action for this controller + * + * See gparts_controller_set_copy_action() for a detailed description. + * + * \param [in] controller A pointer to the controller + * \param [in] action A pointer to the \a paste-action + */ +void +gparts_controller_set_paste_action(GPartsController *controller, GtkAction *action); diff --git a/src/gparts-main.c b/src/gparts-main.c index 27d0581..320eb6e 100644 --- a/src/gparts-main.c +++ b/src/gparts-main.c @@ -41,6 +41,11 @@ struct _GPartsPrivate GtkNotebook *notebook; GtkAction *copy_action; + GtkAction *delete_action; + GtkAction *edit_action; + GtkAction *insert_action; + GtkAction *paste_action; + GtkAction *refresh_action; GPartsController *current_controller; @@ -79,6 +84,18 @@ gparts_set_copy_action(GParts *gparts, GtkAction *action); static void gparts_set_current_controller(GParts *gparts, GPartsController *controller); +static void +gparts_set_delete_action(GParts *gparts, GtkAction *action); + +static void +gparts_set_edit_action(GParts *gparts, GtkAction *action); + +static void +gparts_set_insert_action(GParts *gparts, GtkAction *action); + +static void +gparts_set_paste_action(GParts *gparts, GtkAction *action); + static void gparts_set_refresh_action(GParts *gparts, GtkAction *action); @@ -368,6 +385,26 @@ gparts_instance_init(GTypeInstance* instance, gpointer g_class) GTK_ACTION(gtk_builder_get_object(private->builder, "edit-copy")) ); + gparts_set_delete_action( + GPARTS(instance), + GTK_ACTION(gtk_builder_get_object(private->builder, "edit-delete")) + ); + + gparts_set_edit_action( + GPARTS(instance), + GTK_ACTION(gtk_builder_get_object(private->builder, "edit-edit")) + ); + + gparts_set_insert_action( + GPARTS(instance), + GTK_ACTION(gtk_builder_get_object(private->builder, "edit-insert")) + ); + + gparts_set_paste_action( + GPARTS(instance), + GTK_ACTION(gtk_builder_get_object(private->builder, "edit-paste")) + ); + gparts_set_refresh_action( GPARTS(instance), GTK_ACTION(gtk_builder_get_object(private->builder, "view-refresh")) @@ -393,6 +430,46 @@ gparts_copy_action_cb(GtkAction *action, gpointer user_data) } } +static void +gparts_delete_action_cb(GtkAction *action, gpointer user_data) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(user_data); + + if (privat != NULL) + { + } +} + +static void +gparts_edit_action_cb(GtkAction *action, gpointer user_data) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(user_data); + + if (privat != NULL) + { + } +} + +static void +gparts_insert_action_cb(GtkAction *action, gpointer user_data) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(user_data); + + if (privat != NULL) + { + } +} + +static void +gparts_paste_action_cb(GtkAction *action, gpointer user_data) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(user_data); + + if (privat != NULL) + { + } +} + static void gparts_refresh_action_cb(GtkAction *action, gpointer user_data) { @@ -461,6 +538,194 @@ gparts_set_copy_action(GParts *gparts, GtkAction *action) } } +static void +gparts_set_delete_action(GParts *gparts, GtkAction *action) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(gparts); + + if (privat != NULL) + { + if (privat->delete_action != NULL) + { + g_signal_handlers_disconnect_by_func( + privat->delete_action, + G_CALLBACK(gparts_delete_action_cb), + gparts + ); + + g_object_unref(privat->delete_action); + } + + privat->delete_action = action; + + if (privat->delete_action != NULL) + { + g_object_ref(privat->delete_action); + + g_signal_connect( + privat->delete_action, + "activate", + G_CALLBACK(gparts_delete_action_cb), + gparts + ); + } + + if (privat->current_controller != NULL) + { + gparts_controller_set_delete_action(privat->current_controller, privat->delete_action); + } + else + { + gtk_action_set_label(privat->delete_action, "Delete"); + gtk_action_set_sensitive(privat->delete_action, FALSE); + } + + /* g_object_notify(G_OBJECT(gparts), "delete-action"); */ + } +} + +static void +gparts_set_edit_action(GParts *gparts, GtkAction *action) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(gparts); + + if (privat != NULL) + { + if (privat->edit_action != NULL) + { + g_signal_handlers_disconnect_by_func( + privat->edit_action, + G_CALLBACK(gparts_edit_action_cb), + gparts + ); + + g_object_unref(privat->edit_action); + } + + privat->edit_action = action; + + if (privat->edit_action != NULL) + { + g_object_ref(privat->edit_action); + + g_signal_connect( + privat->edit_action, + "activate", + G_CALLBACK(gparts_edit_action_cb), + gparts + ); + } + + if (privat->current_controller != NULL) + { + gparts_controller_set_edit_action(privat->current_controller, privat->edit_action); + } + else + { + gtk_action_set_label(privat->edit_action, "Edit"); + gtk_action_set_sensitive(privat->edit_action, FALSE); + } + + /* g_object_notify(G_OBJECT(gparts), "edit-action"); */ + } +} + + +static void +gparts_set_insert_action(GParts *gparts, GtkAction *action) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(gparts); + + if (privat != NULL) + { + if (privat->insert_action != NULL) + { + g_signal_handlers_disconnect_by_func( + privat->insert_action, + G_CALLBACK(gparts_insert_action_cb), + gparts + ); + + g_object_unref(privat->insert_action); + } + + privat->insert_action = action; + + if (privat->insert_action != NULL) + { + g_object_ref(privat->insert_action); + + g_signal_connect( + privat->insert_action, + "activate", + G_CALLBACK(gparts_insert_action_cb), + gparts + ); + } + + if (privat->current_controller != NULL) + { + gparts_controller_set_insert_action(privat->current_controller, privat->insert_action); + } + else + { + gtk_action_set_label(privat->insert_action, "Insert"); + gtk_action_set_sensitive(privat->insert_action, FALSE); + } + + /* g_object_notify(G_OBJECT(gparts), "copy-action"); */ + } +} + + +static void +gparts_set_paste_action(GParts *gparts, GtkAction *action) +{ + GPartsPrivate *privat = GPARTS_GET_PRIVATE(gparts); + + if (privat != NULL) + { + if (privat->paste_action != NULL) + { + g_signal_handlers_disconnect_by_func( + privat->paste_action, + G_CALLBACK(gparts_paste_action_cb), + gparts + ); + + g_object_unref(privat->paste_action); + } + + privat->paste_action = action; + + if (privat->paste_action != NULL) + { + g_object_ref(privat->paste_action); + + g_signal_connect( + privat->paste_action, + "activate", + G_CALLBACK(gparts_paste_action_cb), + gparts + ); + } + + if (privat->current_controller != NULL) + { + gparts_controller_set_paste_action(privat->current_controller, privat->paste_action); + } + else + { + gtk_action_set_label(privat->paste_action, "_Paste"); + gtk_action_set_sensitive(privat->paste_action, FALSE); + } + + /* g_object_notify(G_OBJECT(gparts), "paste-action"); */ + } +} + + + static void gparts_set_refresh_action(GParts *gparts, GtkAction *action) { @@ -495,7 +760,7 @@ gparts_set_refresh_action(GParts *gparts, GtkAction *action) if (privat->current_controller != NULL) { - gparts_controller_set_refresh_action(privat->current_controller, privat->refresh_action); + //gparts_controller_set_refresh_action(privat->current_controller, privat->refresh_action); } else { diff --git a/src/gparts-result-controller.h b/src/gparts-result-controller.h index 9d127e7..dce62f9 100644 --- a/src/gparts-result-controller.h +++ b/src/gparts-result-controller.h @@ -54,6 +54,7 @@ struct _GPartsResultControllerClass GPartsControllerClass parent; }; +/*! \private */ GType gparts_result_controller_get_type(void); diff --git a/src/gparts.xml b/src/gparts.xml index ec48bee..7440d9c 100644 --- a/src/gparts.xml +++ b/src/gparts.xml @@ -12,10 +12,24 @@ database-connect - Connect + Connect... gtk-connect + + + database-create + Create... + FALSE + + + + + database-drop + Drop + FALSE + + database-disconnect @@ -23,6 +37,19 @@ gtk-disconnect + + + database-import + Import + + + + + database-import-symbols + Symbols + FALSE + + edit @@ -36,6 +63,34 @@ gtk-copy + + + edit-delete + Delete + gtk-delete + + + + + edit-edit + Edit... + gtk-edit + + + + + edit-insert + Insert + gtk-new + + + + + edit-paste + _Paste + gtk-paste + + view @@ -75,9 +130,21 @@ + + + + + + + + + + + + @@ -89,6 +156,10 @@ + + + +