2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* filetypes.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-05-10 19:54:44 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
2005-11-27 20:46:36 +00:00
|
|
|
* $Id$
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Filetype detection, file extensions and filetype menu items.
|
|
|
|
*/
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2008-03-05 17:09:57 +00:00
|
|
|
#include <glib/gstdio.h>
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#include "geany.h"
|
|
|
|
#include "filetypes.h"
|
|
|
|
#include "highlighting.h"
|
|
|
|
#include "support.h"
|
|
|
|
#include "templates.h"
|
2006-01-23 17:05:29 +00:00
|
|
|
#include "msgwindow.h"
|
2006-10-01 16:14:45 +00:00
|
|
|
#include "utils.h"
|
2006-10-06 23:23:05 +00:00
|
|
|
#include "document.h"
|
|
|
|
#include "sciwrappers.h"
|
2008-04-28 16:52:20 +00:00
|
|
|
#include "ui_utils.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
GPtrArray *filetypes_array = NULL; /* Dynamic array of filetype pointers */
|
|
|
|
|
2008-05-01 12:10:46 +00:00
|
|
|
GHashTable *filetypes_hash = NULL; /* Hash of filetype pointers based on name keys */
|
2008-04-28 14:41:09 +00:00
|
|
|
|
2007-07-19 11:49:53 +00:00
|
|
|
|
2006-08-03 22:17:10 +00:00
|
|
|
static GtkWidget *radio_items[GEANY_MAX_FILE_TYPES];
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2008-04-28 16:52:20 +00:00
|
|
|
static void create_radio_menu_item(GtkWidget *menu, const gchar *label, filetype *ftype);
|
2007-04-25 15:01:14 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2008-05-01 14:51:47 +00:00
|
|
|
static void init_builtin_filetypes(void)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
#define C /* these macros are only to ease navigation */
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->id = GEANY_FILETYPES_C;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->lang = 0;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->name = g_strdup("C");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->title = g_strdup_printf(_("%s source file"), "C");
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->extension = g_strdup("c");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->pattern = utils_strv_new("*.c", "*.h", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_C]->comment_open = g_strdup("/*");
|
|
|
|
filetypes[GEANY_FILETYPES_C]->comment_close = g_strdup("*/");
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define CPP
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->id = GEANY_FILETYPES_CPP;
|
2006-07-14 10:15:12 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->lang = 1;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->name = g_strdup("C++");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->title = g_strdup_printf(_("%s source file"), "C++");
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->extension = g_strdup("cpp");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->pattern = utils_strv_new("*.cpp", "*.cxx", "*.c++", "*.cc",
|
|
|
|
"*.h", "*.hpp", "*.hxx", "*.h++", "*.hh", "*.C", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CPP]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_CPP]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-06-22 17:34:31 +00:00
|
|
|
#define CS
|
|
|
|
filetypes[GEANY_FILETYPES_CS]->id = GEANY_FILETYPES_CS;
|
|
|
|
filetypes[GEANY_FILETYPES_CS]->lang = 25;
|
|
|
|
filetypes[GEANY_FILETYPES_CS]->name = g_strdup("C#");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CS]->title = g_strdup_printf(_("%s source file"), "C#");
|
2007-06-22 17:34:31 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CS]->extension = g_strdup("cs");
|
2007-12-25 14:19:47 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CS]->pattern = utils_strv_new("*.cs", "*.vala", NULL);
|
2007-06-22 17:34:31 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CS]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_CS]->comment_close = NULL;
|
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define D
|
|
|
|
filetypes[GEANY_FILETYPES_D]->id = GEANY_FILETYPES_D;
|
|
|
|
filetypes[GEANY_FILETYPES_D]->lang = 17;
|
|
|
|
filetypes[GEANY_FILETYPES_D]->name = g_strdup("D");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_D]->title = g_strdup_printf(_("%s source file"), "D");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_D]->extension = g_strdup("d");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_D]->pattern = utils_strv_new("*.d", "*.di", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_D]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_D]->comment_close = NULL;
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define JAVA
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->id = GEANY_FILETYPES_JAVA;
|
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->name = g_strdup("Java");
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->lang = 2;
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->title = g_strdup_printf(_("%s source file"), "Java");
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->extension = g_strdup("java");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->pattern = utils_strv_new("*.java", "*.jsp", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->comment_open = g_strdup("/*");
|
|
|
|
filetypes[GEANY_FILETYPES_JAVA]->comment_close = g_strdup("*/");
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
#define PAS /* to avoid warnings when building under Windows, the symbol PASCAL is there defined */
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->id = GEANY_FILETYPES_PASCAL;
|
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->lang = 4;
|
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->name = g_strdup("Pascal");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->title = g_strdup_printf(_("%s source file"), "Pascal");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->extension = g_strdup("pas");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->pattern = utils_strv_new("*.pas", "*.pp", "*.inc", "*.dpr",
|
|
|
|
"*.dpk", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->comment_open = g_strdup("{");
|
|
|
|
filetypes[GEANY_FILETYPES_PASCAL]->comment_close = g_strdup("}");
|
|
|
|
|
|
|
|
#define ASM
|
|
|
|
filetypes[GEANY_FILETYPES_ASM]->id = GEANY_FILETYPES_ASM;
|
|
|
|
filetypes[GEANY_FILETYPES_ASM]->lang = 9;
|
|
|
|
filetypes[GEANY_FILETYPES_ASM]->name = g_strdup("ASM");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ASM]->title = g_strdup_printf(_("%s source file"), "Assembler");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ASM]->extension = g_strdup("asm");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ASM]->pattern = utils_strv_new("*.asm", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ASM]->comment_open = g_strdup(";");
|
|
|
|
filetypes[GEANY_FILETYPES_ASM]->comment_close = NULL;
|
|
|
|
|
2007-06-22 17:34:31 +00:00
|
|
|
#define BASIC
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->id = GEANY_FILETYPES_BASIC;
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->lang = 26;
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->name = g_strdup("FreeBasic");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->title = g_strdup_printf(_("%s source file"), "FreeBasic");
|
2007-06-22 17:34:31 +00:00
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->extension = g_strdup("bas");
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->pattern = utils_strv_new("*.bas", "*.bi", NULL);
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->comment_open = g_strdup("'");
|
|
|
|
filetypes[GEANY_FILETYPES_BASIC]->comment_close = NULL;
|
|
|
|
|
2006-08-15 17:57:41 +00:00
|
|
|
#define FORTRAN
|
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->id = GEANY_FILETYPES_FORTRAN;
|
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->lang = 18;
|
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->name = g_strdup("Fortran");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->title = g_strdup_printf(_("%s source file"), "Fortran (F77)");
|
2006-08-15 17:57:41 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->extension = g_strdup("f");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->pattern = utils_strv_new("*.f", "*.for", "*.ftn", "*.f77",
|
|
|
|
"*.f90", "*.f95", NULL);
|
2006-08-15 17:57:41 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->comment_open = g_strdup("c");
|
|
|
|
filetypes[GEANY_FILETYPES_FORTRAN]->comment_close = NULL;
|
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define CAML
|
|
|
|
filetypes[GEANY_FILETYPES_CAML]->id = GEANY_FILETYPES_CAML;
|
|
|
|
filetypes[GEANY_FILETYPES_CAML]->lang = -2;
|
|
|
|
filetypes[GEANY_FILETYPES_CAML]->name = g_strdup("CAML");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CAML]->title = g_strdup_printf(_("%s source file"), "(O)Caml");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CAML]->extension = g_strdup("ml");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CAML]->pattern = utils_strv_new("*.ml", "*.mli", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CAML]->comment_open = g_strdup("(*");
|
|
|
|
filetypes[GEANY_FILETYPES_CAML]->comment_close = g_strdup("*)");
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define PERL
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->id = GEANY_FILETYPES_PERL;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->lang = 5;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->name = g_strdup("Perl");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->title = g_strdup_printf(_("%s source file"), "Perl");
|
2007-05-05 17:01:59 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->extension = g_strdup("pl");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->pattern = utils_strv_new("*.pl", "*.perl", "*.pm", "*.agi",
|
|
|
|
"*.pod", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PERL]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_PERL]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define PHP
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->id = GEANY_FILETYPES_PHP;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->lang = 6;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->name = g_strdup("PHP");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->title = g_strdup_printf(_("%s source file"), "PHP");
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->extension = g_strdup("php");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->pattern = utils_strv_new("*.php", "*.php3", "*.php4", "*.php5",
|
|
|
|
"*.phtml", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PHP]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_PHP]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-13 20:16:09 +00:00
|
|
|
#define JAVASCRIPT
|
|
|
|
filetypes[GEANY_FILETYPES_JS]->id = GEANY_FILETYPES_JS;
|
|
|
|
filetypes[GEANY_FILETYPES_JS]->lang = 23;
|
|
|
|
filetypes[GEANY_FILETYPES_JS]->name = g_strdup("Javascript");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JS]->title = g_strdup_printf(_("%s source file"), "Javascript");
|
2007-01-13 20:16:09 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JS]->extension = g_strdup("js");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JS]->pattern = utils_strv_new("*.js", NULL);
|
2007-01-13 20:16:09 +00:00
|
|
|
filetypes[GEANY_FILETYPES_JS]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_JS]->comment_close = NULL;
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define PYTHON
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->id = GEANY_FILETYPES_PYTHON;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->lang = 7;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->name = g_strdup("Python");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->title = g_strdup_printf(_("%s source file"), "Python");
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->extension = g_strdup("py");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->pattern = utils_strv_new("*.py", "*.pyw", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_PYTHON]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define RUBY
|
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->id = GEANY_FILETYPES_RUBY;
|
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->lang = 14;
|
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->name = g_strdup("Ruby");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->title = g_strdup_printf(_("%s source file"), "Ruby");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->extension = g_strdup("rb");
|
2007-05-23 14:26:52 +00:00
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->pattern = utils_strv_new("*.rb", "*.rhtml", "*.ruby", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_RUBY]->comment_close = NULL;
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define TCL
|
|
|
|
filetypes[GEANY_FILETYPES_TCL]->id = GEANY_FILETYPES_TCL;
|
|
|
|
filetypes[GEANY_FILETYPES_TCL]->lang = 15;
|
|
|
|
filetypes[GEANY_FILETYPES_TCL]->name = g_strdup("Tcl");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_TCL]->title = g_strdup_printf(_("%s source file"), "Tcl");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_TCL]->extension = g_strdup("tcl");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_TCL]->pattern = utils_strv_new("*.tcl", "*.tk", "*.wish", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_TCL]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_TCL]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-13 20:16:09 +00:00
|
|
|
#define LUA
|
|
|
|
filetypes[GEANY_FILETYPES_LUA]->id = GEANY_FILETYPES_LUA;
|
|
|
|
filetypes[GEANY_FILETYPES_LUA]->lang = 22;
|
|
|
|
filetypes[GEANY_FILETYPES_LUA]->name = g_strdup("Lua");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LUA]->title = g_strdup_printf(_("%s source file"), "Lua");
|
2007-01-13 20:16:09 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LUA]->extension = g_strdup("lua");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LUA]->pattern = utils_strv_new("*.lua", NULL);
|
2007-01-13 20:16:09 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LUA]->comment_open = g_strdup("--");
|
|
|
|
filetypes[GEANY_FILETYPES_LUA]->comment_close = NULL;
|
|
|
|
|
2006-08-27 17:39:34 +00:00
|
|
|
#define FERITE
|
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->id = GEANY_FILETYPES_FERITE;
|
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->lang = 19;
|
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->name = g_strdup("Ferite");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->title = g_strdup_printf(_("%s source file"), "Ferite");
|
2006-08-27 17:39:34 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->extension = g_strdup("fe");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->pattern = utils_strv_new("*.fe", NULL);
|
2006-08-27 17:39:34 +00:00
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->comment_open = g_strdup("/*");
|
|
|
|
filetypes[GEANY_FILETYPES_FERITE]->comment_close = g_strdup("*/");
|
|
|
|
|
2007-05-06 14:05:43 +00:00
|
|
|
#define HASKELL
|
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->id = GEANY_FILETYPES_HASKELL;
|
2007-05-23 12:32:06 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->lang = 24;
|
2007-05-06 14:05:43 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->name = g_strdup("Haskell");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->title = g_strdup_printf(_("%s source file"), "Haskell");
|
2007-05-06 14:05:43 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->extension = g_strdup("hs");
|
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->pattern = utils_strv_new("*.hs", "*.lhs", NULL);
|
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->comment_open = g_strdup("--");
|
|
|
|
filetypes[GEANY_FILETYPES_HASKELL]->comment_close = NULL;
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define SH
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SH]->id = GEANY_FILETYPES_SH;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SH]->lang = 16;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SH]->name = g_strdup("Sh");
|
|
|
|
filetypes[GEANY_FILETYPES_SH]->title = g_strdup(_("Shell script file"));
|
|
|
|
filetypes[GEANY_FILETYPES_SH]->extension = g_strdup("sh");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SH]->pattern = utils_strv_new("*.sh", "configure", "configure.in",
|
2007-05-25 13:08:17 +00:00
|
|
|
"configure.in.in", "configure.ac", "*.ksh", "*.zsh", "*.ash", "*.bash", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SH]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_SH]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define MAKE
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->id = GEANY_FILETYPES_MAKE;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->lang = 3;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->name = g_strdup("Make");
|
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->title = g_strdup(_("Makefile"));
|
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->extension = g_strdup("mak");
|
2007-02-08 16:26:45 +00:00
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->pattern = utils_strv_new(
|
|
|
|
"*.mak", "*.mk", "GNUmakefile", "makefile", "Makefile", "makefile.*", "Makefile.*", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_MAKE]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define XML
|
|
|
|
filetypes[GEANY_FILETYPES_XML]->id = GEANY_FILETYPES_XML;
|
|
|
|
filetypes[GEANY_FILETYPES_XML]->lang = -2;
|
|
|
|
filetypes[GEANY_FILETYPES_XML]->name = g_strdup("XML");
|
2007-07-09 12:46:16 +00:00
|
|
|
filetypes[GEANY_FILETYPES_XML]->title = g_strdup(_("XML document"));
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_XML]->extension = g_strdup("xml");
|
2007-02-08 16:26:45 +00:00
|
|
|
filetypes[GEANY_FILETYPES_XML]->pattern = utils_strv_new(
|
2008-03-18 16:38:01 +00:00
|
|
|
"*.xml", "*.sgml", "*.xsl", "*.xslt", "*.xsd", "*.xhtml", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_XML]->comment_open = g_strdup("<!--");
|
|
|
|
filetypes[GEANY_FILETYPES_XML]->comment_close = g_strdup("-->");
|
|
|
|
|
|
|
|
#define DOCBOOK
|
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->id = GEANY_FILETYPES_DOCBOOK;
|
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->lang = 12;
|
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->name = g_strdup("Docbook");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->title = g_strdup_printf(_("%s source file"), "Docbook");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->extension = g_strdup("docbook");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->pattern = utils_strv_new("*.docbook", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->comment_open = g_strdup("<!--");
|
|
|
|
filetypes[GEANY_FILETYPES_DOCBOOK]->comment_close = g_strdup("-->");
|
|
|
|
|
2006-09-01 17:07:49 +00:00
|
|
|
#define HTML
|
|
|
|
filetypes[GEANY_FILETYPES_HTML]->id = GEANY_FILETYPES_HTML;
|
2008-03-09 18:50:41 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->lang = 29;
|
2006-09-01 17:07:49 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->name = g_strdup("HTML");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->title = g_strdup_printf(_("%s source file"), "HTML");
|
2006-09-01 17:07:49 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->extension = g_strdup("html");
|
2007-02-08 16:26:45 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->pattern = utils_strv_new(
|
|
|
|
"*.htm", "*.html", "*.shtml", "*.hta", "*.htd", "*.htt", "*.cfm", NULL);
|
2006-09-01 17:07:49 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HTML]->comment_open = g_strdup("<!--");
|
|
|
|
filetypes[GEANY_FILETYPES_HTML]->comment_close = g_strdup("-->");
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define CSS
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CSS]->id = GEANY_FILETYPES_CSS;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CSS]->lang = 13;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CSS]->name = g_strdup("CSS");
|
|
|
|
filetypes[GEANY_FILETYPES_CSS]->title = g_strdup(_("Cascading StyleSheet"));
|
|
|
|
filetypes[GEANY_FILETYPES_CSS]->extension = g_strdup("css");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CSS]->pattern = utils_strv_new("*.css", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CSS]->comment_open = g_strdup("/*");
|
|
|
|
filetypes[GEANY_FILETYPES_CSS]->comment_close = g_strdup("*/");
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define SQL
|
2006-02-10 20:53:17 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SQL]->id = GEANY_FILETYPES_SQL;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SQL]->lang = 11;
|
2006-02-10 20:53:17 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SQL]->name = g_strdup("SQL");
|
|
|
|
filetypes[GEANY_FILETYPES_SQL]->title = g_strdup(_("SQL Dump file"));
|
|
|
|
filetypes[GEANY_FILETYPES_SQL]->extension = g_strdup("sql");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SQL]->pattern = utils_strv_new("*.sql", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_SQL]->comment_open = g_strdup("/*");
|
|
|
|
filetypes[GEANY_FILETYPES_SQL]->comment_close = g_strdup("*/");
|
2006-02-10 20:53:17 +00:00
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define LATEX
|
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->id = GEANY_FILETYPES_LATEX;
|
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->lang = 8;
|
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->name = g_strdup("LaTeX");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->title = g_strdup_printf(_("%s source file"), "LaTeX");
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->extension = g_strdup("tex");
|
2007-11-30 18:04:25 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->pattern = utils_strv_new("*.tex", "*.sty", "*.idx", "*.ltx", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->comment_open = g_strdup("%");
|
|
|
|
filetypes[GEANY_FILETYPES_LATEX]->comment_close = NULL;
|
2006-02-10 20:53:17 +00:00
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define OMS
|
2006-02-10 20:53:17 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->id = GEANY_FILETYPES_OMS;
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->lang = -2;
|
2006-02-10 20:53:17 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->name = g_strdup("O-Matrix");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->title = g_strdup_printf(_("%s source file"), "O-Matrix");
|
2006-02-10 20:53:17 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->extension = g_strdup("oms");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->pattern = utils_strv_new("*.oms", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_OMS]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_OMS]->comment_close = NULL;
|
2006-02-10 20:53:17 +00:00
|
|
|
|
2006-11-13 22:11:19 +00:00
|
|
|
#define VHDL
|
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->id = GEANY_FILETYPES_VHDL;
|
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->lang = 21;
|
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->name = g_strdup("VHDL");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->title = g_strdup_printf(_("%s source file"), "VHDL");
|
2006-11-13 22:11:19 +00:00
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->extension = g_strdup("vhd");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->pattern = utils_strv_new("*.vhd", "*.vhdl", NULL);
|
2006-11-13 22:11:19 +00:00
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->comment_open = g_strdup("--");
|
|
|
|
filetypes[GEANY_FILETYPES_VHDL]->comment_close = NULL;
|
|
|
|
|
2006-08-27 17:39:34 +00:00
|
|
|
#define DIFF
|
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->id = GEANY_FILETYPES_DIFF;
|
2006-10-12 23:02:59 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->lang = 20;
|
2006-08-27 17:39:34 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->name = g_strdup("Diff");
|
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->title = g_strdup(_("Diff file"));
|
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->extension = g_strdup("diff");
|
2007-02-08 16:26:45 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->pattern = utils_strv_new("*.diff", "*.patch", "*.rej", NULL);
|
2006-08-27 17:39:34 +00:00
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_DIFF]->comment_close = NULL;
|
|
|
|
|
2006-07-25 10:13:35 +00:00
|
|
|
#define CONF
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->id = GEANY_FILETYPES_CONF;
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->lang = 10;
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->name = g_strdup("Conf");
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->title = g_strdup(_("Config file"));
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->extension = g_strdup("conf");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CONF]->pattern = utils_strv_new("*.conf", "*.ini", "config", "*rc",
|
|
|
|
"*.cfg", NULL);
|
2006-07-25 10:13:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_CONF]->comment_open = g_strdup("#");
|
|
|
|
filetypes[GEANY_FILETYPES_CONF]->comment_close = NULL;
|
2006-07-09 14:41:53 +00:00
|
|
|
|
2007-07-26 09:50:12 +00:00
|
|
|
#define HAXE
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->id = GEANY_FILETYPES_HAXE;
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->lang = 27;
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->name = g_strdup("Haxe");
|
2007-10-31 16:41:01 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->title = g_strdup_printf(_("%s source file"), "Haxe");
|
2007-07-26 09:50:12 +00:00
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->extension = g_strdup("hx");
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->pattern = utils_strv_new("*.hx", NULL);
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->comment_open = g_strdup("//");
|
|
|
|
filetypes[GEANY_FILETYPES_HAXE]->comment_close = NULL;
|
|
|
|
|
2007-08-14 11:50:03 +00:00
|
|
|
#define REST
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->id = GEANY_FILETYPES_REST;
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->lang = 28;
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->name = g_strdup("reStructuredText");
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->title = g_strdup(_("reStructuredText file"));
|
2007-10-31 12:16:48 +00:00
|
|
|
filetypes[GEANY_FILETYPES_REST]->extension = g_strdup("rst");
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->pattern = utils_strv_new(
|
|
|
|
"*.rest", "*.reST", "*.rst", NULL);
|
2007-08-14 11:50:03 +00:00
|
|
|
filetypes[GEANY_FILETYPES_REST]->comment_open = NULL;
|
|
|
|
filetypes[GEANY_FILETYPES_REST]->comment_close = NULL;
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
#define ALL
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->id = GEANY_FILETYPES_ALL;
|
2008-04-11 15:39:44 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->name = g_strdup("None");
|
2006-06-24 14:36:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->lang = -2;
|
2005-11-22 12:26:26 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->title = g_strdup(_("All files"));
|
|
|
|
filetypes[GEANY_FILETYPES_ALL]->extension = g_strdup("*");
|
2007-02-27 14:53:37 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->pattern = utils_strv_new("*", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
filetypes[GEANY_FILETYPES_ALL]->comment_open = NULL;
|
|
|
|
filetypes[GEANY_FILETYPES_ALL]->comment_close = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-01 14:51:47 +00:00
|
|
|
/* initialize fields. */
|
|
|
|
static filetype *filetypes_new(void)
|
2008-04-28 14:41:09 +00:00
|
|
|
{
|
2008-05-01 14:51:47 +00:00
|
|
|
filetype *ft = g_new0(filetype, 1);
|
2008-04-28 14:41:09 +00:00
|
|
|
|
2008-05-01 14:51:47 +00:00
|
|
|
/*
|
|
|
|
ft->id = GEANY_FILETYPES_OTHER;
|
|
|
|
*/
|
|
|
|
ft->lang = -2; /* no tagmanager parser */
|
|
|
|
ft->programs = g_new0(struct build_programs, 1);
|
|
|
|
ft->actions = g_new0(struct build_actions, 1);
|
|
|
|
return ft;
|
2008-04-28 14:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
/* Create the filetypes array and fill it with the known filetypes. */
|
2008-04-28 14:41:09 +00:00
|
|
|
void filetypes_init_types()
|
|
|
|
{
|
|
|
|
filetype_id ft_id;
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
g_return_if_fail(filetypes_array == NULL);
|
2008-04-28 14:41:09 +00:00
|
|
|
g_return_if_fail(filetypes_hash == NULL);
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
filetypes_array = g_ptr_array_sized_new(GEANY_MAX_BUILT_IN_FILETYPES);
|
2008-04-28 14:41:09 +00:00
|
|
|
filetypes_hash = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
|
2008-05-01 14:51:47 +00:00
|
|
|
/* Create built-in filetypes */
|
|
|
|
for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
|
|
|
|
{
|
|
|
|
filetypes[ft_id] = filetypes_new();
|
|
|
|
}
|
|
|
|
init_builtin_filetypes();
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
/* Add built-in filetypes to the hash now the name fields are set */
|
2008-04-28 16:15:08 +00:00
|
|
|
for (ft_id = 0; ft_id < GEANY_MAX_BUILT_IN_FILETYPES; ft_id++)
|
2008-04-28 14:41:09 +00:00
|
|
|
{
|
|
|
|
filetypes_add(filetypes[ft_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-09 12:46:16 +00:00
|
|
|
#define create_sub_menu(menu, item, title) \
|
|
|
|
(menu) = gtk_menu_new(); \
|
|
|
|
(item) = gtk_menu_item_new_with_mnemonic((title)); \
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM((item)), (menu)); \
|
|
|
|
gtk_container_add(GTK_CONTAINER(filetype_menu), (item)); \
|
|
|
|
gtk_widget_show((item));
|
|
|
|
|
|
|
|
|
2008-04-28 16:52:20 +00:00
|
|
|
static void create_set_filetype_menu()
|
2006-04-27 18:06:35 +00:00
|
|
|
{
|
2007-04-25 15:01:14 +00:00
|
|
|
filetype_id ft_id;
|
|
|
|
GtkWidget *filetype_menu = lookup_widget(app->window, "set_filetype1_menu");
|
2007-07-17 08:39:17 +00:00
|
|
|
GtkWidget *sub_menu = filetype_menu;
|
2007-07-09 12:46:16 +00:00
|
|
|
GtkWidget *sub_menu_programming, *sub_menu_scripts, *sub_menu_markup, *sub_menu_misc;
|
|
|
|
GtkWidget *sub_item_programming, *sub_item_scripts, *sub_item_markup, *sub_item_misc;
|
2007-04-25 15:01:14 +00:00
|
|
|
|
2007-07-09 12:46:16 +00:00
|
|
|
create_sub_menu(sub_menu_programming, sub_item_programming, _("_Programming Languages"));
|
|
|
|
create_sub_menu(sub_menu_scripts, sub_item_scripts, _("_Scripting Languages"));
|
|
|
|
create_sub_menu(sub_menu_markup, sub_item_markup, _("_Markup Languages"));
|
|
|
|
create_sub_menu(sub_menu_misc, sub_item_misc, _("M_iscellaneous Languages"));
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Append all filetypes to the filetype menu */
|
2007-04-25 15:01:14 +00:00
|
|
|
for (ft_id = 0; ft_id < GEANY_MAX_FILE_TYPES; ft_id++)
|
|
|
|
{
|
|
|
|
filetype *ft = filetypes[ft_id];
|
2007-07-09 12:46:16 +00:00
|
|
|
const gchar *title = ft->title;
|
2006-05-10 19:54:44 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* insert separators for different filetype groups */
|
2007-05-14 12:55:55 +00:00
|
|
|
switch (ft_id)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_GROUP_COMPILED: /* programming */
|
2007-07-09 12:46:16 +00:00
|
|
|
{
|
|
|
|
sub_menu = sub_menu_programming;
|
|
|
|
break;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_GROUP_SCRIPT: /* scripts */
|
2007-05-14 12:55:55 +00:00
|
|
|
{
|
2007-07-09 12:46:16 +00:00
|
|
|
sub_menu = sub_menu_scripts;
|
|
|
|
break;
|
2007-05-14 12:55:55 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_GROUP_MARKUP: /* markup */
|
|
|
|
{ /* (include also CSS, not really markup but fit quite well to HTML) */
|
2007-07-09 12:46:16 +00:00
|
|
|
sub_menu = sub_menu_markup;
|
2007-05-14 12:55:55 +00:00
|
|
|
break;
|
2007-07-09 12:46:16 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_GROUP_MISC: /* misc */
|
2007-07-09 12:46:16 +00:00
|
|
|
{
|
|
|
|
sub_menu = sub_menu_misc;
|
|
|
|
break;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_ALL: /* none */
|
2007-07-09 12:46:16 +00:00
|
|
|
{
|
|
|
|
sub_menu = filetype_menu;
|
|
|
|
title = _("None");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
2007-05-14 12:55:55 +00:00
|
|
|
}
|
2007-04-25 15:01:14 +00:00
|
|
|
ft->item = NULL;
|
2008-04-28 16:52:20 +00:00
|
|
|
create_radio_menu_item(sub_menu, title, ft);
|
2007-04-25 15:01:14 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 16:52:20 +00:00
|
|
|
void filetypes_init()
|
|
|
|
{
|
|
|
|
filetypes_init_types();
|
|
|
|
create_set_filetype_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-01 17:01:32 +00:00
|
|
|
static gboolean match_basename(G_GNUC_UNUSED gpointer key, gpointer value, gpointer user_data)
|
2008-05-01 14:30:20 +00:00
|
|
|
{
|
2008-05-01 17:01:32 +00:00
|
|
|
filetype *ft = value;
|
2008-05-01 14:30:20 +00:00
|
|
|
const gchar *base_filename = user_data;
|
|
|
|
gint j;
|
2008-05-01 17:01:32 +00:00
|
|
|
gboolean ret = FALSE;
|
2008-05-01 14:30:20 +00:00
|
|
|
|
|
|
|
/* Don't match '*' because it comes before any custom filetypes */
|
|
|
|
if (ft->id == GEANY_FILETYPES_ALL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (j = 0; ft->pattern[j] != NULL; j++)
|
|
|
|
{
|
|
|
|
GPatternSpec *pattern = g_pattern_spec_new(ft->pattern[j]);
|
|
|
|
|
|
|
|
if (g_pattern_match_string(pattern, base_filename))
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
g_pattern_spec_free(pattern);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_pattern_spec_free(pattern);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 17:09:57 +00:00
|
|
|
/* Detect filetype only based on the filename extension.
|
|
|
|
* utf8_filename can include the full path. */
|
|
|
|
filetype *filetypes_detect_from_extension(const gchar *utf8_filename)
|
|
|
|
{
|
|
|
|
gchar *base_filename;
|
2008-05-01 14:30:20 +00:00
|
|
|
filetype *ft;
|
2008-03-05 17:09:57 +00:00
|
|
|
|
2008-05-01 14:30:20 +00:00
|
|
|
/* to match against the basename of the file (because of Makefile*) */
|
2008-03-05 17:09:57 +00:00
|
|
|
base_filename = g_path_get_basename(utf8_filename);
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* use lower case basename */
|
|
|
|
setptr(base_filename, g_utf8_strdown(base_filename, -1));
|
|
|
|
#endif
|
|
|
|
|
2008-05-01 17:01:32 +00:00
|
|
|
ft = g_hash_table_find(filetypes_hash, match_basename, base_filename);
|
2008-05-01 14:30:20 +00:00
|
|
|
if (ft == NULL)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_ALL];
|
2008-03-05 17:09:57 +00:00
|
|
|
|
|
|
|
g_free(base_filename);
|
2008-05-01 14:30:20 +00:00
|
|
|
return ft;
|
2008-03-05 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static filetype *find_shebang(const gchar *utf8_filename, const gchar *line)
|
2006-10-06 23:23:05 +00:00
|
|
|
{
|
|
|
|
filetype *ft = NULL;
|
|
|
|
|
2007-05-25 15:19:23 +00:00
|
|
|
if (strlen(line) > 2 && line[0] == '#' && line[1] == '!')
|
2006-10-06 23:23:05 +00:00
|
|
|
{
|
2007-11-04 10:06:06 +00:00
|
|
|
gchar *tmp = g_path_get_basename(line + 2);
|
|
|
|
gchar *basename_interpreter = tmp;
|
|
|
|
|
|
|
|
if (strncmp(tmp, "env ", 4) == 0 && strlen(tmp) > 4)
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* skip "env" and read the following interpreter */
|
2007-11-04 10:06:06 +00:00
|
|
|
basename_interpreter +=4;
|
|
|
|
}
|
2006-10-06 23:23:05 +00:00
|
|
|
|
|
|
|
if (strncmp(basename_interpreter, "sh", 2) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
|
|
|
else if (strncmp(basename_interpreter, "bash", 4) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
|
|
|
else if (strncmp(basename_interpreter, "perl", 4) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_PERL];
|
|
|
|
else if (strncmp(basename_interpreter, "python", 6) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_PYTHON];
|
|
|
|
else if (strncmp(basename_interpreter, "php", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_PHP];
|
|
|
|
else if (strncmp(basename_interpreter, "ruby", 4) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_RUBY];
|
|
|
|
else if (strncmp(basename_interpreter, "tcl", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_TCL];
|
|
|
|
else if (strncmp(basename_interpreter, "zsh", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
|
|
|
else if (strncmp(basename_interpreter, "ksh", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
|
|
|
else if (strncmp(basename_interpreter, "csh", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
2007-05-25 13:08:17 +00:00
|
|
|
else if (strncmp(basename_interpreter, "ash", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_SH];
|
2006-10-22 17:30:24 +00:00
|
|
|
else if (strncmp(basename_interpreter, "dmd", 3) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_D];
|
2007-05-25 13:08:17 +00:00
|
|
|
else if (strncmp(basename_interpreter, "wish", 4) == 0)
|
|
|
|
ft = filetypes[GEANY_FILETYPES_TCL];
|
2006-10-06 23:23:05 +00:00
|
|
|
|
2007-11-04 10:06:06 +00:00
|
|
|
g_free(tmp);
|
2006-10-06 23:23:05 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* detect XML files */
|
2008-03-05 17:09:57 +00:00
|
|
|
if (utf8_filename && strncmp(line, "<?xml", 5) == 0)
|
2007-05-25 15:19:23 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* HTML and DocBook files might also start with <?xml, so detect them based on filename
|
|
|
|
* extension and use the detected filetype, else assume XML */
|
2008-03-05 17:09:57 +00:00
|
|
|
ft = filetypes_detect_from_extension(utf8_filename);
|
2007-05-25 15:19:23 +00:00
|
|
|
if (FILETYPE_ID(ft) != GEANY_FILETYPES_HTML &&
|
|
|
|
FILETYPE_ID(ft) != GEANY_FILETYPES_DOCBOOK &&
|
2008-02-27 13:17:29 +00:00
|
|
|
FILETYPE_ID(ft) != GEANY_FILETYPES_PERL && /* Perl, Python and PHP only to be safe */
|
2007-05-25 15:19:23 +00:00
|
|
|
FILETYPE_ID(ft) != GEANY_FILETYPES_PHP &&
|
|
|
|
FILETYPE_ID(ft) != GEANY_FILETYPES_PYTHON)
|
2008-03-05 17:09:57 +00:00
|
|
|
{
|
2007-05-25 15:19:23 +00:00
|
|
|
ft = filetypes[GEANY_FILETYPES_XML];
|
2008-03-05 17:09:57 +00:00
|
|
|
}
|
2007-05-25 15:19:23 +00:00
|
|
|
}
|
2007-07-12 18:07:49 +00:00
|
|
|
else if (strncmp(line, "<?php", 5) == 0)
|
|
|
|
{
|
|
|
|
ft = filetypes[GEANY_FILETYPES_PHP];
|
|
|
|
}
|
2006-10-06 23:23:05 +00:00
|
|
|
|
|
|
|
return ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 17:09:57 +00:00
|
|
|
/* Detect the filetype checking for a shebang, then filename extension. */
|
|
|
|
static filetype *filetypes_detect_from_file_internal(const gchar *utf8_filename, const gchar *line)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2006-10-06 23:23:05 +00:00
|
|
|
filetype *ft;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try to find a shebang and if found use it prior to the filename extension
|
|
|
|
* also checks for <?xml */
|
2008-03-05 17:09:57 +00:00
|
|
|
ft = find_shebang(utf8_filename, line);
|
|
|
|
if (ft != NULL)
|
|
|
|
return ft;
|
2006-10-06 23:23:05 +00:00
|
|
|
|
2008-03-05 17:09:57 +00:00
|
|
|
if (utf8_filename == NULL)
|
2006-10-06 23:23:05 +00:00
|
|
|
return filetypes[GEANY_FILETYPES_ALL];
|
2007-04-18 12:12:51 +00:00
|
|
|
|
2008-03-05 17:09:57 +00:00
|
|
|
return filetypes_detect_from_extension(utf8_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Detect the filetype for document idx. */
|
|
|
|
filetype *filetypes_detect_from_file(gint idx)
|
|
|
|
{
|
|
|
|
filetype *ft;
|
|
|
|
gchar *line;
|
|
|
|
|
|
|
|
if (! DOC_IDX_VALID(idx))
|
|
|
|
return filetypes[GEANY_FILETYPES_ALL];
|
|
|
|
|
|
|
|
line = sci_get_line(doc_list[idx].sci, 0);
|
|
|
|
ft = filetypes_detect_from_file_internal(doc_list[idx].file_name, line);
|
|
|
|
g_free(line);
|
|
|
|
return ft;
|
2007-04-18 12:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Detect filetype based on the filename extension.
|
|
|
|
* utf8_filename can include the full path. */
|
|
|
|
filetype *filetypes_detect_from_filename(const gchar *utf8_filename)
|
|
|
|
{
|
2008-03-05 17:09:57 +00:00
|
|
|
gchar line[1024];
|
|
|
|
FILE *f;
|
|
|
|
gchar *locale_name = utils_get_locale_from_utf8(utf8_filename);
|
2006-02-25 22:30:45 +00:00
|
|
|
|
2008-03-05 17:09:57 +00:00
|
|
|
f = g_fopen(locale_name, "r");
|
|
|
|
g_free(locale_name);
|
|
|
|
if (f != NULL)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-03-05 17:09:57 +00:00
|
|
|
if (fgets(line, sizeof(line), f) != NULL)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-03-05 17:09:57 +00:00
|
|
|
fclose(f);
|
|
|
|
return filetypes_detect_from_file_internal(utf8_filename, line);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-03-05 17:09:57 +00:00
|
|
|
fclose(f);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-03-05 17:09:57 +00:00
|
|
|
return filetypes_detect_from_extension(utf8_filename);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-03 22:17:10 +00:00
|
|
|
void filetypes_select_radio_item(const filetype *ft)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* app->ignore_callback has to be set by the caller */
|
2006-08-04 21:03:12 +00:00
|
|
|
if (ft == NULL)
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
|
|
|
|
radio_items[filetypes[GEANY_FILETYPES_ALL]->id]), TRUE);
|
|
|
|
else
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(radio_items[ft->id]), TRUE);
|
2006-08-03 22:17:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-19 13:26:06 +00:00
|
|
|
static void
|
|
|
|
on_filetype_change (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint idx = document_get_cur_idx();
|
|
|
|
if (app->ignore_callback || idx < 0 || ! doc_list[idx].is_valid) return;
|
|
|
|
|
|
|
|
document_set_filetype(idx, (filetype*)user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 16:52:20 +00:00
|
|
|
static void create_radio_menu_item(GtkWidget *menu, const gchar *label, filetype *ftype)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2006-08-03 22:17:10 +00:00
|
|
|
static GSList *group = NULL;
|
|
|
|
GtkWidget *tmp;
|
2007-04-25 15:01:14 +00:00
|
|
|
|
2006-08-03 22:17:10 +00:00
|
|
|
tmp = gtk_radio_menu_item_new_with_label(group, label);
|
|
|
|
group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(tmp));
|
|
|
|
radio_items[ftype->id] = tmp;
|
2005-11-22 12:26:26 +00:00
|
|
|
gtk_widget_show(tmp);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), tmp);
|
|
|
|
g_signal_connect((gpointer) tmp, "activate", G_CALLBACK(on_filetype_change), (gpointer) ftype);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
static void free_filetype(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
2008-04-28 14:41:09 +00:00
|
|
|
{
|
2008-05-01 17:25:18 +00:00
|
|
|
filetype *ft = data;
|
2008-04-28 14:41:09 +00:00
|
|
|
|
|
|
|
g_return_if_fail(ft != NULL);
|
|
|
|
|
|
|
|
g_free(ft->name);
|
|
|
|
g_free(ft->title);
|
|
|
|
g_free(ft->extension);
|
|
|
|
g_free(ft->comment_open);
|
|
|
|
g_free(ft->comment_close);
|
|
|
|
g_free(ft->context_action_cmd);
|
|
|
|
g_free(ft->programs->compiler);
|
|
|
|
g_free(ft->programs->linker);
|
|
|
|
g_free(ft->programs->run_cmd);
|
|
|
|
g_free(ft->programs->run_cmd2);
|
|
|
|
g_free(ft->programs);
|
|
|
|
g_free(ft->actions);
|
|
|
|
|
|
|
|
g_strfreev(ft->pattern);
|
|
|
|
g_free(ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/* frees the array and all related pointers */
|
2006-10-06 23:23:05 +00:00
|
|
|
void filetypes_free_types()
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-05-01 17:25:18 +00:00
|
|
|
g_return_if_fail(filetypes_array != NULL);
|
2008-04-28 14:41:09 +00:00
|
|
|
g_return_if_fail(filetypes_hash != NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
g_ptr_array_foreach(filetypes_array, free_filetype, NULL);
|
|
|
|
g_ptr_array_free(filetypes_array, TRUE);
|
2008-04-28 14:41:09 +00:00
|
|
|
g_hash_table_destroy(filetypes_hash);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-02 17:44:05 +00:00
|
|
|
static void load_settings(gint ft, GKeyFile *config, GKeyFile *configh)
|
2006-04-27 18:06:35 +00:00
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean tmp;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* default extension */
|
2007-11-01 16:33:06 +00:00
|
|
|
result = g_key_file_get_string(configh, "settings", "extension", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "settings", "extension", NULL);
|
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
setptr(filetypes[ft]->extension, result);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* read comment notes */
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "settings", "comment_open", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "settings", "comment_open", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
g_free(filetypes[ft]->comment_open);
|
|
|
|
filetypes[ft]->comment_open = result;
|
2006-05-10 19:54:44 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "settings", "comment_close", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "settings", "comment_close", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
g_free(filetypes[ft]->comment_close);
|
|
|
|
filetypes[ft]->comment_close = result;
|
|
|
|
}
|
|
|
|
|
2006-05-15 19:49:30 +00:00
|
|
|
tmp = g_key_file_get_boolean(configh, "settings", "comment_use_indent", &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_error_free(error);
|
|
|
|
error = NULL;
|
|
|
|
tmp = g_key_file_get_boolean(config, "settings", "comment_use_indent", &error);
|
|
|
|
if (error) g_error_free(error);
|
|
|
|
else filetypes[ft]->comment_use_indent = tmp;
|
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
else filetypes[ft]->comment_use_indent = tmp;
|
2006-05-10 19:54:44 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* read context action */
|
2007-04-15 18:09:59 +00:00
|
|
|
result = g_key_file_get_string(configh, "settings", "context_action_cmd", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "settings", "context_action_cmd", NULL);
|
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
filetypes[ft]->context_action_cmd = result;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* read build settings */
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "build_settings", "compiler", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "build_settings", "compiler", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
filetypes[ft]->programs->compiler = result;
|
2006-11-30 15:42:52 +00:00
|
|
|
filetypes[ft]->actions->can_compile = TRUE;
|
2006-05-10 19:54:44 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "build_settings", "linker", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "build_settings", "linker", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
filetypes[ft]->programs->linker = result;
|
2006-11-30 15:42:52 +00:00
|
|
|
filetypes[ft]->actions->can_link = TRUE;
|
2006-05-10 19:54:44 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "build_settings", "run_cmd", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "build_settings", "run_cmd", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
filetypes[ft]->programs->run_cmd = result;
|
2006-11-30 15:42:52 +00:00
|
|
|
filetypes[ft]->actions->can_exec = TRUE;
|
2006-05-10 19:54:44 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-05-15 19:49:30 +00:00
|
|
|
result = g_key_file_get_string(configh, "build_settings", "run_cmd2", NULL);
|
|
|
|
if (result == NULL) result = g_key_file_get_string(config, "build_settings", "run_cmd2", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
filetypes[ft]->programs->run_cmd2 = result;
|
2006-11-30 15:42:52 +00:00
|
|
|
filetypes[ft]->actions->can_exec = TRUE;
|
2006-05-10 19:54:44 +00:00
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
}
|
2006-08-20 20:39:59 +00:00
|
|
|
|
|
|
|
|
2007-11-02 17:44:05 +00:00
|
|
|
/* simple wrapper function to print file errors in DEBUG mode */
|
|
|
|
static void load_system_keyfile(GKeyFile *key_file, const gchar *file, GKeyFileFlags flags,
|
|
|
|
G_GNUC_UNUSED GError **just_for_compatibility)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean done = g_key_file_load_from_file(key_file, file, flags, &error);
|
|
|
|
if (! done && error != NULL)
|
|
|
|
{
|
|
|
|
geany_debug("Failed to open %s (%s)", file, error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Load the configuration file for the associated filetype id.
|
|
|
|
* This should only be called when the filetype is needed, to save loading
|
|
|
|
* 20+ configuration files all at once. */
|
|
|
|
void filetypes_load_config(gint ft_id)
|
|
|
|
{
|
|
|
|
GKeyFile *config, *config_home;
|
|
|
|
static gboolean loaded[GEANY_MAX_FILE_TYPES] = {FALSE};
|
|
|
|
|
|
|
|
g_return_if_fail(ft_id >= 0 && ft_id < GEANY_MAX_FILE_TYPES);
|
2007-11-04 10:06:06 +00:00
|
|
|
|
2007-11-02 17:44:05 +00:00
|
|
|
if (loaded[ft_id])
|
|
|
|
return;
|
|
|
|
loaded[ft_id] = TRUE;
|
|
|
|
|
|
|
|
config = g_key_file_new();
|
|
|
|
config_home = g_key_file_new();
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* highlighting uses GEANY_FILETYPES_ALL for common settings */
|
2007-11-02 17:44:05 +00:00
|
|
|
gchar *ext = (ft_id != GEANY_FILETYPES_ALL) ?
|
|
|
|
filetypes_get_conf_extension(ft_id) : g_strdup("common");
|
|
|
|
gchar *f0 = g_strconcat(app->datadir, G_DIR_SEPARATOR_S "filetypes.", ext, NULL);
|
|
|
|
gchar *f = g_strconcat(app->configdir,
|
|
|
|
G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", ext, NULL);
|
|
|
|
|
|
|
|
load_system_keyfile(config, f0, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
|
|
|
g_key_file_load_from_file(config_home, f, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
|
|
|
|
|
|
|
g_free(ext);
|
|
|
|
g_free(f);
|
|
|
|
g_free(f0);
|
|
|
|
}
|
|
|
|
|
|
|
|
load_settings(ft_id, config, config_home);
|
|
|
|
highlighting_init_styles(ft_id, config, config_home);
|
2007-11-04 10:06:06 +00:00
|
|
|
|
2007-11-02 17:44:05 +00:00
|
|
|
g_key_file_free(config);
|
|
|
|
g_key_file_free(config_home);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-27 11:30:23 +00:00
|
|
|
gchar *filetypes_get_conf_extension(gint filetype_idx)
|
2006-10-01 16:14:45 +00:00
|
|
|
{
|
2007-06-22 17:34:31 +00:00
|
|
|
gchar *result;
|
2006-10-01 16:14:45 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Handle any special extensions different from lowercase filetype->name */
|
2006-10-01 16:14:45 +00:00
|
|
|
switch (filetype_idx)
|
|
|
|
{
|
|
|
|
case GEANY_FILETYPES_CPP: result = g_strdup("cpp"); break;
|
2007-06-22 17:34:31 +00:00
|
|
|
case GEANY_FILETYPES_CS: result = g_strdup("cs"); break;
|
2006-10-01 16:14:45 +00:00
|
|
|
case GEANY_FILETYPES_MAKE: result = g_strdup("makefile"); break;
|
|
|
|
case GEANY_FILETYPES_OMS: result = g_strdup("oms"); break;
|
2007-06-22 17:34:31 +00:00
|
|
|
default: result = g_ascii_strdown(filetypes[filetype_idx]->name, -1); break;
|
2006-10-01 16:14:45 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void filetypes_save_commands()
|
|
|
|
{
|
|
|
|
gchar *conf_prefix = g_strconcat(app->configdir,
|
|
|
|
G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < GEANY_FILETYPES_ALL; i++)
|
|
|
|
{
|
|
|
|
struct build_programs *bp = filetypes[i]->programs;
|
|
|
|
GKeyFile *config_home;
|
|
|
|
gchar *fname, *ext, *data;
|
|
|
|
|
|
|
|
if (! bp->modified) continue;
|
2006-10-04 19:14:57 +00:00
|
|
|
|
2006-10-27 11:30:23 +00:00
|
|
|
ext = filetypes_get_conf_extension(i);
|
2006-10-01 16:14:45 +00:00
|
|
|
fname = g_strconcat(conf_prefix, ext, NULL);
|
|
|
|
g_free(ext);
|
|
|
|
|
|
|
|
config_home = g_key_file_new();
|
|
|
|
g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
|
|
|
|
|
|
|
if (bp->compiler && *bp->compiler)
|
|
|
|
g_key_file_set_string(config_home, "build_settings", "compiler", bp->compiler);
|
|
|
|
if (bp->linker && *bp->linker)
|
|
|
|
g_key_file_set_string(config_home, "build_settings", "linker", bp->linker);
|
|
|
|
if (bp->run_cmd && *bp->run_cmd)
|
|
|
|
g_key_file_set_string(config_home, "build_settings", "run_cmd", bp->run_cmd);
|
|
|
|
if (bp->run_cmd2 && *bp->run_cmd2)
|
|
|
|
g_key_file_set_string(config_home, "build_settings", "run_cmd2", bp->run_cmd2);
|
|
|
|
|
|
|
|
data = g_key_file_to_data(config_home, NULL, NULL);
|
|
|
|
utils_write_file(fname, data);
|
|
|
|
g_free(data);
|
|
|
|
g_key_file_free(config_home);
|
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
g_free(conf_prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-01 22:38:31 +00:00
|
|
|
/* create one file filter which has each file pattern of each filetype */
|
|
|
|
GtkFileFilter *filetypes_create_file_filter_all_source()
|
|
|
|
{
|
|
|
|
GtkFileFilter *new_filter;
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
new_filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(new_filter, _("All Source"));
|
|
|
|
|
|
|
|
for (i = 0; i < GEANY_FILETYPES_ALL; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; filetypes[i]->pattern[j]; j++)
|
|
|
|
{
|
|
|
|
gtk_file_filter_add_pattern(new_filter, filetypes[i]->pattern[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-20 20:39:59 +00:00
|
|
|
GtkFileFilter *filetypes_create_file_filter(filetype *ft)
|
|
|
|
{
|
|
|
|
GtkFileFilter *new_filter;
|
|
|
|
gint i;
|
|
|
|
|
2007-03-01 22:38:31 +00:00
|
|
|
g_return_val_if_fail(ft != NULL, NULL);
|
2007-04-15 18:09:59 +00:00
|
|
|
|
2006-08-20 20:39:59 +00:00
|
|
|
new_filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(new_filter, ft->title);
|
|
|
|
|
|
|
|
for (i = 0; ft->pattern[i]; i++)
|
|
|
|
{
|
|
|
|
gtk_file_filter_add_pattern(new_filter, ft->pattern[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Indicates whether there is a tag parser for the filetype or not. */
|
2007-05-26 12:13:53 +00:00
|
|
|
gboolean filetype_has_tags(filetype *ft)
|
|
|
|
{
|
2007-05-26 15:26:05 +00:00
|
|
|
g_return_val_if_fail(ft != NULL, FALSE);
|
|
|
|
|
2007-05-26 12:13:53 +00:00
|
|
|
return ft->lang >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 14:41:09 +00:00
|
|
|
/* Add a filetype pointer to the list of available filetypes. */
|
|
|
|
void filetypes_add(filetype *ft)
|
|
|
|
{
|
|
|
|
g_return_if_fail(ft);
|
|
|
|
g_return_if_fail(ft->name);
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
g_ptr_array_add(filetypes_array, ft);
|
2008-04-28 14:41:09 +00:00
|
|
|
g_hash_table_insert(filetypes_hash, ft->name, ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove a filetype pointer from the list of available filetypes. */
|
|
|
|
void filetypes_remove(filetype *ft)
|
|
|
|
{
|
|
|
|
g_return_if_fail(ft);
|
|
|
|
|
2008-05-01 17:25:18 +00:00
|
|
|
g_ptr_array_remove(filetypes_array, ft);
|
|
|
|
|
2008-04-28 14:41:09 +00:00
|
|
|
if (!g_hash_table_remove(filetypes_hash, ft))
|
|
|
|
g_warning("Could not remove filetype %p!", ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Find a filetype pointer from its @c name field. */
|
|
|
|
filetype *filetypes_lookup_by_name(const gchar *name)
|
|
|
|
{
|
|
|
|
filetype *ft;
|
|
|
|
|
|
|
|
g_return_val_if_fail(NZV(name), NULL);
|
|
|
|
|
|
|
|
ft = g_hash_table_lookup(filetypes_hash, name);
|
|
|
|
if (ft == NULL)
|
2008-05-01 12:10:46 +00:00
|
|
|
geany_debug("Could not find filetype '%s'.", name);
|
2008-04-28 14:41:09 +00:00
|
|
|
return ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|