Пример #1
0
gboolean msgwin_goto_messages_file_line(gboolean focus_editor)
{
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkTreeSelection *selection;
	gboolean ret = FALSE;

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow.tree_msg));
	if (gtk_tree_selection_get_selected(selection, &model, &iter))
	{
		gint line;
		guint id;
		gchar *string;
		GeanyDocument *doc;
		GeanyDocument *old_doc = document_get_current();

		gtk_tree_model_get(model, &iter,
			MSG_COL_LINE, &line, MSG_COL_DOC_ID, &id, MSG_COL_STRING, &string, -1);
		if (line >= 0 && id > 0)
		{
			/* check doc is still open */
			doc = document_find_by_id(id);
			if (!doc)
			{
				ui_set_statusbar(FALSE, _("The document has been closed."));
				utils_beep();
			}
			else
			{
				line = adjust_line_number(doc, line, msgwindow.line_shifts_msg);
				ret = navqueue_goto_line(old_doc, doc, line);
				if (ret && focus_editor)
					gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
			}
		}
		else if (line < 0 && string != NULL)
		{
			gchar *filename;

			/* try with a file:line parsing */
			msgwin_parse_generic_line(string, &filename, &line);
			if (filename != NULL)
			{
				/* use document_open_file to find an already open file, or open it in place */
				doc = document_open_file(filename, FALSE, NULL, NULL);
				if (doc != NULL)
				{
					line = adjust_line_number(doc, line, msgwindow.line_shifts_msg);
					ret = (line < 0) ? TRUE : navqueue_goto_line(old_doc, doc, line);
					if (ret && focus_editor)
						gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
				}
			}
			g_free(filename);
		}
		g_free(string);
	}
	return ret;
}
Пример #2
0
/* name should be in UTF-8, and can have a path. */
static void
show_output(const gchar * std_output, const gchar * name, const gchar * force_encoding,
	    gint filetype_new_file)
{
	gint page;
	GtkNotebook *book;
	GeanyDocument *doc, *cur_doc;

	if (std_output)
	{
		cur_doc = document_get_current();
		doc = document_find_by_filename(name);
		if (doc == NULL)
		{
			doc = document_new_file(name,
						   filetypes[filetype_new_file],
						   std_output);
		}
		else
		{
			sci_set_text(doc->editor->sci, std_output);
			book = GTK_NOTEBOOK(geany->main_widgets->notebook);
			page = gtk_notebook_page_num(book, GTK_WIDGET(doc->editor->sci));
			gtk_notebook_set_current_page(book, page);
		}
		document_set_text_changed(doc, FALSE);
		document_set_encoding(doc, (force_encoding ? force_encoding : "UTF-8"));
		navqueue_goto_line(cur_doc, document_get_current(), 1);
	}
	else
	{
		ui_set_statusbar(FALSE, _("Could not parse the output of command"));
	}
}
Пример #3
0
gboolean msgwin_goto_messages_file_line(gboolean focus_editor)
{
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkTreeSelection *selection;
	gboolean ret = FALSE;

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow.tree_msg));
	if (gtk_tree_selection_get_selected(selection, &model, &iter))
	{
		gint line;
		gchar *string;
		GeanyDocument *doc;
		GeanyDocument *old_doc = document_get_current();

		gtk_tree_model_get(model, &iter, 0, &line, 1, &doc, 3, &string, -1);
		/* doc may have been closed, so check doc->index: */
		if (line >= 0 && DOC_VALID(doc))
		{
			ret = navqueue_goto_line(old_doc, doc, line);
			if (ret && focus_editor)
				gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
		}
		else if (line < 0 && string != NULL)
		{
			gchar *filename;

			/* try with a file:line parsing */
			msgwin_parse_generic_line(string, &filename, &line);
			if (filename != NULL)
			{
				/* use document_open_file to find an already open file, or open it in place */
				doc = document_open_file(filename, FALSE, NULL, NULL);
				if (doc != NULL)
				{
					ret = (line < 0) ? TRUE : navqueue_goto_line(old_doc, doc, line);
					if (ret && focus_editor)
						gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
				}
			}
			g_free(filename);
		}
		g_free(string);
	}
	return ret;
}
Пример #4
0
static gboolean goto_compiler_file_line(const gchar *filename, gint line, gboolean focus_editor)
{
	if (!filename || line <= -1)
		return FALSE;

	/* If the path doesn't exist, try the current document.
	 * This happens when we receive build messages in the wrong order - after the
	 * 'Leaving directory' messages */
	if (!g_file_test(filename, G_FILE_TEST_EXISTS))
	{
		gchar *cur_dir = utils_get_current_file_dir_utf8();
		gchar *name;

		if (cur_dir)
		{
			/* we let the user know we couldn't find the parsed filename from the message window */
			setptr(cur_dir, utils_get_locale_from_utf8(cur_dir));
			name = g_path_get_basename(filename);
			setptr(name, g_build_path(G_DIR_SEPARATOR_S, cur_dir, name, NULL));
			g_free(cur_dir);

			if (g_file_test(name, G_FILE_TEST_EXISTS))
			{
				ui_set_statusbar(FALSE, _("Could not find file '%s' - trying the current document path."),
					filename);
				filename = name;
			}
			else
				g_free(name);
		}
	}

	{
		gchar *utf8_filename = utils_get_utf8_from_locale(filename);
		GeanyDocument *doc = document_find_by_filename(utf8_filename);
		GeanyDocument *old_doc = document_get_current();

		g_free(utf8_filename);

		if (doc == NULL)	/* file not already open */
			doc = document_open_file(filename, FALSE, NULL, NULL);

		if (doc != NULL)
		{
			gboolean ret;

			if (! doc->changed && editor_prefs.use_indicators)	/* if modified, line may be wrong */
				editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1);

			ret = navqueue_goto_line(old_doc, doc, line);
			if (ret && focus_editor)
				gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));

			return ret;
		}
	}
	return FALSE;
}
Пример #5
0
static PyObject *
Navqueue_goto_line(PyObject *module, PyObject *args, PyObject *kwargs)
{
	gint line = 1;
	PyObject *py_old = NULL, *py_new = NULL;
	Document *py_doc_old, *py_doc_new;
	GeanyDocument *old_doc, *new_doc;
	static gchar *kwlist[] = { "old_doc", "new_doc", "line", NULL };

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "OOi", kwlist, &py_old,
		&py_new, &line))
	{
		if (!py_old || py_old == Py_None)
			old_doc = NULL;
		else
		{
			py_doc_old = (Document *) py_old;
			old_doc = py_doc_old->doc;
		}

		if (!py_new || py_new == Py_None)
			Py_RETURN_NONE;
		else
		{
			py_doc_new = (Document *) py_new;
			new_doc = py_doc_new->doc;
		}

		if ( (old_doc != NULL && !DOC_VALID(old_doc)) || !DOC_VALID(new_doc) )
			Py_RETURN_NONE;
		if (navqueue_goto_line(old_doc, new_doc, line))
			Py_RETURN_TRUE;
		else
			Py_RETURN_FALSE;
	}

	Py_RETURN_NONE;
}
Пример #6
0
static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type)
{
	tagFile *tf;
	GeanyProject *prj;
	gchar *tag_filename = NULL;
	tagEntry entry;
	tagFileInfo info;

	prj = geany_data->app->project;
	if (!prj)
		return;

	msgwin_clear_tab(MSG_MESSAGE);
	msgwin_set_messages_dir(prj->base_path);

	tag_filename = get_tags_filename();
	tf = tagsOpen(tag_filename, &info);

	if (tf)
	{
		if (find_first(tf, &entry, name, match_type))
		{
			GPatternSpec *name_pat;
			gchar *name_case;
			gchar *path = NULL; 
			gint num = 0;

			if (case_sensitive)
				name_case = g_strdup(name);
			else
				name_case = g_utf8_strdown(name, -1);

			SETPTR(name_case, g_strconcat("*", name_case, "*", NULL));
			name_pat = g_pattern_spec_new(name_case);

			if (!filter_tag(&entry, name_pat, declaration, case_sensitive))
			{
				path = g_build_filename(prj->base_path, entry.file, NULL);
				show_entry(&entry);
				num++;
			}
			
			while (find_next(tf, &entry, match_type))
			{
				if (!filter_tag(&entry, name_pat, declaration, case_sensitive))
				{
					if (!path)
						path = g_build_filename(prj->base_path, entry.file, NULL);
					show_entry(&entry);
					num++;
				}
			}
			
			if (num == 1)
			{
				GeanyDocument *doc = document_open_file(path, FALSE, NULL, NULL);
				if (doc != NULL)
				{
					navqueue_goto_line(document_get_current(), doc, entry.address.lineNumber);
					gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
				}
			}

			g_pattern_spec_free(name_pat);
			g_free(name_case);
			g_free(path);
		}

		tagsClose(tf);
	}

	msgwin_switch_tab(MSG_MESSAGE, TRUE);

	g_free(tag_filename);
}