Revision: 751 Author: ntrel Date: 2006-08-20 13:39:59 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=751&view=rev
Log Message: ----------- Remove filetypes.h and Scintilla includes from geany.h; Add VALID_DOC_IDX macro
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/dialogs.c trunk/src/document.h trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/geany.h trunk/src/highlighting.c trunk/src/highlighting.h trunk/src/keybindings.c trunk/src/sci_cb.c trunk/src/sci_cb.h trunk/src/sciwrappers.c trunk/src/utils.c trunk/src/utils.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/ChangeLog 2006-08-20 20:39:59 UTC (rev 751) @@ -17,6 +17,16 @@ Moved HAVE_FIFO MyApp fields to fifo_info struct in src/main.c. Prevent unnecessary 'does not look like a filename' debug messages. Added fifo_finalize(). + * src/geany.h, src/filetypes.h, document.h, src/highlighting.h, + src/sci_cb.h, src/highlighting.c, src/sciwrappers.c: + Remove filetypes.h and Scintilla includes from geany.h. + * src/document.h: Add VALID_DOC_IDX macro. + * src/utils.h, src/utils.c, src/callbacks.c, src/keybindings.c, + src/sci_cb.h, src/sci_cb.c, src/dialogs.c, src/filetypes.h, + src/filetypes.c: + Move utils_brace_match to sci_cb.c. + Move utils_find_current_word to sci_cb.c. + Move utils_create_file_filter to filetypes.c.
2006-08-19 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/callbacks.c 2006-08-20 20:39:59 UTC (rev 751) @@ -1042,8 +1042,7 @@
if (event->button == 3) { - utils_find_current_word(doc_list[idx].sci, clickpos, - current_word, sizeof current_word); + sci_cb_find_current_word(doc_list[idx].sci, clickpos, current_word, sizeof current_word);
utils_update_popup_goto_items((current_word[0] != '\0') ? TRUE : FALSE); utils_update_popup_copy_items(idx); @@ -1437,7 +1436,7 @@ if (idx == -1 || ! doc_list[idx].is_valid) return;
- utils_find_current_word(doc_list[idx].sci, pos, colour, sizeof colour); + sci_cb_find_current_word(doc_list[idx].sci, pos, colour, sizeof colour); dialogs_show_color(colour); }
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/dialogs.c 2006-08-20 20:39:59 UTC (rev 751) @@ -95,14 +95,14 @@
// add FileFilters(start with "All Files") gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel), - utils_create_file_filter(filetypes[GEANY_FILETYPES_ALL])); + filetypes_create_file_filter(filetypes[GEANY_FILETYPES_ALL])); for (i = 0; i < GEANY_MAX_FILE_TYPES - 1; i++) { if (filetypes[i]) { gtk_combo_box_append_text(GTK_COMBO_BOX(combo), filetypes[i]->title); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel), - utils_create_file_filter(filetypes[i])); + filetypes_create_file_filter(filetypes[i])); } } gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Detect by file extension "));
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/document.h 2006-08-20 20:39:59 UTC (rev 751) @@ -24,8 +24,20 @@ #ifndef GEANY_DOCUMENT_H #define GEANY_DOCUMENT_H 1
+#ifndef PLAT_GTK +# define PLAT_GTK 1 // needed for ScintillaWidget.h +#endif + +#include "Scintilla.h" +#include "ScintillaWidget.h" + #include "geany.h" +#include "filetypes.h"
+#define VALID_DOC_IDX(idx) \ + ((idx) >= 0 && (idx) < GEANY_MAX_OPEN_FILES && doc_list[idx].is_valid) + + /* structure for representing an open tab with all its related stuff. */ typedef struct document {
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/filetypes.c 2006-08-20 20:39:59 UTC (rev 751) @@ -827,3 +827,24 @@ filetypes[ft]->menu_items->can_exec = TRUE; } } + + +GtkFileFilter *filetypes_create_file_filter(filetype *ft) +{ + GtkFileFilter *new_filter; + gint i; + + new_filter = gtk_file_filter_new(); + gtk_file_filter_set_name(new_filter, ft->title); + + // (GEANY_FILETYPES_MAX_PATTERNS - 1) because the last field in pattern is NULL + //for (i = 0; i < (GEANY_MAX_PATTERNS - 1) && ft->pattern[i]; i++) + for (i = 0; ft->pattern[i]; i++) + { + gtk_file_filter_add_pattern(new_filter, ft->pattern[i]); + } + + return new_filter; +} + +
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/filetypes.h 2006-08-20 20:39:59 UTC (rev 751) @@ -24,7 +24,14 @@ #ifndef GEANY_FILETYPES_H #define GEANY_FILETYPES_H 1
+#ifndef PLAT_GTK +# define PLAT_GTK 1 // needed for ScintillaWidget.h +#endif
+#include "Scintilla.h" +#include "ScintillaWidget.h" + + enum { GEANY_FILETYPES_C = 0, @@ -118,4 +125,6 @@
void filetypes_select_radio_item(const filetype *ft);
+GtkFileFilter *filetypes_create_file_filter(filetype *ft); + #endif
Modified: trunk/src/geany.h =================================================================== --- trunk/src/geany.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/geany.h 2006-08-20 20:39:59 UTC (rev 751) @@ -29,20 +29,9 @@
#include <gtk/gtk.h>
-#ifndef PLAT_GTK -# define PLAT_GTK 1 -#endif - -#include "Scintilla.h" -#include "ScintillaWidget.h" - #include "tm_tagmanager.h"
-#include "filetypes.h"
-#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l) - - // for detailed description look in the documentation, things are not // listed in the documentation should not be changed ;-) #define GEANY_HOME_DIR g_get_home_dir()
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/highlighting.c 2006-08-20 20:39:59 UTC (rev 751) @@ -28,6 +28,7 @@ #include "sci_cb.h" #include "utils.h" #include "main.h" +#include "filetypes.h"
static style_set *types[GEANY_MAX_FILE_TYPES] = { NULL };
Modified: trunk/src/highlighting.h =================================================================== --- trunk/src/highlighting.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/highlighting.h 2006-08-20 20:39:59 UTC (rev 751) @@ -24,7 +24,14 @@ #ifndef GEANY_HIGHLIGHTING_H #define GEANY_HIGHLIGHTING_H 1
+#ifndef PLAT_GTK +# define PLAT_GTK 1 // needed for ScintillaWidget.h +#endif
+#include "Scintilla.h" +#include "ScintillaWidget.h" + + typedef struct { gint styling[55][4];
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/keybindings.c 2006-08-20 20:39:59 UTC (rev 751) @@ -633,8 +633,7 @@
pos = sci_get_current_position(doc_list[idx].sci);
- utils_find_current_word(doc_list[idx].sci, pos, - current_word, GEANY_MAX_WORD_LENGTH); + sci_cb_find_current_word(doc_list[idx].sci, pos, current_word, GEANY_MAX_WORD_LENGTH);
if (*current_word == 0) utils_beep();
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/sci_cb.c 2006-08-20 20:39:59 UTC (rev 751) @@ -335,10 +335,47 @@ }
+/* Finds a corresponding matching brace to the given pos + * (this is taken from Scintilla Editor.cxx, + * fit to work with sci_cb_close_block) */ +static gint brace_match(ScintillaObject *sci, gint pos) +{ + gchar chBrace = sci_get_char_at(sci, pos); + gchar chSeek = utils_brace_opposite(chBrace); + gint direction, styBrace, depth = 1; + + if (chSeek == '\0') return -1; + styBrace = sci_get_style_at(sci, pos); + direction = -1; + + if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') + direction = 1; + + pos = pos + direction; + while ((pos >= 0) && (pos < sci_get_length(sci))) + { + gchar chAtPos = sci_get_char_at(sci, pos - 1); + gint styAtPos = sci_get_style_at(sci, pos); + + if ((pos > sci_get_end_styled(sci)) || (styAtPos == styBrace)) + { + if (chAtPos == chBrace) + depth++; + if (chAtPos == chSeek) + depth--; + if (depth == 0) + return pos; + } + pos = pos + direction; + } + return - 1; +} + + void sci_cb_close_block(ScintillaObject *sci, gint pos) { gint x = 0, cnt = 0; - gint start_brace = utils_brace_match(sci, pos); + gint start_brace = brace_match(sci, pos); gint line = sci_get_line_from_position(sci, pos); gint line_start = sci_get_position_from_line(sci, line); gint line_len = sci_get_line_length(sci, line); @@ -377,6 +414,32 @@ }
+void sci_cb_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen) +{ + gint line = sci_get_line_from_position(sci, pos); + gint line_start = sci_get_position_from_line(sci, line); + gint startword = pos - line_start; + gint endword = pos - line_start; + gchar *chunk = g_malloc(sci_get_line_length(sci, line) + 1); + + word[0] = '\0'; + sci_get_line(sci, line, chunk); + chunk[sci_get_line_length(sci, line)] = '\0'; + + while (startword > 0 && strchr(GEANY_WORDCHARS, chunk[startword - 1])) + startword--; + while (chunk[endword] && strchr(GEANY_WORDCHARS, chunk[endword])) + endword++; + if(startword == endword) + return; + + chunk[endword] = '\0'; + + g_strlcpy(word, chunk + startword, wordlen); //ensure null terminated + g_free(chunk); +} + + gboolean sci_cb_show_calltip(ScintillaObject *sci, gint pos, gint idx) { gint orig_pos = pos; //the position for the calltip @@ -413,7 +476,7 @@ if (lexer == SCLEX_CPP && (style == SCE_C_COMMENT || style == SCE_C_COMMENTLINE || style == SCE_C_COMMENTDOC)) return FALSE;
- utils_find_current_word(sci, pos - 1, word, sizeof word); + sci_cb_find_current_word(sci, pos - 1, word, sizeof word); if (word[0] == '\0') return FALSE;
tags = tm_workspace_find(word, tm_tag_max_t, NULL, FALSE, doc_list[idx].file_type->lang); @@ -913,7 +976,8 @@ { gint first_line, last_line; gint x, i, line_start, line_len; - gint sel_start, sel_end, co_len; + gint sel_start, sel_end; + gsize co_len; gchar sel[64], *co, *cc; gboolean break_loop = FALSE, single_line = FALSE; filetype *ft;
Modified: trunk/src/sci_cb.h =================================================================== --- trunk/src/sci_cb.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/sci_cb.h 2006-08-20 20:39:59 UTC (rev 751) @@ -22,7 +22,16 @@ #ifndef GEANY_SCI_CB_H #define GEANY_SCI_CB_H 1
+#ifndef PLAT_GTK +# define PLAT_GTK 1 // needed for ScintillaWidget.h +#endif
+#include "Scintilla.h" +#include "ScintillaWidget.h" + +#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l) + + gchar **html_entities;
@@ -43,6 +52,8 @@
gboolean sci_cb_handle_xml(ScintillaObject *sci, gchar ch);
+void sci_cb_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen); + gboolean sci_cb_show_calltip(ScintillaObject *sci, gint pos, gint idx);
void sci_cb_do_comment(gint idx);
Modified: trunk/src/sciwrappers.c =================================================================== --- trunk/src/sciwrappers.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/sciwrappers.c 2006-08-20 20:39:59 UTC (rev 751) @@ -27,7 +27,9 @@ #include "sciwrappers.h" #include "utils.h"
+#define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
+ // stolen from cssed (http://cssed.sf.net), thanks
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/utils.c 2006-08-20 20:39:59 UTC (rev 751) @@ -263,25 +263,6 @@ }
-GtkFileFilter *utils_create_file_filter(filetype *ft) -{ - GtkFileFilter *new_filter; - gint i; - - new_filter = gtk_file_filter_new(); - gtk_file_filter_set_name(new_filter, ft->title); - - // (GEANY_FILETYPES_MAX_PATTERNS - 1) because the last field in pattern is NULL - //for (i = 0; i < (GEANY_MAX_PATTERNS - 1) && ft->pattern[i]; i++) - for (i = 0; ft->pattern[i]; i++) - { - gtk_file_filter_add_pattern(new_filter, ft->pattern[i]); - } - - return new_filter; -} - - /* taken from anjuta, to determine the EOL mode of the file */ gint utils_get_line_endings(gchar* buffer, glong size) { @@ -1089,32 +1070,6 @@ }
-void utils_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen) -{ - gint line = sci_get_line_from_position(sci, pos); - gint line_start = sci_get_position_from_line(sci, line); - gint startword = pos - line_start; - gint endword = pos - line_start; - gchar *chunk = g_malloc(sci_get_line_length(sci, line) + 1); - - word[0] = '\0'; - sci_get_line(sci, line, chunk); - chunk[sci_get_line_length(sci, line)] = '\0'; - - while (startword > 0 && strchr(GEANY_WORDCHARS, chunk[startword - 1])) - startword--; - while (chunk[endword] && strchr(GEANY_WORDCHARS, chunk[endword])) - endword++; - if(startword == endword) - return; - - chunk[endword] = '\0'; - - g_strlcpy(word, chunk + startword, wordlen); //ensure null terminated - g_free(chunk); -} - - /* returns the end-of-line character(s) length of the specified editor */ gint utils_get_eol_char_len(gint idx) { @@ -1422,43 +1377,6 @@ }
-/* Finds a corresponding matching brace to the given pos - * (this is taken from Scintilla Editor.cxx, - * fit to work with sci_cb_close_block) */ -gint utils_brace_match(ScintillaObject *sci, gint pos) -{ - gchar chBrace = sci_get_char_at(sci, pos); - gchar chSeek = utils_brace_opposite(chBrace); - gint direction, styBrace, depth = 1; - - if (chSeek == '\0') return -1; - styBrace = sci_get_style_at(sci, pos); - direction = -1; - - if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') - direction = 1; - - pos = pos + direction; - while ((pos >= 0) && (pos < sci_get_length(sci))) - { - gchar chAtPos = sci_get_char_at(sci, pos - 1); - gint styAtPos = sci_get_style_at(sci, pos); - - if ((pos > sci_get_end_styled(sci)) || (styAtPos == styBrace)) - { - if (chAtPos == chBrace) - depth++; - if (chAtPos == chSeek) - depth--; - if (depth == 0) - return pos; - } - pos = pos + direction; - } - return - 1; -} - - gchar utils_brace_opposite(gchar ch) { switch (ch)
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2006-08-20 15:47:18 UTC (rev 750) +++ trunk/src/utils.h 2006-08-20 20:39:59 UTC (rev 751) @@ -87,8 +87,6 @@
void utils_set_fullscreen(void);
-GtkFileFilter *utils_create_file_filter(filetype *ft); - void utils_update_tag_list(gint idx, gboolean update);
gchar *utils_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_encoding); @@ -107,8 +105,6 @@ //gchar *utils_get_current_tag(gint idx, gint direction); gint utils_get_current_function(gint idx, const gchar **tagname);
-void utils_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen); - /* returns the end-of-line character(s) length of the specified editor */ gint utils_get_eol_char_len(gint idx);
@@ -141,12 +137,6 @@ gchar *utils_remove_ext_from_filename(const gchar *filename);
-/* Finds a corresponding matching brace to the given pos - * (this is taken from Scintilla Editor.cxx, - * fit to work with sci_cb_close_block) */ -gint utils_brace_match(ScintillaObject *sci, gint pos); - - gchar utils_brace_opposite(gchar ch);
gchar *utils_get_hostname(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.