diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/extstr.c | 32 | ||||
| -rw-r--r-- | src/common/extstr.h | 3 | ||||
| -rw-r--r-- | src/configuration.c | 80 | ||||
| -rw-r--r-- | src/configuration.h | 8 | ||||
| -rw-r--r-- | src/gtkext/gtkdockstation.c | 44 | ||||
| -rw-r--r-- | src/params.h | 6 | 
6 files changed, 147 insertions, 26 deletions
| diff --git a/src/common/extstr.c b/src/common/extstr.c index 4dec066..17cffec 100644 --- a/src/common/extstr.c +++ b/src/common/extstr.c @@ -272,3 +272,35 @@ char *escape_crlf(char *input)      return input;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : input = chaîne de caractères à traiter.                      * +*                max   = taille maximale de chaîne acceptable.                * +*                                                                             * +*  Description : Borne la taille d'une chaîne à une valeur donnée.            * +*                                                                             * +*  Retour      : Adresse de la chaîne de caractères ou input si pas besoin.   * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +char *ellipsis(char *input, size_t max) +{ +    char *result;                           /* Chaîne à retourner          */ + +    if (strlen(input) > max) +    { +        result = strndup(input, max); +        result = stradd(result, "..."); + +        free(input); + +    } +    else result = input; + +    return result; + +} diff --git a/src/common/extstr.h b/src/common/extstr.h index fa1b21b..592719e 100644 --- a/src/common/extstr.h +++ b/src/common/extstr.h @@ -47,6 +47,9 @@ char **strtoka(const char *, const char *, size_t *);  /* S'assure qu'une chaîne de caractères tient sur une ligne. */  char *escape_crlf(char *); +/* Borne la taille d'une chaîne à une valeur donnée. */ +char *ellipsis(char *, size_t); +  #endif  /* _COMMON_EXTSTR_H */ diff --git a/src/configuration.c b/src/configuration.c index 8448c03..1369159 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -110,6 +110,15 @@ configuration *load_configuration(const char *name, config_param *params, unsign                      }                      break; +                case CVT_INTEGER: +                    strval = get_node_text_value(result->context, params[i].path); +                    if (strval != NULL) +                    { +                        set_integer_config_value(result, i, atoi(strval)); +                        free(strval); +                    } +                    break; +                  case CVT_STRING:                      strval = get_node_text_value(result->context, params[i].path);                      set_string_config_value(result, i, strval); @@ -181,6 +190,7 @@ void unload_configuration(configuration *config)      int ret;                                /* Bilan de l'assurance        */      unsigned int i;                         /* Boucle de parcours          */      config_param *params;                   /* Confort d'utilisation       */ +    char tmp[12 /* -INT_MIN */];            /* Reconstruction en chaîne    */      close_xml_file(config->xdoc, config->context); @@ -205,6 +215,16 @@ void unload_configuration(configuration *config)                  break; +            case CVT_INTEGER: +                if (params->cur.integer == params->def.integer) +                    continue; + +                snprintf(tmp, 12, "%d", params->cur.integer); +                add_content_to_node(config->xdoc, config->context, +                                    params->path, tmp); + +                break; +              case CVT_STRING:                  if (params->cur.string == NULL && params->def.string == NULL) @@ -281,8 +301,8 @@ bool get_boolean_config_value(configuration *config, unsigned int index)  {      bool result;                            /* Valeur à retourner          */ -    if (index >= config->count) return NULL; -    if (config->params[index].type != CVT_BOOLEAN) return NULL; +    if (index >= config->count) return false; +    if (config->params[index].type != CVT_BOOLEAN) return false;      if (config->params[index].defined) result = config->params[index].cur.boolean;      else result = config->params[index].def.boolean; @@ -298,6 +318,62 @@ bool get_boolean_config_value(configuration *config, unsigned int index)  *                index  = indice de l'élément à traiter.                      *  *                value  = valeur à considérer comme valeur courante.          *  *                                                                             * +*  Description : Définit une valeur entière dans la configuration.            * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool set_integer_config_value(configuration *config, unsigned int index, int value) +{ +    if (index >= config->count) return false; +    if (config->params[index].type != CVT_INTEGER) return false; + +    config->params[index].defined = true; + +    config->params[index].cur.integer = value; + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : config = configuration à venir consulter.                    * +*                index  = indice de l'élément à traiter.                      * +*                                                                             * +*  Description : Fournit une valeur entière issue de la configuration.        * +*                                                                             * +*  Retour      : Valeur courante ou par défaut de la configuration.           * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int get_integer_config_value(configuration *config, unsigned int index) +{ +    int result;                             /* Valeur à retourner          */ + +    if (index >= config->count) return 0; +    if (config->params[index].type != CVT_INTEGER) return 0; + +    if (config->params[index].defined) result = config->params[index].cur.integer; +    else result = config->params[index].def.integer; + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : config = configuration à venir consulter.                    * +*                index  = indice de l'élément à traiter.                      * +*                value  = valeur à considérer comme valeur courante.          * +*                                                                             *  *  Description : Définit une chaîne de caractères dans la configuration.      *  *                                                                             *  *  Retour      : -                                                            * diff --git a/src/configuration.h b/src/configuration.h index 4600a7a..2da9d53 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -32,6 +32,7 @@  typedef enum _ConfigValueType  {      CVT_BOOLEAN,                            /* Valeur booléenne            */ +    CVT_INTEGER,                            /* Valeur entière              */      CVT_STRING,                             /* Chaîne de caractère         */      CVT_COUNT @@ -42,6 +43,7 @@ typedef enum _ConfigValueType  typedef union _config_value  {      bool boolean;                           /* Valeur booléenne            */ +    int integer;                            /* Valeur entière              */      char *string;                           /* Chaîne de caractère         */  } config_value; @@ -77,6 +79,12 @@ bool set_boolean_config_value(configuration *, unsigned int, bool);  /* Fournit une valeur booléenne issue de la configuration. */  bool get_boolean_config_value(configuration *, unsigned int); +/* Définit une valeur entière dans la configuration. */ +bool set_integer_config_value(configuration *, unsigned int, int); + +/* Fournit une valeur entière issue de la configuration. */ +int get_integer_config_value(configuration *, unsigned int); +  /* Définit une chaîne de caractères dans la configuration. */  bool set_string_config_value(configuration *, unsigned int, const char *); diff --git a/src/gtkext/gtkdockstation.c b/src/gtkext/gtkdockstation.c index 49f4fa1..69544f7 100644 --- a/src/gtkext/gtkdockstation.c +++ b/src/gtkext/gtkdockstation.c @@ -30,6 +30,8 @@  #include "easygtk.h"  #include "iodamarshal.h" +#include "../params.h" +#include "../common/extstr.h" @@ -206,20 +208,32 @@ static gboolean gtk_dock_station_switch_panel(GtkNotebook *notebook, gpointer *p  void gtk_dock_panel_add_widget(GtkDockStation *station, GtkWidget *widget, const char *caption)  { +    size_t max;                             /* Taille maximale des titres  */ +    char *str;                              /* Titre des prochaines fois   */      GtkWidget *label;                       /* Etiquette d'onglet          */ -    label = qck_create_label(NULL, NULL, caption); +    max = get_integer_config_value(get_main_configuration(), MPT_ELLIPSIS_TAB); + +    str = ellipsis(strdup(caption), max); +    label = qck_create_label(NULL, NULL, str); +    free(str);      g_signal_handlers_disconnect_by_func(station->notebook,                                           G_CALLBACK(gtk_dock_station_switch_panel), station);      gtk_notebook_insert_page(station->notebook, widget, label, -1); +    gtk_widget_set_tooltip_text(label, caption);      g_signal_connect(station->notebook, "switch-page",                       G_CALLBACK(gtk_dock_station_switch_panel), station);      gtk_notebook_set_show_tabs(station->notebook, gtk_notebook_get_n_pages(station->notebook) > 1); +    str = g_object_get_data(G_OBJECT(widget), "title"); +    if (str != NULL) free(str); +    max = get_integer_config_value(get_main_configuration(), MPT_ELLIPSIS_HEADER); +    g_object_set_data(G_OBJECT(widget), "title", ellipsis(strdup(caption), max)); +      gtk_dock_panel_update_title(station, widget, caption);      gtk_notebook_set_current_page(station->notebook, -1); @@ -315,32 +329,16 @@ void gtk_dock_panel_remove_widget(GtkDockStation *station, GtkWidget *widget)  void gtk_dock_panel_update_title(GtkDockStation *station, GtkWidget *widget, const char *caption)  {      char *str;                              /* Valeur finale reconstituée  */ -    gint index;                             /* Indice de l'onglet actif    */ - -    /* Sauvegarde pour une prochaine fois */ - -    str = g_object_get_data(G_OBJECT(widget), "title"); -    if (str != NULL) free(str); - -    g_object_set_data(G_OBJECT(widget), "title", strdup(caption)); - -    /* Mise à jour de l'affichage */ - -    index = gtk_notebook_get_current_page(station->notebook); - -    if (index == gtk_notebook_page_num(station->notebook, widget)) -    { -        str = calloc(strlen("<b>") + strlen(caption) + strlen("</b>") + 1, sizeof(char)); -        strcpy(str, "<b>"); -        strcat(str, caption); -        strcat(str, "</b>"); +    str = calloc(strlen("<b>") + strlen(caption) + strlen("</b>") + 1, sizeof(char)); -        gtk_label_set_markup(station->title, str); +    strcpy(str, "<b>"); +    strcat(str, caption); +    strcat(str, "</b>"); -        free(str); +    gtk_label_set_markup(station->title, str); -    } +    free(str);  } diff --git a/src/params.h b/src/params.h index 49e2fd4..d187a97 100644 --- a/src/params.h +++ b/src/params.h @@ -39,6 +39,8 @@  typedef enum _MainParamType  {      MPT_LAST_PROJECT,                       /* Dernier projet ouvert       */ +    MPT_ELLIPSIS_HEADER,                    /* Titre supérieur des panneaux*/ +    MPT_ELLIPSIS_TAB,                       /* Titre inférieur des panneaux*/      MPT_AUTO_SAVE,                          /* Sauvegarde automatique ?    */ @@ -49,8 +51,10 @@ typedef enum _MainParamType  static config_param main_params[MPT_COUNT] = {      [MPT_LAST_PROJECT]      = { "/OpenIDA/Editor/LastProject", CVT_STRING, false, NULL, NULL }, +    [MPT_ELLIPSIS_HEADER]   = { "/OpenIDA/Editor/Panels/ellipsis_header", CVT_INTEGER, false, { .integer = 54 }, NULL }, +    [MPT_ELLIPSIS_TAB]      = { "/OpenIDA/Editor/Panels/ellipsis_tab", CVT_INTEGER, false, { .integer = 35 }, NULL }, -    [MPT_AUTO_SAVE]         = { "/OpenIDA/Project/Autosave", CVT_BOOLEAN, false, true, NULL }, +    [MPT_AUTO_SAVE]         = { "/OpenIDA/Project/Autosave", CVT_BOOLEAN, false, { .boolean = true }, NULL },  }; | 
