Kaydet (Commit) b53385de authored tarafından Enrico Tröger's avatar Enrico Tröger

Removed multiline template because it makes not much sense, instead just comment…

Removed multiline template because it makes not much sense, instead just comment three lines using the general comment functionality.
Removed special templates for Pascal and some other filetypes using "#" as comment char. The comment characters for fileheader and GPL templates are now added dynamically according to the current filetype.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1160 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 5b3b1af1
2007-01-06 Enrico Tröger <enrico.troeger@uvena.de>
* src/callbacks.c, src/sci_cb.c, src/sci_cb.h, src/templates.c,
src/templates.h:
Removed multiline template because it makes not much sense, instead
just comment three lines using the general comment functionality.
Removed special templates for Pascal and some other filetypes using
"#" as comment char. The comment characters for fileheader and GPL
templates are now added dynamically according to the current
filetype.
2007-01-06 Nick Treleaven <nick.treleaven@btinternet.com>
* src/keybindings.c:
......
/*
* callbacks.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2005-2007 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.com>
*
* 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
......@@ -1460,27 +1461,7 @@ on_comments_function_activate (GtkMenuItem *menuitem,
line = utils_get_current_function(idx, &cur_tag);
pos = sci_get_position_from_line(doc_list[idx].sci, line - 1);
switch (doc_list[idx].file_type->id)
{
case GEANY_FILETYPES_PASCAL:
{
text = templates_get_template_function(GEANY_TEMPLATE_FUNCTION_PASCAL, cur_tag);
break;
}
case GEANY_FILETYPES_PYTHON:
case GEANY_FILETYPES_RUBY:
case GEANY_FILETYPES_SH:
case GEANY_FILETYPES_MAKE:
case GEANY_FILETYPES_PERL:
{
text = templates_get_template_function(GEANY_TEMPLATE_FUNCTION_ROUTE, cur_tag);
break;
}
default:
{
text = templates_get_template_function(GEANY_TEMPLATE_FUNCTION, cur_tag);
}
}
text = templates_get_template_function(doc_list[idx].file_type->id, cur_tag);
sci_insert_text(doc_list[idx].sci, pos, text);
g_free(text);
......@@ -1492,35 +1473,27 @@ on_comments_multiline_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gint idx = document_get_cur_idx();
gchar *text;
if (doc_list[idx].file_type == NULL)
if (! DOC_IDX_VALID(idx) || doc_list[idx].file_type == NULL)
{
ui_set_statusbar(_("Please set the filetype for the current file before using this function."));
return;
}
switch (doc_list[idx].file_type->id)
{
case GEANY_FILETYPES_PASCAL:
{
text = templates_get_template_generic(GEANY_TEMPLATE_MULTILINE_PASCAL);
break;
}
case GEANY_FILETYPES_PYTHON:
case GEANY_FILETYPES_RUBY:
case GEANY_FILETYPES_SH:
case GEANY_FILETYPES_MAKE:
case GEANY_FILETYPES_PERL:
{
text = templates_get_template_generic(GEANY_TEMPLATE_MULTILINE_ROUTE);
break;
}
default:
{
text = templates_get_template_generic(GEANY_TEMPLATE_MULTILINE);
}
}
verify_click_pos(idx); // make sure that the click_pos is valid
sci_cb_insert_multiline_comment(idx);
}
void
on_comments_gpl_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gint idx = document_get_cur_idx();
gchar *text;
text = templates_get_template_licence(FILETYPE_ID(doc_list[idx].file_type));
verify_click_pos(idx); // make sure that the click_pos is valid
......@@ -1530,18 +1503,20 @@ on_comments_multiline_activate (GtkMenuItem *menuitem,
void
on_comments_gpl_activate (GtkMenuItem *menuitem,
on_comments_bsd_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
/*
gint idx = document_get_cur_idx();
gchar *text;
text = templates_get_template_gpl(FILETYPE_ID(doc_list[idx].file_type));
text = templates_get_template_licence(FILETYPE_ID(doc_list[idx].file_type), GEANY_TEMPLATE_BSD);
verify_click_pos(idx); // make sure that the click_pos is valid
sci_insert_text(doc_list[idx].sci, editor_info.click_pos, text);
g_free(text);
*/
}
......@@ -1944,7 +1919,7 @@ on_menu_comment_line1_activate (GtkMenuItem *menuitem,
{
gint idx = document_get_cur_idx();
if (idx == -1 || ! doc_list[idx].is_valid) return;
sci_cb_do_comment(idx, -1);
sci_cb_do_comment(idx, -1, FALSE);
}
......@@ -2074,6 +2049,15 @@ on_menu_comments_gpl_activate (GtkMenuItem *menuitem,
}
void
on_menu_comments_bsd_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
insert_callback_from_menu = TRUE;
on_comments_bsd_activate(menuitem, user_data);
}
void
on_menu_insert_include_activate (GtkMenuItem *menuitem,
gpointer user_data)
......@@ -2090,3 +2074,6 @@ on_menu_insert_date_activate (GtkMenuItem *menuitem,
insert_callback_from_menu = TRUE;
on_insert_date_activate(menuitem, user_data);
}
/*
* sci_cb.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2005-2007 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.com>
*
* 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
......@@ -1479,7 +1480,7 @@ void sci_cb_do_comment_toggle(gint idx)
if (do_continue) continue;
// we are still here, so the above lines were not already comments, so comment it
sci_cb_do_comment(idx, i);
sci_cb_do_comment(idx, i, FALSE);
count_commented++;
}
// use multi line comment
......@@ -1566,7 +1567,7 @@ void sci_cb_do_comment_toggle(gint idx)
}
void sci_cb_do_comment(gint idx, gint line)
void sci_cb_do_comment(gint idx, gint line, gboolean allow_empty_lines)
{
gint first_line, last_line;
gint x, i, line_start, line_len;
......@@ -1622,10 +1623,14 @@ void sci_cb_do_comment(gint idx, gint line)
sci_get_text_range(doc_list[idx].sci, line_start, MIN((line_start + 256), (line_start + line_len - 1)), sel);
sel[MIN(256, (line_len - 1))] = '\0';
/// TODO fix the above code to remove the described segfault below
// The following loop causes a segfault when the cursor is on the last line of doc and
// there are no other characters on this line and Geany was compiled with -O2, with -O0
// all works fine.
while (isspace(sel[x])) x++;
// to skip blank lines
if (x < line_len && sel[x] != '\0')
if (allow_empty_lines || (x < line_len && sel[x] != '\0'))
{
// use single line comment
if (cc == NULL || strlen(cc) == 0)
......@@ -1938,3 +1943,59 @@ gint sci_cb_lexer_get_type_keyword_idx(gint lexer)
return -1;
}
}
// inserts a three-line comment at one line above current cursor position
void sci_cb_insert_multiline_comment(gint idx)
{
gchar *text;
gint text_len;
gint line;
gint pos;
gboolean have_multiline_comment = FALSE;
if (doc_list[idx].file_type->comment_close != NULL &&
strlen(doc_list[idx].file_type->comment_close) > 0)
have_multiline_comment = TRUE;
// insert three lines one line above of the current position
line = sci_get_line_from_position(doc_list[idx].sci, editor_info.click_pos);
pos = sci_get_position_from_line(doc_list[idx].sci, line);
// use the indentation on the current line but only when comment indention is used
// and we don't have multi line comment characters
if (doc_list[idx].use_auto_indention && ! have_multiline_comment &&
doc_list[idx].file_type->comment_use_indent)
{
get_indent(doc_list[idx].sci, editor_info.click_pos, TRUE);
text = g_strdup_printf("%s\n%s\n%s\n", indent, indent, indent);
text_len = strlen(text);
}
else
{
text = g_strdup("\n\n\n");
text_len = 3;
}
sci_insert_text(doc_list[idx].sci, pos, text);
g_free(text);
// select the inserted lines for commenting
sci_set_selection_start(doc_list[idx].sci, pos);
sci_set_selection_end(doc_list[idx].sci, pos + text_len);
sci_cb_do_comment(idx, -1, TRUE);
// set the current position to the start of the first inserted line
pos += strlen(doc_list[idx].file_type->comment_open);
// on multi line comment jump to the next line, otherwise add the length of added indentation
if (have_multiline_comment)
pos += 1;
else
pos += strlen(indent);
sci_set_current_position(doc_list[idx].sci, pos);
// reset the selection
sci_set_anchor(doc_list[idx].sci, pos);
}
/*
* sci_cb.h - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2005-2007 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.com>
*
* 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
......@@ -69,7 +70,7 @@ gboolean sci_cb_show_calltip(gint idx, gint pos);
void sci_cb_do_comment_toggle(gint idx);
void sci_cb_do_comment(gint idx, gint line);
void sci_cb_do_comment(gint idx, gint line, gboolean allow_empty_lines);
void sci_cb_do_uncomment(gint idx, gint line);
......@@ -83,4 +84,6 @@ gboolean sci_cb_lexer_is_c_like(gint lexer);
gint sci_cb_lexer_get_type_keyword_idx(gint lexer);
void sci_cb_insert_multiline_comment(gint idx);
#endif
This diff is collapsed.
/*
* templates.h - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2005-2007 Enrico Troeger <enrico.troeger@uvena.de>
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.com>
*
* 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
......@@ -25,7 +26,6 @@
#include "filetypes.h"
void templates_init(void);
gchar *templates_get_template_fileheader(gint idx);
......@@ -36,28 +36,19 @@ gchar *templates_get_template_changelog(void);
gchar *templates_get_template_generic(gint template);
gchar *templates_get_template_function(gint template, const gchar *func_name);
gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name);
gchar *templates_get_template_gpl(gint filetype_idx);
gchar *templates_get_template_licence(gint filetype_idx);
void templates_free_templates(void);
enum
{
GEANY_TEMPLATE_GPL_PASCAL = 0,
GEANY_TEMPLATE_GPL_ROUTE,
GEANY_TEMPLATE_GPL,
GEANY_TEMPLATE_FILEHEADER_PASCAL,
GEANY_TEMPLATE_FILEHEADER_ROUTE,
GEANY_TEMPLATE_GPL = 0,
GEANY_TEMPLATE_FILEHEADER,
GEANY_TEMPLATE_CHANGELOG,
GEANY_TEMPLATE_FUNCTION,
GEANY_TEMPLATE_FUNCTION_PASCAL,
GEANY_TEMPLATE_FUNCTION_ROUTE,
GEANY_TEMPLATE_MULTILINE,
GEANY_TEMPLATE_MULTILINE_PASCAL,
GEANY_TEMPLATE_MULTILINE_ROUTE,
GEANY_TEMPLATE_FILETYPE_NONE,
GEANY_TEMPLATE_FILETYPE_C,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment