SF.net SVN: geany: [2172] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Jan 14 17:31:00 UTC 2008


Revision: 2172
          http://geany.svn.sourceforge.net/geany/?rev=2172&view=rev
Author:   ntrel
Date:     2008-01-14 09:30:59 -0800 (Mon, 14 Jan 2008)

Log Message:
-----------
Make 'Open Selected File' first try the current file's directory,
falling back to the project base path if no file was found.
Add editor_get_default_selection() from get_default_text() in
search.c, to get the current selection or current word.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/editor.c
    trunk/src/editor.h
    trunk/src/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-01-13 17:50:04 UTC (rev 2171)
+++ trunk/ChangeLog	2008-01-14 17:30:59 UTC (rev 2172)
@@ -1,3 +1,12 @@
+2008-01-14  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/callbacks.c, src/search.c, src/editor.c, src/editor.h:
+   Make 'Open Selected File' first try the current file's directory,
+   falling back to the project base path if no file was found.
+   Add editor_get_default_selection() from get_default_text() in
+   search.c, to get the current selection or current word.
+
+
 2008-01-13  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/keyfile.c, src/project.c:

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2008-01-13 17:50:04 UTC (rev 2171)
+++ trunk/src/callbacks.c	2008-01-14 17:30:59 UTC (rev 2172)
@@ -1889,43 +1889,32 @@
                                         gpointer         user_data)
 {
 	gint idx = document_get_cur_idx();
-	gchar *filename = NULL;
+	gchar *sel = NULL;
 
-	if (idx == -1 || ! doc_list[idx].is_valid) return;
+	if (! DOC_IDX_VALID(idx)) return;
 
-	if (sci_get_lines_selected(doc_list[idx].sci) == 1)
-	{
-		gint len = sci_get_selected_text_length(doc_list[idx].sci);
+	sel = editor_get_default_selection(idx, GEANY_WORDCHARS"./");
 
-		filename = g_malloc(len + 1);
-		sci_get_selected_text(doc_list[idx].sci, filename);
-	}
-	else if (sci_get_lines_selected(doc_list[idx].sci) == 0)
-	{	// use the word at current cursor position
-		gchar word[GEANY_MAX_WORD_LENGTH];
-
-		editor_find_current_word(doc_list[idx].sci, -1, word, sizeof(word), GEANY_WORDCHARS"./");
-		if (word[0] != '\0')
-			filename = g_strdup(word);
-	}
-
-	if (filename != NULL)
+	if (sel != NULL)
 	{
-		gchar *locale_filename;
+		gchar *locale_filename, *filename;
 
-		if (! g_path_is_absolute(filename))
+		if (g_path_is_absolute(sel))
+			filename = g_strdup(sel);
+		else
 		{	// relative filename, add the path of the current file
 			gchar *path;
-			gchar *tmp = filename;
 
-			// use the projects base path if we have an open project (useful?)
-			if (app->project != NULL && app->project->base_path != NULL)
-				path = g_strdup(app->project->base_path);
-			else
-				path = g_path_get_dirname(doc_list[idx].file_name);
+			path = g_path_get_dirname(doc_list[idx].file_name);
+			filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL);
 
-			filename = g_strconcat(path, G_DIR_SEPARATOR_S, filename, NULL);
-			g_free(tmp);
+			if (! g_file_test(filename, G_FILE_TEST_EXISTS) &&
+				app->project != NULL && NZV(app->project->base_path))
+			{
+				// try the project's base path
+				setptr(path, project_get_base_path());
+				setptr(filename, g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL));
+			}
 			g_free(path);
 		}
 
@@ -1934,6 +1923,7 @@
 
 		g_free(filename);
 		g_free(locale_filename);
+		g_free(sel);
 	}
 }
 

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2008-01-13 17:50:04 UTC (rev 2171)
+++ trunk/src/editor.c	2008-01-14 17:30:59 UTC (rev 2172)
@@ -2592,3 +2592,30 @@
 
 	scintilla_release_resources();
 }
+
+
+/* wordchars: NULL or a string containing characters to match a word.
+ * Returns: the current selection or the current word. */
+gchar *editor_get_default_selection(gint idx, const gchar *wordchars)
+{
+	gchar *s = NULL;
+
+	g_return_val_if_fail(DOC_IDX_VALID(idx), NULL);
+
+	if (sci_get_lines_selected(doc_list[idx].sci) == 1)
+	{
+		gint len = sci_get_selected_text_length(doc_list[idx].sci);
+
+		s = g_malloc(len + 1);
+		sci_get_selected_text(doc_list[idx].sci, s);
+	}
+	else if (sci_get_lines_selected(doc_list[idx].sci) == 0)
+	{	// use the word at current cursor position
+		gchar word[GEANY_MAX_WORD_LENGTH];
+
+		editor_find_current_word(doc_list[idx].sci, -1, word, sizeof(word), wordchars);
+		if (word[0] != '\0')
+			s = g_strdup(word);
+	}
+	return s;
+}

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2008-01-13 17:50:04 UTC (rev 2171)
+++ trunk/src/editor.h	2008-01-14 17:30:59 UTC (rev 2172)
@@ -108,9 +108,6 @@
 
 void editor_show_macro_list(ScintillaObject *sci);
 
-void editor_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen,
-	const gchar *wc);
-
 gboolean editor_show_calltip(gint idx, gint pos);
 
 void editor_do_comment_toggle(gint idx);
@@ -127,12 +124,6 @@
 
 void editor_insert_multiline_comment(gint idx);
 
-void editor_select_word(ScintillaObject *sci);
-
-void editor_select_lines(ScintillaObject *sci, gboolean extra_line);
-
-void editor_select_paragraph(ScintillaObject *sci);
-
 void editor_insert_alternative_whitespace(gint idx);
 
 void editor_auto_line_indentation(gint idx, gint pos);
@@ -143,4 +134,18 @@
 
 void editor_finalize();
 
+
+/* General editing functions */
+
+void editor_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen,
+	const gchar *wc);
+
+gchar *editor_get_default_selection(gint idx, const gchar *wordchars);
+
+void editor_select_word(ScintillaObject *sci);
+
+void editor_select_lines(ScintillaObject *sci, gboolean extra_line);
+
+void editor_select_paragraph(ScintillaObject *sci);
+
 #endif

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2008-01-13 17:50:04 UTC (rev 2171)
+++ trunk/src/search.c	2008-01-14 17:30:59 UTC (rev 2172)
@@ -208,28 +208,6 @@
 }
 
 
-static gchar *get_default_text(gint idx)
-{
-	gchar *s = NULL;
-
-	if (sci_get_lines_selected(doc_list[idx].sci) == 1)
-	{
-		gint len = sci_get_selected_text_length(doc_list[idx].sci);
-
-		s = g_malloc(len + 1);
-		sci_get_selected_text(doc_list[idx].sci, s);
-	}
-	else if (sci_get_lines_selected(doc_list[idx].sci) == 0)
-	{	// use the word at current cursor position
-		gchar word[GEANY_MAX_WORD_LENGTH];
-
-		editor_find_current_word(doc_list[idx].sci, -1, word, sizeof(word), NULL);
-		if (word[0] != '\0') s = g_strdup(word);
-	}
-	return s;
-}
-
-
 // store text, clear search flags so we can use Search->Find Next/Previous
 static void setup_find_next(const gchar *text)
 {
@@ -269,7 +247,7 @@
 	}
 #endif
 
-	if (!s)	{ s=get_default_text(idx); }
+	if (!s)	{ s=editor_get_default_selection(idx, NULL); }
 	if (s)
 	{
 		setup_find_next(s);	// allow find next/prev
@@ -286,7 +264,7 @@
 
 	g_return_if_fail(DOC_IDX_VALID(idx));
 
-	sel = get_default_text(idx);
+	sel = editor_get_default_selection(idx, NULL);
 
 	if (widgets.find_dialog == NULL)
 	{
@@ -405,7 +383,7 @@
 
 	if (idx == -1 || ! doc_list[idx].is_valid) return;
 
-	sel = get_default_text(idx);
+	sel = editor_get_default_selection(idx, NULL);
 
 	if (widgets.replace_dialog == NULL)
 	{
@@ -702,13 +680,13 @@
 				G_CALLBACK(gtk_widget_hide_on_delete), NULL);
 
 		gtk_widget_show_all(widgets.find_in_files_dialog);
-		sel = get_default_text(idx);
+		sel = editor_get_default_selection(idx, NULL);
 	}
 
 	entry = GTK_BIN(combo)->child;
 	// only set selection if the dialog is not already visible, or has just been created
 	if (! sel && ! GTK_WIDGET_VISIBLE(widgets.find_in_files_dialog))
-		sel = get_default_text(idx);
+		sel = editor_get_default_selection(idx, NULL);
 	if (sel)
 		gtk_entry_set_text(GTK_ENTRY(entry), sel);
 	g_free(sel);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list