summaryrefslogtreecommitdiff
path: root/src/gui/core
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-05 00:39:57 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-05 00:39:57 (GMT)
commit1e3fa9b79ebe55698e2aa7d5484baec7e8400a8f (patch)
treec3581ceb7f8586f2f6822de563927a1246dd33a5 /src/gui/core
parent6122bb7f34b178d4c07285adae16afcc55294b1f (diff)
Rewritten the whole API dealing with panels.
Diffstat (limited to 'src/gui/core')
-rw-r--r--src/gui/core/core.c40
-rw-r--r--src/gui/core/items.c50
-rw-r--r--src/gui/core/items.h7
-rw-r--r--src/gui/core/panels.c173
-rw-r--r--src/gui/core/panels.h10
5 files changed, 129 insertions, 151 deletions
diff --git a/src/gui/core/core.c b/src/gui/core/core.c
index 0c1e3f3..ccad3ad 100644
--- a/src/gui/core/core.c
+++ b/src/gui/core/core.c
@@ -30,6 +30,7 @@
#include "theme.h"
#include "../menubar.h"
#include "../menus/view.h"
+#include "../panels/log.h"
#include "../panels/welcome.h"
#include "../../core/params.h"
#include "../../glibext/linesegment.h"
@@ -37,6 +38,11 @@
+/* Charge les panneaux sur la base de la configuration fournie. */
+static bool apply_panel_items_configuration(GPanelItemClass *, GGenConfig *);
+
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -64,7 +70,7 @@ bool load_all_gui_components(void)
* Charge une liste initiale pour activer les raccourcis clavier.
*/
- bar = G_MENU_BAR(find_editor_item_by_key("menubar"));
+ bar = G_MENU_BAR(find_editor_item_by_type(G_TYPE_MENU_BAR));
builder = get_editor_builder();
@@ -83,6 +89,34 @@ bool load_all_gui_components(void)
/******************************************************************************
* *
+* Paramètres : class = classe de panneau enregistré comme existant. *
+* config = configuration à charger. *
+* *
+* Description : Charge les panneaux sur la base de la configuration fournie. *
+* *
+* Retour : true, par conformité avec browse_all_item_panels(). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool apply_panel_items_configuration(GPanelItemClass *class, GGenConfig *config)
+{
+ GPanelItem *panel; /* Panneau à mettre en place */
+
+ if (gtk_panel_item_class_dock_at_startup(class))
+ {
+ panel = g_panel_item_new(G_TYPE_FROM_CLASS(class), "");
+ g_object_unref(G_OBJECT(panel));
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : config = configuration globale à utiliser. *
* *
* Description : Finalise le chargement des éléments graphiques de l'éditeur. *
@@ -111,7 +145,7 @@ bool complete_loading_of_all_gui_components(GGenConfig *config)
grid = get_tiled_grid();
- welcome = get_panel_item_by_name(PANEL_WELCOME_ID);
+ welcome = g_panel_item_new(G_TYPE_WELCOME_PANEL, NULL);
gtk_tiled_grid_set_default_main_panel(grid, welcome);
g_object_unref(G_OBJECT(welcome));
@@ -127,7 +161,7 @@ bool complete_loading_of_all_gui_components(GGenConfig *config)
*/
if (result)
- result = _browse_all_item_panels(true, (handle_panel_item_fc)gtk_panel_item_apply_configuration, config);
+ result = _browse_all_item_panels(true, (handle_panel_item_fc)apply_panel_items_configuration, config);
/**
* Comme la boucle de traitements GTK n'est pas encore lancée, tous les
diff --git a/src/gui/core/items.c b/src/gui/core/items.c
index 9c82100..6c57b7b 100644
--- a/src/gui/core/items.c
+++ b/src/gui/core/items.c
@@ -24,6 +24,7 @@
#include "items.h"
+#include <assert.h>
#include <malloc.h>
#include <string.h>
@@ -33,7 +34,7 @@
-/* Liste des éléments enregistrés */
+/* Liste des éléments en place */
static GEditorItem **_item_list = NULL;
static size_t _item_count = 0;
@@ -52,7 +53,7 @@ static void track_cursor_on_view_panel(GLoadedPanel *, const GLineCursor *, gpoi
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : item = élément de l'interface graphique à intégrer. *
* *
* Description : Procède à l'enregistrement d'un élément reactif de l'éditeur.*
* *
@@ -75,9 +76,9 @@ void register_editor_item(GEditorItem *item)
/******************************************************************************
* *
-* Paramètres : target = désignation de l'élément réactif à retrouver. *
+* Paramètres : target = type de l'élément réactif à retrouver. *
* *
-* Description : Retrouve un élément reactif de l'éditeur par son nom clef. *
+* Description : Retrouve un élément reactif de l'éditeur par son type. *
* *
* Retour : Elément retrouvé ou NULL. *
* *
@@ -85,26 +86,24 @@ void register_editor_item(GEditorItem *item)
* *
******************************************************************************/
-GEditorItem *find_editor_item_by_key(const char *target)
+GEditorItem *find_editor_item_by_type(GType target)
{
GEditorItem *result; /* Elément à retourner */
size_t i; /* Boucle de parcours */
- char *key; /* Nom d'un élément à analyser */
+ GType type; /* Type d'un élément analysé */
result = NULL;
for (i = 0; i < _item_count && result == NULL; i++)
{
- key = g_editor_item_get_key(_item_list[i]);
+ type = G_TYPE_FROM_INSTANCE(_item_list[i]);
- if (strcmp(key, target) == 0)
+ if (type == target)
{
result = _item_list[i];
g_object_ref(G_OBJECT(result));
}
- free(key);
-
}
return result;
@@ -114,6 +113,37 @@ GEditorItem *find_editor_item_by_key(const char *target)
/******************************************************************************
* *
+* Paramètres : item = élément de l'interface graphique à oublier. *
+* *
+* Description : Retire un des éléments reactifs de l'éditeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void unregister_editor_item(GEditorItem *item)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < _item_count; i++)
+ if (_item_list[i] == item)
+ break;
+
+ assert(i < _item_count);
+
+ g_object_unref(G_OBJECT(item));
+
+ memmove(&_item_list[i], &_item_list[i + 1], (_item_count - i - 1) * sizeof(GEditorItem *));
+
+ _item_list = realloc(_item_list, --_item_count * sizeof(GEditorItem *));
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : content = nouvelle instance de contenu analysé. *
* *
* Description : Lance une actualisation du fait d'un changement de contenu. *
diff --git a/src/gui/core/items.h b/src/gui/core/items.h
index 7509b3b..39d6991 100644
--- a/src/gui/core/items.h
+++ b/src/gui/core/items.h
@@ -34,8 +34,11 @@
/* Procède à l'enregistrement d'un élément reactif de l'éditeur. */
void register_editor_item(GEditorItem *);
-/* Retrouve un élément reactif de l'éditeur par son nom clef. */
-GEditorItem *find_editor_item_by_key(const char *);
+/* Retrouve un élément reactif de l'éditeur par son type. */
+GEditorItem *find_editor_item_by_type(GType);
+
+/* Retire un des éléments reactifs de l'éditeur. */
+void unregister_editor_item(GEditorItem *);
/* Lance une actualisation du fait d'un changement de contenu. */
void change_editor_items_current_content(GLoadedContent *);
diff --git a/src/gui/core/panels.c b/src/gui/core/panels.c
index 8505f37..1b6f604 100644
--- a/src/gui/core/panels.c
+++ b/src/gui/core/panels.c
@@ -25,10 +25,10 @@
#include "panels.h"
+#include <assert.h>
#include <malloc.h>
-#include "global.h"
#include "items.h"
#include "../panel-int.h"
#include "../panels/bintree.h"
@@ -42,12 +42,12 @@
#include "../panels/symbols.h"
#include "../panels/welcome.h"
#include "../../core/params.h"
-#include "../../gtkext/gtkdockable.h"
-/* Liste des panneaux en place. */
-static GPanelItem *_panels_list = NULL;
+/* Liste des panneaux disponibles */
+static GType *_panels_list = NULL;
+static size_t _panels_count = 0;
@@ -66,46 +66,32 @@ static GPanelItem *_panels_list = NULL;
void load_main_panels(void)
{
GGenConfig *config; /* Configuration globale */
- GPanelItem *item; /* Panneau de base à charger */
+ GPanelItem *panel; /* Panneau à précharger */
config = get_main_configuration();
- item = g_welcome_panel_new();
- register_panel_item(item, config);
+ register_panel_item(G_TYPE_LOG_PANEL, config);
- item = g_log_panel_new();
- register_panel_item(item, config);
+ /* Chargement du panneau de rapport au plus tôt */
+ panel = g_panel_item_new(G_TYPE_LOG_PANEL, NULL);
+ g_object_unref(G_OBJECT(panel));
- item = g_regedit_panel_new();
- register_panel_item(item, config);
-
- item = g_symbols_panel_new();
- register_panel_item(item, config);
-
- item = g_history_panel_new();
- register_panel_item(item, config);
-
- item = g_strings_panel_new();
- register_panel_item(item, config);
-
- item = g_glance_panel_new();
- register_panel_item(item, config);
-
- item = g_bookmarks_panel_new();
- register_panel_item(item, config);
-
- item = g_bintree_panel_new();
- register_panel_item(item, config);
-
- item = g_error_panel_new();
- register_panel_item(item, config);
+ register_panel_item(G_TYPE_WELCOME_PANEL, config);
+ register_panel_item(G_TYPE_REGEDIT_PANEL, config);
+ register_panel_item(G_TYPE_SYMBOLS_PANEL, config);
+ register_panel_item(G_TYPE_HISTORY_PANEL, config);
+ register_panel_item(G_TYPE_STRINGS_PANEL, config);
+ register_panel_item(G_TYPE_GLANCE_PANEL, config);
+ register_panel_item(G_TYPE_BOOKMARKS_PANEL, config);
+ register_panel_item(G_TYPE_BINTREE_PANEL, config);
+ register_panel_item(G_TYPE_ERROR_PANEL, config);
}
/******************************************************************************
* *
-* Paramètres : item = composant à présenter à l'affichage. *
+* Paramètres : type = type du composant à présenter à l'affichage. *
* config = configuration à compléter. *
* *
* Description : Enregistre un panneau comme partie intégrante de l'éditeur. *
@@ -116,46 +102,27 @@ void load_main_panels(void)
* *
******************************************************************************/
-void register_panel_item(GPanelItem *item, GGenConfig *config)
+void register_panel_item(GType type, GGenConfig *config)
{
- GEditorItem *parent; /* Autre version de l'élément */
+ GPanelItemClass *class; /* Classe associée au type */
+#ifndef NDEBUG
+ bool status; /* Bilan de mise en place */
+#endif
- parent = G_EDITOR_ITEM(item);
+ _panels_list = realloc(_panels_list, ++_panels_count * sizeof(GType));
- /* Enregistre correctement le tout */
- register_editor_item(parent);
- panels_list_add_tail(item, &_panels_list);
+ _panels_list[_panels_count - 1] = type;
- activate_panel_item(item, config);
+ class = g_type_class_ref(type);
-}
+#ifndef NDEBUG
+ status = gtk_panel_item_class_setup_configuration(class, config);
+ assert(status);
+#else
+ gtk_panel_item_class_setup_configuration(class, config);
+#endif
-
-/******************************************************************************
-* *
-* Paramètres : item = composant à présenter à l'affichage. *
-* config = configuration à compléter. *
-* *
-* Description : Intègre un panneau comme partie intégrante de l'éditeur. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void activate_panel_item(GPanelItem *item, GGenConfig *config)
-{
- GtkTiledGrid *grid; /* Composant d'affichage */
-
- grid = get_tiled_grid();
-
- g_signal_connect_swapped(item, "dock-request", G_CALLBACK(gtk_tiled_grid_add), grid);
- g_signal_connect_swapped(item, "undock-request", G_CALLBACK(gtk_tiled_grid_remove), grid);
-
- gtk_dockable_setup_dnd(GTK_DOCKABLE(item));
-
- gtk_panel_item_setup_configuration(item, config);
+ g_type_class_unref(class);
}
@@ -177,79 +144,29 @@ void activate_panel_item(GPanelItem *item, GGenConfig *config)
bool _browse_all_item_panels(bool skip, handle_panel_item_fc handle, void *data)
{
bool result; /* Résultat à renvoyer */
- GPanelItem *welcome; /* Panneau d'accueil */
- GPanelItem *iter; /* Boucle de parcours */
+ GType type; /* Type de panneau à traiter */
+ size_t i; /* Boucle de parcours */
+ GPanelItemClass *class; /* Classe associée au type */
result = true;
- if (skip)
- welcome = get_panel_item_by_name(PANEL_WELCOME_ID);
- else
- welcome = NULL;
-
- panels_list_for_each(iter, _panels_list)
+ for (i = 0; i < _panels_count; i++)
{
- if (skip && iter == welcome)
- continue;
+ type = _panels_list[i];
- result = handle(iter, data);
-
- if (!result) break;
-
- }
-
- g_clear_object(&welcome);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = désignation courte servant de clef. *
-* *
-* Description : Recherche un panneau à partir de son nom court. *
-* *
-* Retour : Panneau trouvé ou NULL si aucun. *
-* *
-* Remarques : Le parcours peut se faire aussi depuis la classe parente, *
-* mais il est plus rapide par ici. *
-* *
-******************************************************************************/
-
-GPanelItem *get_panel_item_by_name(const char *name)
-{
- GPanelItem *result; /* Trouvaille à retourner */
-
- bool look_for_named_panel(GPanelItem *item, GPanelItem **found)
- {
- char *key; /* Clef à utiliser */
- bool status; /* Bilan de la comparaison */
+ if (skip && type == G_TYPE_WELCOME_PANEL)
+ continue;
- key = g_editor_item_get_key(G_EDITOR_ITEM(item));
+ class = g_type_class_ref(type);
- if (strcmp(key, name) == 0)
- {
- *found = item;
- status = false;
- }
- else
- status = true;
+ result = handle(class, data);
- free(key);
+ g_type_class_unref(class);
- return status;
+ if (!result) break;
}
- result = NULL;
-
- browse_all_item_panels((handle_panel_item_fc)look_for_named_panel, &result);
-
- if (result != NULL)
- g_object_ref(G_OBJECT(result));
-
return result;
}
diff --git a/src/gui/core/panels.h b/src/gui/core/panels.h
index 40c2fbd..3846038 100644
--- a/src/gui/core/panels.h
+++ b/src/gui/core/panels.h
@@ -38,13 +38,10 @@
void load_main_panels(void);
/* Enregistre un panneau comme partie intégrante de l'éditeur. */
-void register_panel_item(GPanelItem *, GGenConfig *);
-
-/* Intègre un panneau comme partie intégrante de l'éditeur. */
-void activate_panel_item(GPanelItem *, GGenConfig *);
+void register_panel_item(GType, GGenConfig *);
/* Réalise un traitement sur un panneau de l'éditeur. */
-typedef bool (* handle_panel_item_fc) (GPanelItem *, void *);
+typedef bool (* handle_panel_item_fc) (GPanelItemClass *, void *);
/* Effectue le parcours de tous les panneaux chargés. */
bool _browse_all_item_panels(bool, handle_panel_item_fc, void *);
@@ -52,9 +49,6 @@ bool _browse_all_item_panels(bool, handle_panel_item_fc, void *);
#define browse_all_item_panels(h, d) \
_browse_all_item_panels(false, h, d)
-/* Recherche un panneau à partir de son nom court. */
-GPanelItem *get_panel_item_by_name(const char *);
-
#endif /* _GUI_CORE_PANELS_H */