Revision: 750 Author: eht16 Date: 2006-08-20 08:47:18 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=750&view=rev
Log Message: ----------- Moved prototype for geany_debug() to main.h. Moved declaration of document struct to document.h. Keep selection when commenting and uncommenting code.
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/document.c trunk/src/document.h trunk/src/geany.h trunk/src/highlighting.c trunk/src/main.h trunk/src/sci_cb.c trunk/src/search.c trunk/src/templates.c trunk/src/utils.c trunk/src/vte.c Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/ChangeLog 2006-08-20 15:47:18 UTC (rev 750) @@ -1,3 +1,13 @@ +2006-08-20 Enrico Tröger enrico.troeger@uvena.de + + * src/build.c, src/document.c, src/document.h, src/geany.h, + src/highlighting.c, src/main.h, src/sci_cb.c, src/search.c, + src/templates.c, src/utils.c, src/vte.c: + Moved prototype for geany_debug() to main.h. + Moved declaration of document struct to document.h. + * src/sci_cb.c: Keep selection when commenting and uncommenting code. + + 2006-08-20 Nick Treleaven nick.treleaven@btinternet.com
* src/callbacks.c, src/main.c:
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/build.c 2006-08-20 15:47:18 UTC (rev 750) @@ -40,6 +40,7 @@ #include "dialogs.h" #include "msgwindow.h" #include "document.h" +#include "main.h"
static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data);
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/document.c 2006-08-20 15:47:18 UTC (rev 750) @@ -55,6 +55,7 @@ #include "utils.h" #include "encodings.h" #include "notebook.h" +#include "main.h"
/* Returns -1 if no text found or the new range endpoint after replacing. */
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/document.h 2006-08-20 15:47:18 UTC (rev 750) @@ -24,7 +24,40 @@ #ifndef GEANY_DOCUMENT_H #define GEANY_DOCUMENT_H 1
+#include "geany.h"
+/* structure for representing an open tab with all its related stuff. */ +typedef struct document +{ + gboolean is_valid; + gboolean has_tags; + // the filename is encoded in UTF-8, but every GLibC function expect the locale representation + gchar *file_name; + gchar *encoding; + gboolean has_bom; + filetype *file_type; + TMWorkObject *tm_file; + ScintillaObject *sci; + GtkWidget *tab_label; + GtkWidget *tabmenu_label; + GtkWidget *tag_tree; + GtkTreeStore *tag_store; + GtkTreeIter iter; + gboolean readonly; + gboolean changed; + gboolean do_overwrite; + gboolean line_breaking; + gboolean use_auto_indention; + time_t last_check; // to remember the last disk check + time_t mtime; +} document; + + +/* array of document elements to hold all information of the notebook tabs */ +document doc_list[GEANY_MAX_OPEN_FILES]; + + + /* returns the index of the notebook page which has the given filename */ gint document_find_by_filename(const gchar*, gboolean is_tm_filename);
Modified: trunk/src/geany.h =================================================================== --- trunk/src/geany.h 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/geany.h 2006-08-20 15:47:18 UTC (rev 750) @@ -77,38 +77,6 @@
-/* structure for representing an open tab with all its related stuff. */ -typedef struct document -{ - gboolean is_valid; - gboolean has_tags; - // the filename is encoded in UTF-8, but every GLibC function expect the locale representation - gchar *file_name; - gchar *encoding; - gboolean has_bom; - filetype *file_type; - TMWorkObject *tm_file; - ScintillaObject *sci; - GtkWidget *tab_label; - GtkWidget *tabmenu_label; - GtkWidget *tag_tree; - GtkTreeStore *tag_store; - GtkTreeIter iter; - gboolean readonly; - gboolean changed; - gboolean do_overwrite; - gboolean line_breaking; - gboolean use_auto_indention; - time_t last_check; // to remember the last disk check - time_t mtime; -} document; - - - -/* array of document elements to hold all information of the notebook tabs */ -document doc_list[GEANY_MAX_OPEN_FILES]; - - /* store some pointers and variables for frequently used widgets */ typedef struct MyApp { @@ -253,8 +221,5 @@ GIGABYTE = (MEGABYTE*1024) };
-// implementation in main.c -void geany_debug(gchar const *format, ...);
- #endif
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/highlighting.c 2006-08-20 15:47:18 UTC (rev 750) @@ -27,6 +27,7 @@ #include "highlighting.h" #include "sci_cb.h" #include "utils.h" +#include "main.h"
static style_set *types[GEANY_MAX_FILE_TYPES] = { NULL };
Modified: trunk/src/main.h =================================================================== --- trunk/src/main.h 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/main.h 2006-08-20 15:47:18 UTC (rev 750) @@ -27,4 +27,6 @@
void fifo_finalize();
+void geany_debug(gchar const *format, ...); + #endif
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/sci_cb.c 2006-08-20 15:47:18 UTC (rev 750) @@ -31,6 +31,7 @@ #include "document.h" #include "sciwrappers.h" #include "utils.h" +#include "main.h"
static struct { @@ -910,15 +911,18 @@
void sci_cb_do_uncomment(gint idx) { - gint first_line; - gint last_line; + gint first_line, last_line; gint x, i, line_start, line_len; + gint sel_start, sel_end, co_len; gchar sel[64], *co, *cc; - gboolean break_loop = FALSE; + gboolean break_loop = FALSE, single_line = FALSE; filetype *ft;
if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return;
+ sel_start = sci_get_selection_start(doc_list[idx].sci); + sel_end = sci_get_selection_end(doc_list[idx].sci); + ft = doc_list[idx].file_type;
first_line = sci_get_line_from_position(doc_list[idx].sci, @@ -941,6 +945,8 @@ cc = ft->comment_close; if (co == NULL) return;
+ co_len = strlen(co); + SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0);
for (i = first_line; (i <= last_line) && (! break_loop); i++) @@ -962,9 +968,10 @@ if (cc == NULL || strlen(cc) == 0) { guint i; - guint len = strlen(co);
- switch (len) + single_line = TRUE; + + switch (co_len) { case 1: if (sel[x] != co[0]) continue; break; case 2: if (sel[x] != co[0] || sel[x+1] != co[1]) continue; break; @@ -973,8 +980,8 @@ default: continue; }
- SSM(doc_list[idx].sci, SCI_GOTOPOS, line_start + x + len, 0); - for (i = 0; i < len; i++) SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0); + SSM(doc_list[idx].sci, SCI_GOTOPOS, line_start + x + co_len, 0); + for (i = 0; i < co_len; i++) SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0); } // use multi line comment else @@ -1031,7 +1038,6 @@ len = sci_get_line_length(doc_list[idx].sci, line); linebuf = g_malloc(len + 1); sci_get_line(doc_list[idx].sci, line, linebuf); - geany_debug("%d", line); linebuf[len] = '\0'; x = 0; while (linebuf[x] != '\0' && isspace(linebuf[x])) x++; @@ -1046,20 +1052,36 @@ } } SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0); + + // restore selection + if (single_line) + { + sci_set_selection_start(doc_list[idx].sci, sel_start - co_len); + sci_set_selection_end(doc_list[idx].sci, sel_end - ((i - first_line) * co_len)); + } + else + { + gint eol_len = (sci_get_eol_mode(doc_list[idx].sci) == SC_EOL_CRLF) ? 2 : 1; + sci_set_selection_start(doc_list[idx].sci, sel_start - co_len - eol_len); + sci_set_selection_end(doc_list[idx].sci, sel_end - co_len - eol_len); + } }
void sci_cb_do_comment(gint idx) { - gint first_line; - gint last_line; + gint first_line, last_line; gint x, i, line_start, line_len; + gint sel_start, sel_end, co_len; gchar sel[64], *co, *cc; - gboolean break_loop = FALSE; + gboolean break_loop = FALSE, single_line = FALSE; filetype *ft;
if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return;
+ sel_start = sci_get_selection_start(doc_list[idx].sci); + sel_end = sci_get_selection_end(doc_list[idx].sci); + ft = doc_list[idx].file_type;
first_line = sci_get_line_from_position(doc_list[idx].sci, @@ -1082,6 +1104,8 @@ cc = ft->comment_close; if (co == NULL) return;
+ co_len = strlen(co); + SSM(doc_list[idx].sci, SCI_BEGINUNDOACTION, 0, 0);
for (i = first_line; (i <= last_line) && (! break_loop); i++) @@ -1105,7 +1129,7 @@ /* disabled because of #1521714, it makes sense to double(or triple, ...) comment * if someone think it is not that good we could introduce a config option for it gboolean do_continue = FALSE; - switch (strlen(co)) + switch (co_len) { case 1: if (sel[x] == co[0]) do_continue = TRUE; break; case 2: if (sel[x] == co[0] && sel[x+1] == co[1]) do_continue = TRUE; break; @@ -1115,6 +1139,7 @@ } if (do_continue) continue; */ + single_line = TRUE; if (ft->comment_use_indent) sci_insert_text(doc_list[idx].sci, line_start + x, co); else @@ -1165,6 +1190,20 @@ } } SSM(doc_list[idx].sci, SCI_ENDUNDOACTION, 0, 0); + + // restore selection + if (single_line) + { + sci_set_selection_start(doc_list[idx].sci, sel_start + co_len); + sci_set_selection_end(doc_list[idx].sci, sel_end + ((i - first_line) * co_len)); + } + else + { + gint eol_len = (sci_get_eol_mode(doc_list[idx].sci) == SC_EOL_CRLF) ? 2 : 1; + sci_set_selection_start(doc_list[idx].sci, sel_start + co_len + eol_len); + sci_set_selection_end(doc_list[idx].sci, sel_end + co_len + eol_len); + } + }
Modified: trunk/src/search.c =================================================================== --- trunk/src/search.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/search.c 2006-08-20 15:47:18 UTC (rev 750) @@ -28,6 +28,7 @@ #include "msgwindow.h" #include "document.h" #include "sciwrappers.h" +#include "main.h"
#include <unistd.h> #include <string.h>
Modified: trunk/src/templates.c =================================================================== --- trunk/src/templates.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/templates.c 2006-08-20 15:47:18 UTC (rev 750) @@ -27,6 +27,7 @@ #include "templates.h" #include "support.h" #include "utils.h" +#include "document.h"
// some simple macros to reduce code size and make the code readable #define templates_get_filename(x) g_strconcat(app->configdir, G_DIR_SEPARATOR_S, x, NULL)
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/utils.c 2006-08-20 15:47:18 UTC (rev 750) @@ -49,6 +49,7 @@ #include "sciwrappers.h" #include "dialogs.h" #include "win32.h" +#include "main.h"
#include "utils.h"
Modified: trunk/src/vte.c =================================================================== --- trunk/src/vte.c 2006-08-20 12:33:09 UTC (rev 749) +++ trunk/src/vte.c 2006-08-20 15:47:18 UTC (rev 750) @@ -35,6 +35,7 @@ #include "support.h" #include "utils.h" #include "callbacks.h" +#include "main.h"
VteInfo vte_info; @@ -413,7 +414,7 @@
/* Taken from Terminal by os-cillation: terminal_screen_get_working_directory, thanks. - * Determinies the working directory using various OS-specific mechanisms. */ + * Determines the working directory using various OS-specific mechanisms. */ const gchar* vte_get_working_directory() { gchar buffer[4096 + 1];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.