~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to plugins/htmlchars.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
21
 *      MA 02110-1301, USA.
22
22
 *
23
 
 * $Id: htmlchars.c 4630 2010-01-31 21:54:47Z eht16 $
 
23
 * $Id: htmlchars.c 4861 2010-04-25 17:43:09Z eht16 $
24
24
 */
25
25
 
26
26
/* HTML Characters plugin (Inserts HTML character entities like '&') */
68
68
static GtkWidget *menu_htmltoggle = NULL;
69
69
static gboolean plugin_active = FALSE;
70
70
 
 
71
/* Configuration file */
 
72
static gchar *config_file = NULL;
 
73
 
71
74
const gchar *chars[][2] ={
72
75
        { N_("HTML characters"), NULL },
73
76
        { "\"", """ },
342
345
 
343
346
 
344
347
/* Functions to toggle the status of plugin */
345
 
void set_status(gboolean new_status)
 
348
static void set_status(gboolean new_status)
346
349
{
347
 
        /* No more function at the moment.*/
348
350
        if (plugin_active != new_status)
 
351
        {
 
352
                GKeyFile *config = g_key_file_new();
 
353
                gchar *data;
 
354
                gchar *config_dir = g_path_get_dirname(config_file);
 
355
 
349
356
                plugin_active = new_status;
350
 
}
 
357
 
 
358
                /* Now we save the new status into configuration file to
 
359
                 * remember next time */
 
360
                g_key_file_set_boolean(config, "general", "replacement_on_typing_active",
 
361
                        plugin_active);
 
362
 
 
363
                if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR)
 
364
                        && utils_mkdir(config_dir, TRUE) != 0)
 
365
                {
 
366
                        dialogs_show_msgbox(GTK_MESSAGE_ERROR,
 
367
                                _("Plugin configuration directory could not be created."));
 
368
                }
 
369
                else
 
370
                {
 
371
                        /* write config to file */
 
372
                        data = g_key_file_to_data(config, NULL, NULL);
 
373
                        utils_write_file(config_file, data);
 
374
                        g_free(data);
 
375
                }
 
376
                g_free(config_dir);
 
377
                g_key_file_free(config);
 
378
        }
 
379
}       
 
380
 
351
381
 
352
382
static void toggle_status(G_GNUC_UNUSED GtkMenuItem * menuitem)
353
383
{
368
398
 
369
399
/* Function takes over value of key which was pressed and returns
370
400
 * HTML/SGML entity if any */
371
 
const gchar *get_entity(gchar *letter)
 
401
static const gchar *get_entity(gchar *letter)
372
402
{
373
403
        guint i, len;
374
404
 
429
459
static void kbhtmltoggle_toggle(G_GNUC_UNUSED guint key_id)
430
460
{
431
461
        if (plugin_active == TRUE)
 
462
        {
432
463
                set_status(FALSE);
 
464
        }
433
465
        else
 
466
        {
434
467
                set_status(TRUE);
 
468
        }
435
469
}
436
470
 
 
471
 
437
472
static void tools_show_dialog_insert_special_chars(void)
438
473
{
439
474
        if (sc_dialog == NULL)
451
486
                gtk_box_set_spacing(GTK_BOX(vbox), 6);
452
487
                gtk_widget_set_name(sc_dialog, "GeanyDialog");
453
488
 
454
 
                height = GEANY_WINDOW_MINIMAL_HEIGHT;
 
489
                height = GEANY_DEFAULT_DIALOG_HEIGHT;
455
490
                gtk_window_set_default_size(GTK_WINDOW(sc_dialog), height * 8 / 10, height);
456
491
                gtk_dialog_set_default_response(GTK_DIALOG(sc_dialog), GTK_RESPONSE_CANCEL);
457
492
 
530
565
        }
531
566
}
532
567
 
 
568
 
533
569
/* just inserts the HTML_NAME coloumn of the selected row at current position
534
570
 * returns only TRUE if a valid selection(i.e. no category) could be found */
535
571
static gboolean sc_insert(GtkTreeModel *model, GtkTreeIter *iter)
599
635
}
600
636
 
601
637
 
602
 
static void replace_special_character()
 
638
static void replace_special_character(void)
603
639
{
604
640
        GeanyDocument *doc = NULL;
605
641
        doc = document_get_current();
650
686
        tools_show_dialog_insert_special_chars();
651
687
}
652
688
 
 
689
 
653
690
static void kb_activate(G_GNUC_UNUSED guint key_id)
654
691
{
655
692
        item_activate(NULL, NULL);
664
701
}
665
702
 
666
703
 
667
 
 
668
704
static void kb_special_chars_replacement(G_GNUC_UNUSED guint key_id)
669
705
{
670
706
        replace_special_character();
671
707
}
672
708
 
673
709
 
674
 
/* Called by Geany to initialize the plugin */
 
710
static void init_configuration(void)
 
711
{
 
712
        GKeyFile *config = g_key_file_new();
 
713
 
 
714
        /* loading configurations from file ...*/
 
715
        config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
 
716
        "plugins", G_DIR_SEPARATOR_S,
 
717
        "htmchars", G_DIR_SEPARATOR_S, "general.conf", NULL);
 
718
 
 
719
        /* ... and initialising options from config file */
 
720
        g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
 
721
 
 
722
        plugin_active = utils_get_setting_boolean(config, "general",
 
723
                "replacement_on_typing_active", FALSE);
 
724
}
 
725
 
 
726
 
 
727
/* Called by Geany to initialise the plugin */
675
728
void plugin_init(GeanyData *data)
676
729
{
677
730
        GtkWidget *menu_item;
678
731
        const gchar *menu_text = _("_Insert Special HTML Characters");
679
732
 
 
733
        /* First we catch the configuration and initialize them */
 
734
        init_configuration();
 
735
 
680
736
        /* Add an item to the Tools menu for html chars dialog*/
681
737
        menu_item = gtk_menu_item_new_with_mnemonic(menu_text);
682
738
        gtk_widget_show(menu_item);
736
792
 
737
793
        if (sc_dialog != NULL)
738
794
                gtk_widget_destroy(sc_dialog);
 
795
 
 
796
        if (config_file != NULL)
 
797
                g_free(config_file);
739
798
}
740
799
 
741
800