Use document pointer instead of an index to the documents array everywhere in the core code.
Pass a document pointer to the callbacks of all "document-*" signals. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/document-pointer@2692 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
45af150af0
commit
d3439f8a17
@ -1,3 +1,11 @@
|
||||
2008-06-15 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* src/*:
|
||||
Use document pointer instead of an index to the documents array
|
||||
everywhere in the core code.
|
||||
Pass a document pointer to the callbacks of all "document-*" signals.
|
||||
|
||||
|
||||
2008-06-13 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* src/msgwindow.c:
|
||||
|
209
src/build.c
209
src/build.c
@ -45,10 +45,10 @@
|
||||
|
||||
#include "prefs.h"
|
||||
#include "support.h"
|
||||
#include "document.h"
|
||||
#include "utils.h"
|
||||
#include "ui_utils.h"
|
||||
#include "dialogs.h"
|
||||
#include "document.h"
|
||||
#include "msgwindow.h"
|
||||
#include "filetypes.h"
|
||||
#include "keybindings.h"
|
||||
@ -98,7 +98,7 @@ widgets;
|
||||
|
||||
static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data);
|
||||
static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose);
|
||||
static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir);
|
||||
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir);
|
||||
static void set_stop_button(gboolean stop);
|
||||
static void build_exit_cb(GPid child_pid, gint status, gpointer user_data);
|
||||
static void run_exit_cb(GPid child_pid, gint status, gpointer user_data);
|
||||
@ -125,28 +125,29 @@ void build_finalize()
|
||||
}
|
||||
|
||||
|
||||
static GPid build_compile_tex_file(gint idx, gint mode)
|
||||
static GPid build_compile_tex_file(GeanyDocument *doc, gint mode)
|
||||
{
|
||||
const gchar *cmd = NULL;
|
||||
|
||||
if (idx < 0 || documents[idx]->file_name == NULL) return (GPid) 1;
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 1;
|
||||
|
||||
if (mode == LATEX_CMD_TO_DVI)
|
||||
{
|
||||
cmd = documents[idx]->file_type->programs->compiler;
|
||||
cmd = doc->file_type->programs->compiler;
|
||||
build_info.type = GBO_COMPILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = documents[idx]->file_type->programs->linker;
|
||||
cmd = doc->file_type->programs->linker;
|
||||
build_info.type = GBO_BUILD;
|
||||
}
|
||||
|
||||
return build_spawn_cmd(idx, cmd, NULL);
|
||||
return build_spawn_cmd(doc, cmd, NULL);
|
||||
}
|
||||
|
||||
|
||||
static GPid build_view_tex_file(gint idx, gint mode)
|
||||
static GPid build_view_tex_file(GeanyDocument *doc, gint mode)
|
||||
{
|
||||
gchar **argv, **term_argv;
|
||||
gchar *executable = NULL;
|
||||
@ -161,12 +162,12 @@ static GPid build_view_tex_file(gint idx, gint mode)
|
||||
GError *error = NULL;
|
||||
struct stat st;
|
||||
|
||||
if (! DOC_IDX_VALID(idx) || documents[idx]->file_name == NULL)
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 1;
|
||||
|
||||
run_info.file_type_id = GEANY_FILETYPES_LATEX;
|
||||
|
||||
executable = utils_remove_ext_from_filename(documents[idx]->file_name);
|
||||
executable = utils_remove_ext_from_filename(doc->file_name);
|
||||
view_file = g_strconcat(executable, (mode == LATEX_CMD_VIEW_DVI) ? ".dvi" : ".pdf", NULL);
|
||||
|
||||
/* try convert in locale for stat() */
|
||||
@ -183,8 +184,8 @@ static GPid build_view_tex_file(gint idx, gint mode)
|
||||
|
||||
/* replace %f and %e in the run_cmd string */
|
||||
cmd_string = g_strdup((mode == LATEX_CMD_VIEW_DVI) ?
|
||||
g_strdup(documents[idx]->file_type->programs->run_cmd) :
|
||||
g_strdup(documents[idx]->file_type->programs->run_cmd2));
|
||||
g_strdup(doc->file_type->programs->run_cmd) :
|
||||
g_strdup(doc->file_type->programs->run_cmd2));
|
||||
cmd_string = utils_str_replace(cmd_string, "%f", view_file);
|
||||
cmd_string = utils_str_replace(cmd_string, "%e", executable);
|
||||
|
||||
@ -275,7 +276,7 @@ static GPid build_view_tex_file(gint idx, gint mode)
|
||||
{
|
||||
/*setpgid(0, getppid());*/
|
||||
g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL);
|
||||
build_menu_update(idx);
|
||||
build_menu_update(doc);
|
||||
}
|
||||
|
||||
utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string,
|
||||
@ -288,13 +289,13 @@ static GPid build_view_tex_file(gint idx, gint mode)
|
||||
|
||||
|
||||
/* get curfile.o in locale encoding from document::file_name */
|
||||
static gchar *get_object_filename(gint idx)
|
||||
static gchar *get_object_filename(GeanyDocument *doc)
|
||||
{
|
||||
gchar *locale_filename, *short_file, *noext, *object_file;
|
||||
|
||||
if (documents[idx]->file_name == NULL) return NULL;
|
||||
if (doc->file_name == NULL) return NULL;
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
|
||||
short_file = g_path_get_basename(locale_filename);
|
||||
g_free(locale_filename);
|
||||
@ -309,13 +310,14 @@ static gchar *get_object_filename(gint idx)
|
||||
}
|
||||
|
||||
|
||||
static GPid build_make_file(gint idx, gint build_opts)
|
||||
static GPid build_make_file(GeanyDocument *doc, gint build_opts)
|
||||
{
|
||||
GString *cmdstr;
|
||||
gchar *dir = NULL;
|
||||
GPid pid;
|
||||
|
||||
if (idx < 0 || documents[idx]->file_name == NULL) return (GPid) 1;
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 1;
|
||||
|
||||
cmdstr = g_string_new(tool_prefs.make_cmd);
|
||||
g_string_append_c(cmdstr, ' ');
|
||||
@ -325,7 +327,7 @@ static GPid build_make_file(gint idx, gint build_opts)
|
||||
gchar *tmp;
|
||||
|
||||
build_info.type = build_opts;
|
||||
tmp = get_object_filename(idx);
|
||||
tmp = get_object_filename(doc);
|
||||
g_string_append(cmdstr, tmp);
|
||||
g_free(tmp);
|
||||
}
|
||||
@ -342,42 +344,42 @@ static GPid build_make_file(gint idx, gint build_opts)
|
||||
dir = project_get_make_dir();
|
||||
}
|
||||
|
||||
pid = build_spawn_cmd(idx, cmdstr->str, dir); /* if dir is NULL, idx filename is used */
|
||||
pid = build_spawn_cmd(doc, cmdstr->str, dir); /* if dir is NULL, idx filename is used */
|
||||
g_free(dir);
|
||||
g_string_free(cmdstr, TRUE);
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
static GPid build_compile_file(gint idx)
|
||||
static GPid build_compile_file(GeanyDocument *doc)
|
||||
{
|
||||
if (! DOC_IDX_VALID(idx) || documents[idx]->file_name == NULL)
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 1;
|
||||
|
||||
build_info.type = GBO_COMPILE;
|
||||
return build_spawn_cmd(idx, documents[idx]->file_type->programs->compiler, NULL);
|
||||
return build_spawn_cmd(doc, doc->file_type->programs->compiler, NULL);
|
||||
}
|
||||
|
||||
|
||||
static GPid build_link_file(gint idx)
|
||||
static GPid build_link_file(GeanyDocument *doc)
|
||||
{
|
||||
if (! DOC_IDX_VALID(idx) || documents[idx]->file_name == NULL)
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 1;
|
||||
|
||||
build_info.type = GBO_BUILD;
|
||||
return build_spawn_cmd(idx, documents[idx]->file_type->programs->linker, NULL);
|
||||
return build_spawn_cmd(doc, doc->file_type->programs->linker, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* If linking, clear all error indicators in all documents.
|
||||
* Otherwise, just clear error indicators in document idx. */
|
||||
static void clear_errors(gint idx)
|
||||
static void clear_errors(GeanyDocument *doc)
|
||||
{
|
||||
switch (build_info.type)
|
||||
{
|
||||
case GBO_COMPILE:
|
||||
case GBO_MAKE_OBJECT:
|
||||
editor_clear_indicators(idx);
|
||||
editor_clear_indicators(doc);
|
||||
break;
|
||||
|
||||
case GBO_BUILD:
|
||||
@ -389,7 +391,7 @@ static void clear_errors(gint idx)
|
||||
for (i = 0; i < documents_array->len; i++)
|
||||
{
|
||||
if (documents[i]->is_valid)
|
||||
editor_clear_indicators(i);
|
||||
editor_clear_indicators(documents[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -422,7 +424,7 @@ static gchar *quote_executable(const gchar *cmd)
|
||||
|
||||
/* dir is the UTF-8 working directory to run cmd in. It can be NULL to use the
|
||||
* idx document directory */
|
||||
static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
|
||||
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar **argv;
|
||||
@ -436,12 +438,12 @@ static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
|
||||
gint stdout_fd;
|
||||
gint stderr_fd;
|
||||
|
||||
g_return_val_if_fail(DOC_IDX_VALID(idx), (GPid) 1);
|
||||
g_return_val_if_fail(doc != NULL, (GPid) 1);
|
||||
|
||||
clear_errors(idx);
|
||||
clear_errors(doc);
|
||||
setptr(current_dir_entered, NULL);
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
executable = utils_remove_ext_from_filename(locale_filename);
|
||||
|
||||
cmd_string = g_strdup(cmd);
|
||||
@ -472,7 +474,7 @@ static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
|
||||
|
||||
utf8_cmd_string = utils_get_utf8_from_locale(cmd_string);
|
||||
utf8_working_dir = (dir != NULL) ? g_strdup(dir) :
|
||||
g_path_get_dirname(documents[idx]->file_name);
|
||||
g_path_get_dirname(doc->file_name);
|
||||
working_dir = utils_get_locale_from_utf8(utf8_working_dir);
|
||||
|
||||
gtk_list_store_clear(msgwindow.store_compiler);
|
||||
@ -484,7 +486,7 @@ static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
|
||||
/* set the build info for the message window */
|
||||
g_free(build_info.dir);
|
||||
build_info.dir = g_strdup(working_dir);
|
||||
build_info.file_type_id = FILETYPE_ID(documents[idx]->file_type);
|
||||
build_info.file_type_id = FILETYPE_ID(doc->file_type);
|
||||
|
||||
if (! g_spawn_async_with_pipes(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
NULL, NULL, &(build_info.pid), NULL, &stdout_fd, &stderr_fd, &error))
|
||||
@ -502,7 +504,7 @@ static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir)
|
||||
if (build_info.pid > 0)
|
||||
{
|
||||
g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL);
|
||||
build_menu_update(idx);
|
||||
build_menu_update(doc);
|
||||
}
|
||||
|
||||
/* use GIOChannels to monitor stdout and stderr */
|
||||
@ -586,12 +588,12 @@ static gchar *get_build_executable(const gchar *locale_filename, gboolean check_
|
||||
/* Returns: NULL if there was an error, or the working directory the script was created in.
|
||||
* vte_cmd_nonscript is the location of a string which is filled with the command to be used
|
||||
* when vc->skip_run_script is set, otherwise it will be set to NULL */
|
||||
static gchar *prepare_run_script(gint idx, gchar **vte_cmd_nonscript)
|
||||
static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript)
|
||||
{
|
||||
gchar *locale_filename = NULL;
|
||||
gboolean have_project;
|
||||
GeanyProject *project = app->project;
|
||||
GeanyFiletype *ft = documents[idx]->file_type;
|
||||
GeanyFiletype *ft = doc->file_type;
|
||||
gboolean check_exists;
|
||||
gchar *cmd = NULL;
|
||||
gchar *executable = NULL;
|
||||
@ -603,7 +605,7 @@ static gchar *prepare_run_script(gint idx, gchar **vte_cmd_nonscript)
|
||||
if (vte_cmd_nonscript != NULL)
|
||||
*vte_cmd_nonscript = NULL;
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
|
||||
have_project = (project != NULL && NZV(project->run_cmd));
|
||||
cmd = (have_project) ?
|
||||
@ -688,22 +690,22 @@ static gchar *prepare_run_script(gint idx, gchar **vte_cmd_nonscript)
|
||||
}
|
||||
|
||||
|
||||
static GPid build_run_cmd(gint idx)
|
||||
static GPid build_run_cmd(GeanyDocument *doc)
|
||||
{
|
||||
gchar *working_dir;
|
||||
gchar *vte_cmd_nonscript = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (! DOC_IDX_VALID(idx) || documents[idx]->file_name == NULL)
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
return (GPid) 0;
|
||||
|
||||
working_dir = prepare_run_script(idx, &vte_cmd_nonscript);
|
||||
working_dir = prepare_run_script(doc, &vte_cmd_nonscript);
|
||||
if (working_dir == NULL)
|
||||
{
|
||||
return (GPid) 0;
|
||||
}
|
||||
|
||||
run_info.file_type_id = FILETYPE_ID(documents[idx]->file_type);
|
||||
run_info.file_type_id = FILETYPE_ID(doc->file_type);
|
||||
|
||||
#ifdef HAVE_VTE
|
||||
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
|
||||
@ -810,7 +812,7 @@ static GPid build_run_cmd(gint idx)
|
||||
if (run_info.pid > 0)
|
||||
{
|
||||
g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL);
|
||||
build_menu_update(idx);
|
||||
build_menu_update(doc);
|
||||
}
|
||||
free_strings:
|
||||
g_strfreev(argv);
|
||||
@ -853,9 +855,9 @@ static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data)
|
||||
&filename, &line);
|
||||
if (line != -1 && filename != NULL)
|
||||
{
|
||||
gint idx = document_find_by_filename(filename);
|
||||
GeanyDocument *doc = document_find_by_filename(filename);
|
||||
|
||||
editor_set_indicator_on_line(idx, line - 1); /* will check valid idx */
|
||||
editor_set_indicator_on_line(doc, line - 1); /* will check valid idx */
|
||||
color = COLOR_RED; /* error message parsed on the line */
|
||||
}
|
||||
g_free(filename);
|
||||
@ -965,7 +967,7 @@ static void build_exit_cb(GPid child_pid, gint status, gpointer user_data)
|
||||
|
||||
build_info.pid = 0;
|
||||
/* enable build items again */
|
||||
build_menu_update(-1);
|
||||
build_menu_update(NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -975,7 +977,7 @@ static void run_exit_cb(GPid child_pid, gint status, gpointer user_data)
|
||||
|
||||
run_info.pid = 0;
|
||||
/* reset the stop button and menu item to the original meaning */
|
||||
build_menu_update(-1);
|
||||
build_menu_update(NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -1323,11 +1325,12 @@ on_includes_arguments_tex_dialog_response (GtkDialog *dialog,
|
||||
static void show_includes_arguments_tex(void)
|
||||
{
|
||||
GtkWidget *dialog, *label, *entries[4], *vbox, *table;
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gint response;
|
||||
GeanyFiletype *ft = NULL;
|
||||
|
||||
if (DOC_IDX_VALID(idx)) ft = documents[idx]->file_type;
|
||||
if (doc != NULL)
|
||||
ft = doc->file_type;
|
||||
g_return_if_fail(ft != NULL);
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons(_("Set Arguments"), GTK_WINDOW(main_widgets.window),
|
||||
@ -1492,11 +1495,12 @@ static void show_includes_arguments_gen(void)
|
||||
GtkWidget *dialog, *label, *entries[3], *vbox;
|
||||
GtkWidget *ft_table = NULL;
|
||||
gint row = 0;
|
||||
gint idx = document_get_cur_idx();
|
||||
gint response;
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GeanyFiletype *ft = NULL;
|
||||
|
||||
if (DOC_IDX_VALID(idx)) ft = documents[idx]->file_type;
|
||||
if (doc != NULL)
|
||||
ft = doc->file_type;
|
||||
g_return_if_fail(ft != NULL);
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons(_("Set Includes and Arguments"), GTK_WINDOW(main_widgets.window),
|
||||
@ -1633,17 +1637,16 @@ static gboolean is_c_header(const gchar *fname)
|
||||
|
||||
/* Call this whenever build menu items need to be enabled/disabled.
|
||||
* Uses current document (if there is one) when idx == -1 */
|
||||
void build_menu_update(gint idx)
|
||||
void build_menu_update(GeanyDocument *doc)
|
||||
{
|
||||
GeanyFiletype *ft;
|
||||
gboolean have_path, can_build, can_make, can_run, can_stop, can_set_args, have_errors;
|
||||
BuildMenuItems *menu_items;
|
||||
|
||||
if (idx == -1)
|
||||
idx = document_get_cur_idx();
|
||||
if (idx == -1 ||
|
||||
(FILETYPE_ID(documents[idx]->file_type) == GEANY_FILETYPES_NONE &&
|
||||
documents[idx]->file_name == NULL))
|
||||
if (doc == NULL)
|
||||
doc = document_get_current();
|
||||
if (doc == NULL ||
|
||||
(FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_NONE && doc->file_name == NULL))
|
||||
{
|
||||
gtk_widget_set_sensitive(lookup_widget(main_widgets.window, "menu_build1"), FALSE);
|
||||
gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(main_widgets.window, "menu_build1")));
|
||||
@ -1654,7 +1657,7 @@ void build_menu_update(gint idx)
|
||||
else
|
||||
gtk_widget_set_sensitive(lookup_widget(main_widgets.window, "menu_build1"), TRUE);
|
||||
|
||||
ft = documents[idx]->file_type;
|
||||
ft = doc->file_type;
|
||||
g_return_if_fail(ft != NULL);
|
||||
|
||||
menu_items = build_get_menu_items(ft->id);
|
||||
@ -1663,13 +1666,13 @@ void build_menu_update(gint idx)
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(main_widgets.window, "menu_build1")),
|
||||
menu_items->menu);
|
||||
|
||||
have_path = (documents[idx]->file_name != NULL);
|
||||
have_path = (doc->file_name != NULL);
|
||||
|
||||
can_make = have_path && build_info.pid <= (GPid) 1;
|
||||
|
||||
/* disable compile and link for C/C++ header files */
|
||||
if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP)
|
||||
can_build = can_make && ! is_c_header(documents[idx]->file_name);
|
||||
can_build = can_make && ! is_c_header(doc->file_name);
|
||||
else
|
||||
can_build = can_make;
|
||||
|
||||
@ -1783,11 +1786,11 @@ BuildMenuItems *build_get_menu_items(gint filetype_idx)
|
||||
|
||||
if (filetype_idx == -1)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GeanyFiletype *ft = NULL;
|
||||
|
||||
if (DOC_IDX_VALID(idx))
|
||||
ft = documents[idx]->file_type;
|
||||
if (doc != NULL)
|
||||
ft = doc->file_type;
|
||||
filetype_idx = FILETYPE_ID(ft);
|
||||
}
|
||||
|
||||
@ -1811,16 +1814,18 @@ static void
|
||||
on_build_compile_activate (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
if (documents[idx]->changed) document_save_file(idx, FALSE);
|
||||
if (doc->changed)
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
if (FILETYPE_ID(documents[idx]->file_type) == GEANY_FILETYPES_LATEX)
|
||||
build_compile_tex_file(idx, 0);
|
||||
if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_LATEX)
|
||||
build_compile_tex_file(doc, 0);
|
||||
else
|
||||
build_compile_file(idx);
|
||||
build_compile_file(doc);
|
||||
}
|
||||
|
||||
|
||||
@ -1828,21 +1833,22 @@ static void
|
||||
on_build_tex_activate (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
if (documents[idx]->changed) document_save_file(idx, FALSE);
|
||||
if (doc->changed)
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
switch (GPOINTER_TO_INT(user_data))
|
||||
{
|
||||
case LATEX_CMD_TO_DVI:
|
||||
case LATEX_CMD_TO_PDF:
|
||||
build_compile_tex_file(idx, GPOINTER_TO_INT(user_data)); break;
|
||||
build_compile_tex_file(doc, GPOINTER_TO_INT(user_data)); break;
|
||||
case LATEX_CMD_VIEW_DVI:
|
||||
case LATEX_CMD_VIEW_PDF:
|
||||
build_view_tex_file(idx, GPOINTER_TO_INT(user_data)); break;
|
||||
build_view_tex_file(doc, GPOINTER_TO_INT(user_data)); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1851,30 +1857,32 @@ static void
|
||||
on_build_build_activate (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
if (documents[idx]->changed) document_save_file(idx, FALSE);
|
||||
if (doc->changed)
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
if (FILETYPE_ID(documents[idx]->file_type) == GEANY_FILETYPES_LATEX)
|
||||
build_compile_tex_file(idx, 1);
|
||||
if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_LATEX)
|
||||
build_compile_tex_file(doc, 1);
|
||||
else
|
||||
build_link_file(idx);
|
||||
build_link_file(doc);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_make_custom_input_response(const gchar *input)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (documents[idx]->changed)
|
||||
document_save_file(idx, FALSE);
|
||||
if (doc->changed)
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
setptr(build_info.custom_target, g_strdup(input));
|
||||
|
||||
build_make_file(idx, GBO_MAKE_CUSTOM);
|
||||
build_make_file(doc, GBO_MAKE_CUSTOM);
|
||||
}
|
||||
|
||||
|
||||
@ -1898,10 +1906,10 @@ static void
|
||||
on_build_make_activate (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gint build_opts = GPOINTER_TO_INT(user_data);
|
||||
|
||||
g_return_if_fail(DOC_IDX_VALID(idx) && documents[idx]->file_name != NULL);
|
||||
g_return_if_fail(doc != NULL && doc->file_name != NULL);
|
||||
|
||||
switch (build_opts)
|
||||
{
|
||||
@ -1915,15 +1923,16 @@ on_build_make_activate (GtkMenuItem *menuitem,
|
||||
/* fall through */
|
||||
case GBO_MAKE_ALL:
|
||||
{
|
||||
if (documents[idx]->changed) document_save_file(idx, FALSE);
|
||||
if (doc->changed)
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
build_make_file(idx, build_opts);
|
||||
build_make_file(doc, build_opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean use_html_builtin(gint idx, GeanyFiletype *ft)
|
||||
static gboolean use_html_builtin(GeanyDocument *doc, GeanyFiletype *ft)
|
||||
{
|
||||
gboolean use_builtin = FALSE;
|
||||
if (ft->id == GEANY_FILETYPES_HTML)
|
||||
@ -1941,7 +1950,7 @@ static gboolean use_html_builtin(gint idx, GeanyFiletype *ft)
|
||||
|
||||
if (use_builtin)
|
||||
{
|
||||
gchar *uri = g_strconcat("file:///", g_path_skip_root(documents[idx]->file_name), NULL);
|
||||
gchar *uri = g_strconcat("file:///", g_path_skip_root(doc->file_name), NULL);
|
||||
utils_start_browser(uri);
|
||||
g_free(uri);
|
||||
|
||||
@ -1955,11 +1964,11 @@ static void
|
||||
on_build_execute_activate (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
filetype_id ft_id;
|
||||
GeanyFiletype *ft;
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
/* make the process "stopable" */
|
||||
@ -1969,26 +1978,26 @@ on_build_execute_activate (GtkMenuItem *menuitem,
|
||||
return;
|
||||
}
|
||||
|
||||
ft_id = FILETYPE_ID(documents[idx]->file_type);
|
||||
ft_id = FILETYPE_ID(doc->file_type);
|
||||
ft = filetypes[ft_id];
|
||||
if (ft_id == GEANY_FILETYPES_LATEX)
|
||||
{ /* run LaTeX file */
|
||||
if (build_view_tex_file(idx, GPOINTER_TO_INT(user_data)) == (GPid) 0)
|
||||
if (build_view_tex_file(doc, GPOINTER_TO_INT(user_data)) == (GPid) 0)
|
||||
{
|
||||
ui_set_statusbar(TRUE, _("Failed to execute the view program"));
|
||||
}
|
||||
}
|
||||
/* use_html_builtin() checks for HTML builtin request and returns FALSE if not */
|
||||
else if (! use_html_builtin(idx, ft))
|
||||
else if (! use_html_builtin(doc, ft))
|
||||
{ /* run everything else */
|
||||
|
||||
/* save the file only if the run command uses it */
|
||||
if (documents[idx]->changed &&
|
||||
if (doc->changed &&
|
||||
NZV(ft->programs->run_cmd) && /* can happen when project is open */
|
||||
strstr(ft->programs->run_cmd, "%f") != NULL)
|
||||
document_save_file(idx, FALSE);
|
||||
document_save_file(doc, FALSE);
|
||||
|
||||
if (build_run_cmd(idx) == (GPid) 0)
|
||||
if (build_run_cmd(doc) == (GPid) 0)
|
||||
{
|
||||
ui_set_statusbar(TRUE, _("Failed to execute the terminal program"));
|
||||
}
|
||||
@ -2020,7 +2029,7 @@ static void kill_process(GPid *pid)
|
||||
else
|
||||
{
|
||||
*pid = 0;
|
||||
build_menu_update(-1);
|
||||
build_menu_update(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ void build_finalize(void);
|
||||
|
||||
gboolean build_parse_make_dir(const gchar *string, gchar **prefix);
|
||||
|
||||
void build_menu_update(gint idx);
|
||||
void build_menu_update(GeanyDocument *doc);
|
||||
|
||||
BuildMenuItems *build_get_menu_items(gint filetype_idx);
|
||||
|
||||
|
533
src/callbacks.c
533
src/callbacks.c
File diff suppressed because it is too large
Load Diff
@ -21,9 +21,13 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include "geany.h" /* necessary for interface.c */
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint last_doc_idx;
|
||||
GeanyDocument *last_doc;
|
||||
} CallbacksData;
|
||||
|
||||
extern CallbacksData callbacks_data;
|
||||
|
@ -385,22 +385,22 @@ static void on_save_as_new_tab_toggled(GtkToggleButton *togglebutton, gpointer u
|
||||
static void handle_save_as(const gchar *utf8_filename, gboolean open_new_tab,
|
||||
gboolean rename_file)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
g_return_if_fail(NZV(utf8_filename));
|
||||
|
||||
if (open_new_tab)
|
||||
{ /* "open" the saved file in a new tab and switch to it */
|
||||
idx = document_clone(idx, utf8_filename);
|
||||
document_save_file_as(idx, NULL);
|
||||
doc = document_clone(doc, utf8_filename);
|
||||
document_save_file_as(doc, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (documents[idx]->file_name != NULL)
|
||||
if (doc->file_name != NULL)
|
||||
{
|
||||
if (rename_file)
|
||||
{
|
||||
gchar *old_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
gchar *old_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
gchar *new_filename = utils_get_locale_from_utf8(utf8_filename);
|
||||
|
||||
g_rename(old_filename, new_filename);
|
||||
@ -408,14 +408,14 @@ static void handle_save_as(const gchar *utf8_filename, gboolean open_new_tab,
|
||||
g_free(new_filename);
|
||||
}
|
||||
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
|
||||
tm_workspace_remove_object(documents[idx]->tm_file, TRUE, TRUE);
|
||||
documents[idx]->tm_file = NULL;
|
||||
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
|
||||
doc->tm_file = NULL;
|
||||
}
|
||||
document_save_file_as(idx, utf8_filename);
|
||||
document_save_file_as(doc, utf8_filename);
|
||||
}
|
||||
|
||||
if (! open_new_tab)
|
||||
build_menu_update(idx);
|
||||
build_menu_update(doc);
|
||||
}
|
||||
|
||||
|
||||
@ -520,7 +520,8 @@ static void create_save_file_dialog(void)
|
||||
#if ! GEANY_USE_WIN32_DIALOG
|
||||
static gboolean gtk_show_save_as(const gchar *initdir)
|
||||
{
|
||||
gint idx = document_get_cur_idx(), resp;
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gint resp;
|
||||
gboolean folder_set = FALSE;
|
||||
|
||||
if (ui_widgets.save_filesel == NULL)
|
||||
@ -528,11 +529,11 @@ static gboolean gtk_show_save_as(const gchar *initdir)
|
||||
|
||||
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.save_filesel));
|
||||
|
||||
if (documents[idx]->file_name != NULL)
|
||||
if (doc->file_name != NULL)
|
||||
{
|
||||
if (g_path_is_absolute(documents[idx]->file_name))
|
||||
if (g_path_is_absolute(doc->file_name))
|
||||
{
|
||||
gchar *locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
gchar *locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
gchar *locale_basename = g_path_get_basename(locale_filename);
|
||||
gchar *locale_dirname = g_path_get_dirname(locale_filename);
|
||||
|
||||
@ -548,16 +549,16 @@ static gboolean gtk_show_save_as(const gchar *initdir)
|
||||
}
|
||||
else
|
||||
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(ui_widgets.save_filesel),
|
||||
documents[idx]->file_name);
|
||||
doc->file_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *fname = NULL;
|
||||
|
||||
if (documents[idx]->file_type != NULL && documents[idx]->file_type->id != GEANY_FILETYPES_NONE &&
|
||||
documents[idx]->file_type->extension != NULL)
|
||||
if (doc->file_type != NULL && doc->file_type->id != GEANY_FILETYPES_NONE &&
|
||||
doc->file_type->extension != NULL)
|
||||
fname = g_strconcat(GEANY_STRING_UNTITLED, ".",
|
||||
documents[idx]->file_type->extension, NULL);
|
||||
doc->file_type->extension, NULL);
|
||||
else
|
||||
fname = g_strdup(GEANY_STRING_UNTITLED);
|
||||
|
||||
@ -660,7 +661,7 @@ void dialogs_show_msgbox_with_secondary(gint type, const gchar *text, const gcha
|
||||
}
|
||||
|
||||
|
||||
gboolean dialogs_show_unsaved_file(gint idx)
|
||||
gboolean dialogs_show_unsaved_file(GeanyDocument *doc)
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
GtkWidget *dialog, *button;
|
||||
@ -672,12 +673,12 @@ gboolean dialogs_show_unsaved_file(gint idx)
|
||||
/* display the file tab to remind the user of the document */
|
||||
main_status.quitting = FALSE;
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
document_get_notebook_page(idx));
|
||||
document_get_notebook_page(doc));
|
||||
main_status.quitting = old_quitting_state;
|
||||
|
||||
if (documents[idx]->file_name != NULL)
|
||||
if (doc->file_name != NULL)
|
||||
{
|
||||
short_fn = g_path_get_basename(documents[idx]->file_name);
|
||||
short_fn = g_path_get_basename(doc->file_name);
|
||||
}
|
||||
|
||||
msg = g_strdup_printf(_("The file '%s' is not saved."),
|
||||
@ -711,13 +712,13 @@ gboolean dialogs_show_unsaved_file(gint idx)
|
||||
{
|
||||
case GTK_RESPONSE_YES:
|
||||
{
|
||||
if (documents[idx]->file_name == NULL)
|
||||
if (doc->file_name == NULL)
|
||||
{
|
||||
ret = dialogs_show_save_as();
|
||||
}
|
||||
else
|
||||
/* document_save_file() returns the status if the file could be saved */
|
||||
ret = document_save_file(idx, FALSE);
|
||||
ret = document_save_file(doc, FALSE);
|
||||
break;
|
||||
}
|
||||
case GTK_RESPONSE_NO: ret = TRUE; break;
|
||||
@ -943,7 +944,7 @@ void dialogs_show_goto_line()
|
||||
}
|
||||
|
||||
|
||||
void dialogs_show_file_properties(gint idx)
|
||||
void dialogs_show_file_properties(GeanyDocument *doc)
|
||||
{
|
||||
GtkWidget *dialog, *label, *table, *hbox, *image, *perm_table, *check, *vbox;
|
||||
gchar *file_size, *title, *base_name, *time_changed, *time_modified, *time_accessed, *enctext;
|
||||
@ -972,7 +973,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
# define S_IXOTH 0
|
||||
#endif
|
||||
|
||||
if (idx == -1 || ! documents[idx]->is_valid || documents[idx]->file_name == NULL)
|
||||
if (doc == NULL || doc->file_name == NULL)
|
||||
{
|
||||
dialogs_show_msgbox(GTK_MESSAGE_ERROR,
|
||||
_("An error occurred or file information could not be retrieved (e.g. from a new file)."));
|
||||
@ -981,7 +982,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
||||
if (g_stat(locale_filename, &st) == 0)
|
||||
{
|
||||
/* first copy the returned string and the trim it, to not modify the static glibc string
|
||||
@ -1007,7 +1008,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
time_accessed = g_strdup(_("unknown"));
|
||||
#endif
|
||||
|
||||
base_name = g_path_get_basename(documents[idx]->file_name);
|
||||
base_name = g_path_get_basename(doc->file_name);
|
||||
title = g_strconcat(base_name, " ", _("Properties"), NULL);
|
||||
dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(main_widgets.window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
@ -1044,7 +1045,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
||||
|
||||
label = gtk_label_new(documents[idx]->file_type->title);
|
||||
label = gtk_label_new(doc->file_type->title);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1,
|
||||
(GtkAttachOptions) (GTK_FILL),
|
||||
(GtkAttachOptions) (0), 0, 0);
|
||||
@ -1072,7 +1073,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
||||
|
||||
label = gtk_label_new(documents[idx]->file_name);
|
||||
label = gtk_label_new(doc->file_name);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 1, 2, 2, 3,
|
||||
(GtkAttachOptions) (GTK_FILL),
|
||||
(GtkAttachOptions) (0), 0, 0);
|
||||
@ -1088,7 +1089,7 @@ void dialogs_show_file_properties(gint idx)
|
||||
check = gtk_check_button_new_with_label(_("(only inside Geany)"));
|
||||
gtk_widget_set_sensitive(check, FALSE);
|
||||
gtk_button_set_focus_on_click(GTK_BUTTON(check), FALSE);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), documents[idx]->readonly);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), doc->readonly);
|
||||
gtk_table_attach(GTK_TABLE(table), check, 1, 2, 3, 4,
|
||||
(GtkAttachOptions) (GTK_FILL),
|
||||
(GtkAttachOptions) (0), 0, 0);
|
||||
@ -1102,9 +1103,9 @@ void dialogs_show_file_properties(gint idx)
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
||||
|
||||
enctext = g_strdup_printf("%s %s",
|
||||
documents[idx]->encoding,
|
||||
(encodings_is_unicode_charset(documents[idx]->encoding)) ?
|
||||
((documents[idx]->has_bom) ? _("(with BOM)") : _("(without BOM)")) : "");
|
||||
doc->encoding,
|
||||
(encodings_is_unicode_charset(doc->encoding)) ?
|
||||
((doc->has_bom) ? _("(with BOM)") : _("(without BOM)")) : "");
|
||||
|
||||
label = gtk_label_new(enctext);
|
||||
g_free(enctext);
|
||||
|
@ -37,7 +37,7 @@ void dialogs_show_open_file(void);
|
||||
|
||||
gboolean dialogs_show_save_as(void);
|
||||
|
||||
gboolean dialogs_show_unsaved_file(gint idx);
|
||||
gboolean dialogs_show_unsaved_file(GeanyDocument *doc);
|
||||
|
||||
void dialogs_show_open_font(void);
|
||||
|
||||
@ -50,7 +50,7 @@ GtkWidget *dialogs_show_input(const gchar *title, const gchar *label_text,
|
||||
|
||||
void dialogs_show_goto_line(void);
|
||||
|
||||
void dialogs_show_file_properties(gint idx);
|
||||
void dialogs_show_file_properties(GeanyDocument *doc);
|
||||
|
||||
gboolean dialogs_show_question(const gchar *text, ...) G_GNUC_PRINTF (1, 2);
|
||||
|
||||
|
1058
src/document.c
1058
src/document.c
File diff suppressed because it is too large
Load Diff
101
src/document.h
101
src/document.h
@ -67,7 +67,7 @@ extern GeanyFilePrefs file_prefs;
|
||||
/**
|
||||
* Structure for representing an open tab with all its properties.
|
||||
**/
|
||||
typedef struct GeanyDocument
|
||||
struct GeanyDocument
|
||||
{
|
||||
/** General flag to represent this document is active and all properties are set correctly. */
|
||||
gboolean is_valid;
|
||||
@ -117,8 +117,7 @@ typedef struct GeanyDocument
|
||||
* not be set elsewhere.
|
||||
* @see file_name. */
|
||||
gchar *real_path;
|
||||
}
|
||||
GeanyDocument;
|
||||
};
|
||||
|
||||
|
||||
/** Dynamic array of GeanyDocument pointers holding information about the notebook tabs. */
|
||||
@ -155,128 +154,104 @@ extern GPtrArray *documents_array;
|
||||
* GEANY_STRING_UNTITLED (e.g. _("untitled")) if the %document's filename was not yet set.
|
||||
* This macro never returns NULL.
|
||||
**/
|
||||
#define DOC_FILENAME(doc_idx) \
|
||||
#define DOC_FILENAME(doc) \
|
||||
((doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED)
|
||||
|
||||
#define DOC_IDX_FILENAME(doc_idx) \
|
||||
((documents[doc_idx]->file_name != NULL) ? (documents[doc_idx]->file_name) : \
|
||||
GEANY_STRING_UNTITLED)
|
||||
|
||||
|
||||
/* These functions will replace the older functions. For now they have a documents_ prefix. */
|
||||
|
||||
GeanyDocument* documents_new_file(const gchar *filename, GeanyFiletype *ft,
|
||||
const gchar *text);
|
||||
GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
|
||||
|
||||
GeanyDocument* documents_find_by_filename(const gchar *utf8_filename);
|
||||
GeanyDocument* document_new_file_if_non_open();
|
||||
|
||||
GeanyDocument* documents_find_by_real_path(const gchar *realname);
|
||||
GeanyDocument* document_find_by_filename(const gchar *utf8_filename);
|
||||
|
||||
gboolean documents_save_file(GeanyDocument *doc, gboolean force);
|
||||
GeanyDocument* document_find_by_real_path(const gchar *realname);
|
||||
|
||||
GeanyDocument* documents_open_file(const gchar *locale_filename, gboolean readonly,
|
||||
gboolean document_save_file(GeanyDocument *doc, gboolean force);
|
||||
|
||||
gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname);
|
||||
|
||||
GeanyDocument* document_open_file(const gchar *locale_filename, gboolean readonly,
|
||||
GeanyFiletype *ft, const gchar *forced_enc);
|
||||
|
||||
gboolean documents_reload_file(GeanyDocument *doc, const gchar *forced_enc);
|
||||
gboolean document_reload_file(GeanyDocument *doc, const gchar *forced_enc);
|
||||
|
||||
void documents_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
|
||||
void document_set_text_changed(GeanyDocument *doc, gboolean changed);
|
||||
|
||||
void documents_set_text_changed(GeanyDocument *doc, gboolean changed);
|
||||
|
||||
void documents_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
|
||||
void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
|
||||
|
||||
|
||||
GeanyDocument *document_find_by_sci(ScintillaObject *sci);
|
||||
|
||||
gint document_find_by_filename(const gchar *utf8_filename);
|
||||
|
||||
gint document_find_by_real_path(const gchar *realname);
|
||||
|
||||
gint document_find_by_sci(ScintillaObject *sci);
|
||||
|
||||
gint document_get_notebook_page(gint doc_idx);
|
||||
gint document_get_notebook_page(GeanyDocument *doc);
|
||||
|
||||
GeanyDocument* document_get_from_page(guint page_num);
|
||||
|
||||
gint document_get_n_idx(guint page_num);
|
||||
|
||||
GeanyDocument *document_get_current(void);
|
||||
|
||||
gint document_get_cur_idx(void);
|
||||
|
||||
void document_init_doclist(void);
|
||||
|
||||
void document_finalize(void);
|
||||
|
||||
void document_set_text_changed(gint idx);
|
||||
|
||||
void document_apply_update_prefs(gint idx);
|
||||
void document_apply_update_prefs(GeanyDocument *doc);
|
||||
|
||||
gboolean document_remove_page(guint page_num);
|
||||
|
||||
gboolean document_remove(guint page_num);
|
||||
|
||||
gboolean document_account_for_unsaved(void);
|
||||
|
||||
gboolean document_close_all(void);
|
||||
|
||||
gint document_new_file_if_non_open();
|
||||
GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename);
|
||||
|
||||
gint document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
|
||||
|
||||
gint document_clone(gint old_idx, const gchar *utf8_filename);
|
||||
|
||||
gint document_open_file(const gchar *locale_filename, gboolean readonly,
|
||||
GeanyFiletype *ft, const gchar *forced_enc);
|
||||
|
||||
gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean readonly,
|
||||
GeanyFiletype *ft, const gchar *forced_enc);
|
||||
GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos,
|
||||
gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
|
||||
|
||||
void document_open_file_list(const gchar *data, gssize length);
|
||||
|
||||
void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
|
||||
const gchar *forced_enc);
|
||||
|
||||
gboolean document_reload_file(gint idx, const gchar *forced_enc);
|
||||
gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint flags, gboolean inc);
|
||||
|
||||
|
||||
gboolean document_save_file_as(gint idx, const gchar *utf8_fname);
|
||||
|
||||
gboolean document_save_file(gint idx, gboolean force);
|
||||
|
||||
gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
|
||||
|
||||
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards,
|
||||
gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gboolean search_backwards,
|
||||
gboolean scroll, GtkWidget *parent);
|
||||
|
||||
gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
|
||||
gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
|
||||
gint flags, gboolean search_backwards);
|
||||
|
||||
gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
|
||||
gboolean document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
|
||||
gint flags, gboolean escaped_chars);
|
||||
|
||||
void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags,
|
||||
void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, gint flags,
|
||||
gboolean escaped_chars);
|
||||
|
||||
void document_update_tag_list(gint idx, gboolean update);
|
||||
void document_update_tag_list(GeanyDocument *doc, gboolean update);
|
||||
|
||||
void document_set_filetype(gint idx, GeanyFiletype *type);
|
||||
|
||||
void document_set_encoding(gint idx, const gchar *new_encoding);
|
||||
void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
|
||||
|
||||
gboolean document_check_disk_status(GeanyDocument *doc, gboolean force);
|
||||
|
||||
/* own Undo / Redo implementation to be able to undo / redo changes
|
||||
* to the encoding or the Unicode BOM (which are Scintilla independent).
|
||||
* All Scintilla events are stored in the undo / redo buffer and are passed through. */
|
||||
|
||||
gboolean document_can_undo(gint idx);
|
||||
gboolean document_can_undo(GeanyDocument *doc);
|
||||
|
||||
gboolean document_can_redo(gint idx);
|
||||
gboolean document_can_redo(GeanyDocument *doc);
|
||||
|
||||
void document_undo(gint idx);
|
||||
void document_undo(GeanyDocument *doc);
|
||||
|
||||
void document_redo(gint idx);
|
||||
void document_redo(GeanyDocument *doc);
|
||||
|
||||
void document_undo_add(gint idx, guint type, gpointer data);
|
||||
void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
|
||||
|
||||
|
||||
GdkColor *document_get_status_color(gint idx);
|
||||
GdkColor *document_get_status_color(GeanyDocument *doc);
|
||||
|
||||
void document_delay_colourise(void);
|
||||
|
||||
|
788
src/editor.c
788
src/editor.c
File diff suppressed because it is too large
Load Diff
62
src/editor.h
62
src/editor.h
@ -115,23 +115,23 @@ gboolean on_editor_button_press_event(GtkWidget *widget, GdkEventButton *event,
|
||||
|
||||
void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer user_data);
|
||||
|
||||
gboolean editor_start_auto_complete(gint idx, gint pos, gboolean force);
|
||||
gboolean editor_start_auto_complete(GeanyDocument *doc, gint pos, gboolean force);
|
||||
|
||||
void editor_close_block(gint idx, gint pos);
|
||||
void editor_close_block(GeanyDocument *doc, gint pos);
|
||||
|
||||
gboolean editor_complete_snippet(gint idx, gint pos);
|
||||
gboolean editor_complete_snippet(GeanyDocument *doc, gint pos);
|
||||
|
||||
void editor_auto_latex(gint idx, gint pos);
|
||||
void editor_auto_latex(GeanyDocument *doc, gint pos);
|
||||
|
||||
void editor_show_macro_list(ScintillaObject *sci);
|
||||
|
||||
gboolean editor_show_calltip(gint idx, gint pos);
|
||||
gboolean editor_show_calltip(GeanyDocument *doc, gint pos);
|
||||
|
||||
void editor_do_comment_toggle(gint idx);
|
||||
void editor_do_comment_toggle(GeanyDocument *doc);
|
||||
|
||||
void editor_do_comment(gint idx, gint line, gboolean allow_empty_lines, gboolean toggle);
|
||||
void editor_do_comment(GeanyDocument *doc, gint line, gboolean allow_empty_lines, gboolean toggle);
|
||||
|
||||
gint editor_do_uncomment(gint idx, gint line, gboolean toggle);
|
||||
gint editor_do_uncomment(GeanyDocument *doc, gint line, gboolean toggle);
|
||||
|
||||
void editor_highlight_braces(ScintillaObject *sci, gint cur_pos);
|
||||
|
||||
@ -139,19 +139,19 @@ gboolean editor_lexer_is_c_like(gint lexer);
|
||||
|
||||
gint editor_lexer_get_type_keyword_idx(gint lexer);
|
||||
|
||||
void editor_insert_multiline_comment(gint idx);
|
||||
void editor_insert_multiline_comment(GeanyDocument *doc);
|
||||
|
||||
void editor_insert_alternative_whitespace(gint idx);
|
||||
void editor_insert_alternative_whitespace(GeanyDocument *doc);
|
||||
|
||||
void editor_smart_line_indentation(gint idx, gint pos);
|
||||
void editor_smart_line_indentation(GeanyDocument *doc, gint pos);
|
||||
|
||||
void editor_indentation_by_one_space(gint idx, gint pos, gboolean decrease);
|
||||
void editor_indentation_by_one_space(GeanyDocument *doc, gint pos, gboolean decrease);
|
||||
|
||||
gboolean editor_line_in_view(ScintillaObject *sci, gint line);
|
||||
|
||||
void editor_scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view);
|
||||
|
||||
void editor_display_current_line(gint idx, gfloat percent_of_view);
|
||||
void editor_display_current_line(GeanyDocument *doc, gfloat percent_of_view);
|
||||
|
||||
void editor_finalize(void);
|
||||
|
||||
@ -161,7 +161,7 @@ void editor_finalize(void);
|
||||
void editor_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t wordlen,
|
||||
const gchar *wc);
|
||||
|
||||
gchar *editor_get_default_selection(gint idx, gboolean use_current_word, const gchar *wordchars);
|
||||
gchar *editor_get_default_selection(GeanyDocument *doc, gboolean use_current_word, const gchar *wordchars);
|
||||
|
||||
void editor_select_word(ScintillaObject *sci);
|
||||
|
||||
@ -169,38 +169,38 @@ void editor_select_lines(ScintillaObject *sci, gboolean extra_line);
|
||||
|
||||
void editor_select_paragraph(ScintillaObject *sci);
|
||||
|
||||
void editor_set_indicator_on_line(gint idx, gint line);
|
||||
void editor_set_indicator_on_line(GeanyDocument *doc, gint line);
|
||||
|
||||
void editor_set_indicator(gint idx, gint start, gint end);
|
||||
void editor_set_indicator(GeanyDocument *doc, gint start, gint end);
|
||||
|
||||
void editor_clear_indicators(gint idx);
|
||||
void editor_clear_indicators(GeanyDocument *doc);
|
||||
|
||||
void editor_set_font(gint idx, const gchar *font_name, gint size);
|
||||
void editor_set_font(GeanyDocument *doc, const gchar *font_name, gint size);
|
||||
|
||||
const gchar *editor_get_eol_char_name(gint idx);
|
||||
const gchar *editor_get_eol_char_name(GeanyDocument *doc);
|
||||
|
||||
gint editor_get_eol_char_len(gint idx);
|
||||
gint editor_get_eol_char_len(GeanyDocument *doc);
|
||||
|
||||
const gchar *editor_get_eol_char(gint idx);
|
||||
const gchar *editor_get_eol_char(GeanyDocument *doc);
|
||||
|
||||
void editor_fold_all(gint idx);
|
||||
void editor_fold_all(GeanyDocument *doc);
|
||||
|
||||
void editor_unfold_all(gint idx);
|
||||
void editor_unfold_all(GeanyDocument *doc);
|
||||
|
||||
void editor_replace_tabs(gint idx);
|
||||
void editor_replace_tabs(GeanyDocument *doc);
|
||||
|
||||
void editor_strip_line_trailing_spaces(gint idx, gint line);
|
||||
void editor_strip_line_trailing_spaces(GeanyDocument *doc, gint line);
|
||||
|
||||
void editor_strip_trailing_spaces(gint idx);
|
||||
void editor_strip_trailing_spaces(GeanyDocument *doc);
|
||||
|
||||
void editor_ensure_final_newline(gint idx);
|
||||
void editor_ensure_final_newline(GeanyDocument *doc);
|
||||
|
||||
void editor_insert_color(gint idx, const gchar *colour);
|
||||
void editor_insert_color(GeanyDocument *doc, const gchar *colour);
|
||||
|
||||
void editor_set_use_tabs(gint idx, gboolean use_tabs);
|
||||
void editor_set_use_tabs(GeanyDocument *doc, gboolean use_tabs);
|
||||
|
||||
void editor_set_line_wrapping(gint idx, gboolean wrap);
|
||||
void editor_set_line_wrapping(GeanyDocument *doc, gboolean wrap);
|
||||
|
||||
gboolean editor_goto_pos(gint idx, gint pos, gboolean mark);
|
||||
gboolean editor_goto_pos(GeanyDocument *doc, gint pos, gboolean mark);
|
||||
|
||||
#endif
|
||||
|
@ -658,16 +658,16 @@ static GeanyFiletype *filetypes_detect_from_file_internal(const gchar *utf8_file
|
||||
|
||||
|
||||
/* Detect the filetype for document idx. */
|
||||
GeanyFiletype *filetypes_detect_from_file(gint idx)
|
||||
GeanyFiletype *filetypes_detect_from_file(GeanyDocument *doc)
|
||||
{
|
||||
GeanyFiletype *ft;
|
||||
gchar *line;
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return filetypes[GEANY_FILETYPES_NONE];
|
||||
|
||||
line = sci_get_line(documents[idx]->sci, 0);
|
||||
ft = filetypes_detect_from_file_internal(documents[idx]->file_name, line);
|
||||
line = sci_get_line(doc->sci, 0);
|
||||
ft = filetypes_detect_from_file_internal(doc->file_name, line);
|
||||
g_free(line);
|
||||
return ft;
|
||||
}
|
||||
@ -715,10 +715,11 @@ static void
|
||||
on_filetype_change (GtkMenuItem *menuitem,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (ignore_callback || idx < 0 || ! documents[idx]->is_valid) return;
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (ignore_callback || doc == NULL)
|
||||
return;
|
||||
|
||||
document_set_filetype(idx, (GeanyFiletype*)user_data);
|
||||
document_set_filetype(doc, (GeanyFiletype*)user_data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ void filetypes_init(void);
|
||||
void filetypes_init_types(void);
|
||||
|
||||
/* Detect the filetype for document idx, checking for a shebang, then filename extension. */
|
||||
GeanyFiletype *filetypes_detect_from_file(gint idx);
|
||||
GeanyFiletype *filetypes_detect_from_file(GeanyDocument *doc);
|
||||
|
||||
GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename);
|
||||
|
||||
|
@ -55,6 +55,7 @@
|
||||
|
||||
|
||||
/* useful forward declarations */
|
||||
typedef struct GeanyDocument GeanyDocument;
|
||||
typedef struct GeanyFiletype GeanyFiletype;
|
||||
typedef struct GeanyProject GeanyProject;
|
||||
|
||||
|
@ -86,27 +86,27 @@ static void create_signals(GObjectClass *g_object_class)
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, document_new),
|
||||
NULL, NULL,
|
||||
gtk_marshal_NONE__INT,
|
||||
gtk_marshal_NONE__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_INT);
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_OPEN] = g_signal_new (
|
||||
"document-open",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, document_open),
|
||||
NULL, NULL,
|
||||
gtk_marshal_NONE__INT,
|
||||
gtk_marshal_NONE__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_INT);
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
|
||||
"document-save",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, document_save),
|
||||
NULL, NULL,
|
||||
gtk_marshal_NONE__INT,
|
||||
gtk_marshal_NONE__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_INT);
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_ACTIVATE] = g_signal_new (
|
||||
"document-activate",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
@ -115,7 +115,7 @@ static void create_signals(GObjectClass *g_object_class)
|
||||
NULL, NULL,
|
||||
gtk_marshal_NONE__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_INT);
|
||||
G_TYPE_POINTER);
|
||||
|
||||
geany_object_signals[GCB_PROJECT_OPEN] = g_signal_new (
|
||||
"project-open",
|
||||
|
@ -70,10 +70,10 @@ struct _GeanyObjectClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*document_new)(gint idx);
|
||||
void (*document_open)(gint idx);
|
||||
void (*document_save)(gint idx);
|
||||
void (*document_activate)(gint idx);
|
||||
void (*document_new)(GeanyDocument *doc);
|
||||
void (*document_open)(GeanyDocument *doc);
|
||||
void (*document_save)(GeanyDocument *doc);
|
||||
void (*document_activate)(GeanyDocument *doc);
|
||||
void (*project_open)(GKeyFile *keyfile);
|
||||
void (*project_save)(GKeyFile *keyfile);
|
||||
void (*project_close)(void);
|
||||
|
@ -783,17 +783,17 @@ static gboolean check_snippet_completion(guint keyval, guint state)
|
||||
|
||||
if (kb->key == keyval && kb->mods == state)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
|
||||
/* keybinding only valid when scintilla widget has focus */
|
||||
if (DOC_IDX_VALID(idx) && focusw == GTK_WIDGET(documents[idx]->sci))
|
||||
if (doc != NULL && focusw == GTK_WIDGET(doc->sci))
|
||||
{
|
||||
ScintillaObject *sci = documents[idx]->sci;
|
||||
ScintillaObject *sci = doc->sci;
|
||||
gint pos = sci_get_current_position(sci);
|
||||
|
||||
if (editor_prefs.complete_snippets)
|
||||
return editor_complete_snippet(idx, pos);
|
||||
return editor_complete_snippet(doc, pos);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
@ -849,11 +849,11 @@ static gboolean check_vte(GdkModifierType state, guint keyval)
|
||||
|
||||
static void check_disk_status(void)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (DOC_IDX_VALID(idx))
|
||||
if (doc != NULL)
|
||||
{
|
||||
utils_check_disk_status(idx, FALSE);
|
||||
document_check_disk_status(doc, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1066,28 +1066,29 @@ static void cb_func_menu_zoomout(G_GNUC_UNUSED guint key_id)
|
||||
|
||||
static void cb_func_menu_foldall(G_GNUC_UNUSED guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
editor_fold_all(idx);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
editor_fold_all(doc);
|
||||
}
|
||||
|
||||
static void cb_func_menu_unfoldall(G_GNUC_UNUSED guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
editor_unfold_all(idx);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
editor_unfold_all(doc);
|
||||
}
|
||||
|
||||
static void cb_func_build_action(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GtkWidget *item;
|
||||
GeanyFiletype *ft;
|
||||
BuildMenuItems *menu_items;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
ft = documents[idx]->file_type;
|
||||
ft = doc->file_type;
|
||||
if (! ft) return;
|
||||
menu_items = build_get_menu_items(ft->id);
|
||||
|
||||
@ -1132,23 +1133,23 @@ static void cb_func_build_action(guint key_id)
|
||||
|
||||
static void cb_func_reloadtaglist(G_GNUC_UNUSED guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
document_update_tag_list(idx, TRUE);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
document_update_tag_list(doc, TRUE);
|
||||
}
|
||||
|
||||
|
||||
static gboolean check_current_word(void)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
gint pos;
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return FALSE;
|
||||
|
||||
pos = sci_get_current_position(documents[idx]->sci);
|
||||
pos = sci_get_current_position(doc->sci);
|
||||
|
||||
editor_find_current_word(documents[idx]->sci, pos,
|
||||
editor_find_current_word(doc->sci, pos,
|
||||
editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL);
|
||||
|
||||
if (*editor_info.current_word == 0)
|
||||
@ -1162,9 +1163,9 @@ static gboolean check_current_word(void)
|
||||
|
||||
static void cb_func_switch_editor(G_GNUC_UNUSED guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
gtk_widget_grab_focus(GTK_WIDGET(documents[idx]->sci));
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
gtk_widget_grab_focus(GTK_WIDGET(doc->sci));
|
||||
}
|
||||
|
||||
static void cb_func_switch_scribble(G_GNUC_UNUSED guint key_id)
|
||||
@ -1230,24 +1231,26 @@ static void cb_func_switch_tabright(G_GNUC_UNUSED guint key_id)
|
||||
|
||||
static void cb_func_switch_tablastused(G_GNUC_UNUSED guint key_id)
|
||||
{
|
||||
gint last_doc_idx = callbacks_data.last_doc_idx;
|
||||
GeanyDocument *last_doc = callbacks_data.last_doc;
|
||||
|
||||
if (DOC_IDX_VALID(last_doc_idx))
|
||||
if (DOC_VALID(last_doc))
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
document_get_notebook_page(last_doc_idx));
|
||||
document_get_notebook_page(last_doc));
|
||||
}
|
||||
|
||||
/* move document left/right/first/last */
|
||||
static void cb_func_move_tab(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GtkWidget *sci = GTK_WIDGET(documents[idx]->sci);
|
||||
GtkWidget *sci;
|
||||
GtkNotebook *nb = GTK_NOTEBOOK(main_widgets.notebook);
|
||||
gint cur_page = gtk_notebook_get_current_page(nb);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
sci = GTK_WIDGET(doc->sci);
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
case GEANY_KEYS_NOTEBOOK_MOVETABLEFT:
|
||||
@ -1284,30 +1287,32 @@ static void cb_func_menu_toggle_all(G_GNUC_UNUSED guint key_id)
|
||||
}
|
||||
|
||||
|
||||
static void goto_matching_brace(gint idx)
|
||||
static void goto_matching_brace(GeanyDocument *doc)
|
||||
{
|
||||
gint pos, new_pos;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
pos = sci_get_current_position(documents[idx]->sci);
|
||||
if (! utils_isbrace(sci_get_char_at(documents[idx]->sci, pos), TRUE))
|
||||
pos = sci_get_current_position(doc->sci);
|
||||
if (! utils_isbrace(sci_get_char_at(doc->sci, pos), TRUE))
|
||||
pos--; /* set pos to the brace */
|
||||
|
||||
new_pos = sci_find_bracematch(documents[idx]->sci, pos);
|
||||
new_pos = sci_find_bracematch(doc->sci, pos);
|
||||
if (new_pos != -1)
|
||||
{ /* set the cursor at the brace */
|
||||
sci_set_current_position(documents[idx]->sci, new_pos, FALSE);
|
||||
editor_display_current_line(idx, 0.5F);
|
||||
sci_set_current_position(doc->sci, new_pos, FALSE);
|
||||
editor_display_current_line(doc, 0.5F);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void cb_func_clipboard(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
@ -1321,10 +1326,10 @@ static void cb_func_clipboard(guint key_id)
|
||||
on_paste1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_CLIPBOARD_COPYLINE:
|
||||
sci_cmd(documents[idx]->sci, SCI_LINECOPY);
|
||||
sci_cmd(doc->sci, SCI_LINECOPY);
|
||||
break;
|
||||
case GEANY_KEYS_CLIPBOARD_CUTLINE:
|
||||
sci_cmd(documents[idx]->sci, SCI_LINECUT);
|
||||
sci_cmd(doc->sci, SCI_LINECUT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1334,11 +1339,12 @@ static void cb_func_clipboard(guint key_id)
|
||||
static void cb_func_goto_action(guint key_id)
|
||||
{
|
||||
gint cur_line;
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
cur_line = sci_get_current_line(documents[idx]->sci);
|
||||
cur_line = sci_get_current_line(doc->sci);
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
@ -1352,34 +1358,34 @@ static void cb_func_goto_action(guint key_id)
|
||||
on_go_to_line1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_GOTO_MATCHINGBRACE:
|
||||
goto_matching_brace(idx);
|
||||
goto_matching_brace(doc);
|
||||
break;
|
||||
case GEANY_KEYS_GOTO_TOGGLEMARKER:
|
||||
{
|
||||
gboolean set = sci_is_marker_set_at_line(documents[idx]->sci, cur_line, 1);
|
||||
gboolean set = sci_is_marker_set_at_line(doc->sci, cur_line, 1);
|
||||
|
||||
sci_set_marker_at_line(documents[idx]->sci, cur_line, ! set, 1);
|
||||
sci_set_marker_at_line(doc->sci, cur_line, ! set, 1);
|
||||
break;
|
||||
}
|
||||
case GEANY_KEYS_GOTO_NEXTMARKER:
|
||||
{
|
||||
gint mline = sci_marker_next(documents[idx]->sci, cur_line + 1, 1 << 1, TRUE);
|
||||
gint mline = sci_marker_next(doc->sci, cur_line + 1, 1 << 1, TRUE);
|
||||
|
||||
if (mline != -1)
|
||||
{
|
||||
sci_set_current_line(documents[idx]->sci, mline);
|
||||
editor_display_current_line(idx, 0.5F);
|
||||
sci_set_current_line(doc->sci, mline);
|
||||
editor_display_current_line(doc, 0.5F);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GEANY_KEYS_GOTO_PREVIOUSMARKER:
|
||||
{
|
||||
gint mline = sci_marker_previous(documents[idx]->sci, cur_line - 1, 1 << 1, TRUE);
|
||||
gint mline = sci_marker_previous(doc->sci, cur_line - 1, 1 << 1, TRUE);
|
||||
|
||||
if (mline != -1)
|
||||
{
|
||||
sci_set_current_line(documents[idx]->sci, mline);
|
||||
editor_display_current_line(idx, 0.5F);
|
||||
sci_set_current_line(doc->sci, mline);
|
||||
editor_display_current_line(doc, 0.5F);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1419,11 +1425,12 @@ static void delete_lines(ScintillaObject *sci)
|
||||
/* common function for editor keybindings, only valid when scintilla has focus. */
|
||||
static void cb_func_editor_action(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
|
||||
/* edit keybindings only valid when scintilla widget has focus */
|
||||
if (! DOC_IDX_VALID(idx) || focusw != GTK_WIDGET(documents[idx]->sci)) return;
|
||||
if (doc == NULL || focusw != GTK_WIDGET(doc->sci))
|
||||
return;
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
@ -1434,31 +1441,31 @@ static void cb_func_editor_action(guint key_id)
|
||||
on_redo1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_SCROLLTOLINE:
|
||||
editor_scroll_to_line(documents[idx]->sci, -1, 0.5F);
|
||||
editor_scroll_to_line(doc->sci, -1, 0.5F);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_SCROLLLINEUP:
|
||||
sci_cmd(documents[idx]->sci, SCI_LINESCROLLUP);
|
||||
sci_cmd(doc->sci, SCI_LINESCROLLUP);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_SCROLLLINEDOWN:
|
||||
sci_cmd(documents[idx]->sci, SCI_LINESCROLLDOWN);
|
||||
sci_cmd(doc->sci, SCI_LINESCROLLDOWN);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_DUPLICATELINE:
|
||||
duplicate_lines(documents[idx]->sci);
|
||||
duplicate_lines(doc->sci);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_DELETELINE:
|
||||
delete_lines(documents[idx]->sci);
|
||||
delete_lines(doc->sci);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_TRANSPOSELINE:
|
||||
sci_cmd(documents[idx]->sci, SCI_LINETRANSPOSE);
|
||||
sci_cmd(doc->sci, SCI_LINETRANSPOSE);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_AUTOCOMPLETE:
|
||||
editor_start_auto_complete(idx, sci_get_current_position(documents[idx]->sci), TRUE);
|
||||
editor_start_auto_complete(doc, sci_get_current_position(doc->sci), TRUE);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_CALLTIP:
|
||||
editor_show_calltip(idx, -1);
|
||||
editor_show_calltip(doc, -1);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_MACROLIST:
|
||||
editor_show_macro_list(documents[idx]->sci);
|
||||
editor_show_macro_list(doc->sci);
|
||||
break;
|
||||
case GEANY_KEYS_EDITOR_CONTEXTACTION:
|
||||
if (check_current_word())
|
||||
@ -1473,10 +1480,10 @@ static void cb_func_editor_action(guint key_id)
|
||||
switch (kb->key)
|
||||
{
|
||||
case GDK_space:
|
||||
sci_add_text(documents[idx]->sci, " ");
|
||||
sci_add_text(doc->sci, " ");
|
||||
break;
|
||||
case GDK_Tab:
|
||||
sci_cmd(documents[idx]->sci, SCI_TAB);
|
||||
sci_cmd(doc->sci, SCI_TAB);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1490,11 +1497,12 @@ static void cb_func_editor_action(guint key_id)
|
||||
/* common function for format keybindings, only valid when scintilla has focus. */
|
||||
static void cb_func_format_action(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
|
||||
/* keybindings only valid when scintilla widget has focus */
|
||||
if (! DOC_IDX_VALID(idx) || focusw != GTK_WIDGET(documents[idx]->sci)) return;
|
||||
if (doc == NULL || focusw != GTK_WIDGET(doc->sci))
|
||||
return;
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
@ -1514,28 +1522,28 @@ static void cb_func_format_action(guint key_id)
|
||||
on_menu_decrease_indent1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_INCREASEINDENTBYSPACE:
|
||||
editor_indentation_by_one_space(idx, -1, FALSE);
|
||||
editor_indentation_by_one_space(doc, -1, FALSE);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_DECREASEINDENTBYSPACE:
|
||||
editor_indentation_by_one_space(idx, -1, TRUE);
|
||||
editor_indentation_by_one_space(doc, -1, TRUE);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_AUTOINDENT:
|
||||
editor_smart_line_indentation(idx, -1);
|
||||
editor_smart_line_indentation(doc, -1);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_TOGGLECASE:
|
||||
on_toggle_case1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_SENDTOCMD1:
|
||||
if (ui_prefs.custom_commands && g_strv_length(ui_prefs.custom_commands) > 0)
|
||||
tools_execute_custom_command(idx, ui_prefs.custom_commands[0]);
|
||||
tools_execute_custom_command(doc, ui_prefs.custom_commands[0]);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_SENDTOCMD2:
|
||||
if (ui_prefs.custom_commands && g_strv_length(ui_prefs.custom_commands) > 1)
|
||||
tools_execute_custom_command(idx, ui_prefs.custom_commands[1]);
|
||||
tools_execute_custom_command(doc, ui_prefs.custom_commands[1]);
|
||||
break;
|
||||
case GEANY_KEYS_FORMAT_SENDTOCMD3:
|
||||
if (ui_prefs.custom_commands && g_strv_length(ui_prefs.custom_commands) > 2)
|
||||
tools_execute_custom_command(idx, ui_prefs.custom_commands[2]);
|
||||
tools_execute_custom_command(doc, ui_prefs.custom_commands[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1544,7 +1552,7 @@ static void cb_func_format_action(guint key_id)
|
||||
/* common function for select keybindings, only valid when scintilla has focus. */
|
||||
static void cb_func_select_action(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
static GtkWidget *scribble_widget = NULL;
|
||||
|
||||
@ -1558,7 +1566,8 @@ static void cb_func_select_action(guint key_id)
|
||||
}
|
||||
|
||||
/* keybindings only valid when scintilla widget has focus */
|
||||
if (! DOC_IDX_VALID(idx) || focusw != GTK_WIDGET(documents[idx]->sci)) return;
|
||||
if (doc == NULL || focusw != GTK_WIDGET(doc->sci))
|
||||
return;
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
@ -1566,13 +1575,13 @@ static void cb_func_select_action(guint key_id)
|
||||
on_menu_select_all1_activate(NULL, NULL);
|
||||
break;
|
||||
case GEANY_KEYS_SELECT_WORD:
|
||||
editor_select_word(documents[idx]->sci);
|
||||
editor_select_word(doc->sci);
|
||||
break;
|
||||
case GEANY_KEYS_SELECT_LINE:
|
||||
editor_select_lines(documents[idx]->sci, FALSE);
|
||||
editor_select_lines(doc->sci, FALSE);
|
||||
break;
|
||||
case GEANY_KEYS_SELECT_PARAGRAPH:
|
||||
editor_select_paragraph(documents[idx]->sci);
|
||||
editor_select_paragraph(doc->sci);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1587,16 +1596,16 @@ static void cb_func_menu_replacetabs(G_GNUC_UNUSED guint key_id)
|
||||
/* common function for insert keybindings, only valid when scintilla has focus. */
|
||||
static void cb_func_insert_action(guint key_id)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
|
||||
/* keybindings only valid when scintilla widget has focus */
|
||||
if (! DOC_IDX_VALID(idx) || focusw != GTK_WIDGET(documents[idx]->sci)) return;
|
||||
if (doc == NULL || focusw != GTK_WIDGET(doc->sci)) return;
|
||||
|
||||
switch (key_id)
|
||||
{
|
||||
case GEANY_KEYS_INSERT_ALTWHITESPACE:
|
||||
editor_insert_alternative_whitespace(idx);
|
||||
editor_insert_alternative_whitespace(doc);
|
||||
break;
|
||||
case GEANY_KEYS_INSERT_DATE:
|
||||
gtk_menu_item_activate(GTK_MENU_ITEM(lookup_widget(main_widgets.window, "insert_date_custom1")));
|
||||
|
@ -116,33 +116,34 @@ static void save_recent_files(GKeyFile *config)
|
||||
}
|
||||
|
||||
|
||||
static gchar *get_session_file_string(gint idx)
|
||||
static gchar *get_session_file_string(GeanyDocument *doc)
|
||||
{
|
||||
gchar *fname;
|
||||
GeanyFiletype *ft = documents[idx]->file_type;
|
||||
GeanyFiletype *ft = doc->file_type;
|
||||
|
||||
if (ft == NULL) /* can happen when saving a new file when quitting */
|
||||
ft = filetypes[GEANY_FILETYPES_NONE];
|
||||
|
||||
fname = g_strdup_printf("%d;%s;%d;%d;%d;%d;%d;%s;",
|
||||
sci_get_current_position(documents[idx]->sci),
|
||||
sci_get_current_position(doc->sci),
|
||||
ft->name,
|
||||
documents[idx]->readonly,
|
||||
encodings_get_idx_from_charset(documents[idx]->encoding),
|
||||
documents[idx]->use_tabs,
|
||||
documents[idx]->auto_indent,
|
||||
documents[idx]->line_wrapping,
|
||||
documents[idx]->file_name);
|
||||
doc->readonly,
|
||||
encodings_get_idx_from_charset(doc->encoding),
|
||||
doc->use_tabs,
|
||||
doc->auto_indent,
|
||||
doc->line_wrapping,
|
||||
doc->file_name);
|
||||
return fname;
|
||||
}
|
||||
|
||||
|
||||
void configuration_save_session_files(GKeyFile *config)
|
||||
{
|
||||
gint idx, npage;
|
||||
gint npage;
|
||||
gchar *tmp;
|
||||
gchar entry[14];
|
||||
guint i = 0, j = 0, max;
|
||||
GeanyDocument *doc;
|
||||
|
||||
npage = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
g_key_file_set_integer(config, "files", "current_page", npage);
|
||||
@ -151,13 +152,13 @@ void configuration_save_session_files(GKeyFile *config)
|
||||
max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
idx = document_get_n_idx(i);
|
||||
if (idx >= 0 && documents[idx]->real_path != NULL)
|
||||
doc = document_get_from_page(i);
|
||||
if (doc != NULL && doc->real_path != NULL)
|
||||
{
|
||||
gchar *fname;
|
||||
|
||||
g_snprintf(entry, 13, "FILE_NAME_%d", j);
|
||||
fname = get_session_file_string(idx);
|
||||
fname = get_session_file_string(doc);
|
||||
g_key_file_set_string(config, "files", entry, fname);
|
||||
g_free(fname);
|
||||
j++;
|
||||
@ -840,16 +841,16 @@ static gboolean open_session_file(gchar **tmp)
|
||||
if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
|
||||
{
|
||||
GeanyFiletype *ft = filetypes_lookup_by_name(ft_name);
|
||||
gint new_idx = document_open_file_full(
|
||||
-1, locale_filename, pos, ro, ft,
|
||||
GeanyDocument *doc = document_open_file_full(
|
||||
NULL, locale_filename, pos, ro, ft,
|
||||
(enc_idx >= 0 && enc_idx < GEANY_ENCODINGS_MAX) ?
|
||||
encodings[enc_idx].charset : NULL);
|
||||
|
||||
if (DOC_IDX_VALID(new_idx))
|
||||
if (DOC_VALID(doc))
|
||||
{
|
||||
editor_set_use_tabs(new_idx, use_tabs);
|
||||
editor_set_line_wrapping(new_idx, line_wrapping);
|
||||
documents[new_idx]->auto_indent = auto_indent;
|
||||
editor_set_use_tabs(doc, use_tabs);
|
||||
editor_set_line_wrapping(doc, line_wrapping);
|
||||
doc->auto_indent = auto_indent;
|
||||
ret = TRUE;
|
||||
}
|
||||
}
|
||||
|
30
src/main.c
30
src/main.c
@ -661,7 +661,7 @@ static void signal_cb(gint sig)
|
||||
|
||||
static void handle_cl_filename(gchar *const filename)
|
||||
{
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
|
||||
if (filename != NULL)
|
||||
{
|
||||
@ -677,17 +677,17 @@ static void handle_cl_filename(gchar *const filename)
|
||||
if (filename != NULL &&
|
||||
g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
|
||||
{
|
||||
idx = document_open_file(filename, FALSE, NULL, NULL);
|
||||
doc = document_open_file(filename, FALSE, NULL, NULL);
|
||||
/* add recent file manually because opening_session_files is set */
|
||||
if (DOC_IDX_VALID(idx))
|
||||
ui_add_recent_file(documents[idx]->file_name);
|
||||
if (DOC_VALID(doc))
|
||||
ui_add_recent_file(doc->file_name);
|
||||
}
|
||||
else if (filename != NULL)
|
||||
{ /* create new file if it doesn't exist */
|
||||
idx = document_new_file(filename, NULL, NULL);
|
||||
if (DOC_IDX_VALID(idx))
|
||||
doc = document_new_file(filename, NULL, NULL);
|
||||
if (DOC_VALID(doc))
|
||||
{
|
||||
ui_add_recent_file(documents[idx]->file_name);
|
||||
ui_add_recent_file(doc->file_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -755,7 +755,7 @@ static void load_settings(void)
|
||||
|
||||
gint main(gint argc, gchar **argv)
|
||||
{
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
gint config_dir_result;
|
||||
gboolean load_project_from_cl = FALSE;
|
||||
|
||||
@ -899,8 +899,8 @@ gint main(gint argc, gchar **argv)
|
||||
|
||||
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 0)
|
||||
{
|
||||
ui_update_popup_copy_items(-1);
|
||||
ui_update_popup_reundo_items(-1);
|
||||
ui_update_popup_copy_items(NULL);
|
||||
ui_update_popup_reundo_items(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -912,11 +912,11 @@ gint main(gint argc, gchar **argv)
|
||||
ui_document_buttons_update();
|
||||
ui_save_buttons_toggle(FALSE);
|
||||
|
||||
idx = document_get_cur_idx();
|
||||
gtk_widget_grab_focus(GTK_WIDGET(documents[idx]->sci));
|
||||
treeviews_select_openfiles_item(idx);
|
||||
build_menu_update(idx);
|
||||
treeviews_update_tag_list(idx, FALSE);
|
||||
doc = document_get_current();
|
||||
gtk_widget_grab_focus(GTK_WIDGET(doc->sci));
|
||||
treeviews_select_openfiles_item(doc);
|
||||
build_menu_update(doc);
|
||||
treeviews_update_tag_list(doc, FALSE);
|
||||
|
||||
/* finally realize the window to show the user what we have done */
|
||||
gtk_widget_show(main_widgets.window);
|
||||
|
@ -532,18 +532,18 @@ gboolean msgwin_goto_compiler_file_line()
|
||||
if (filename != NULL && line > -1)
|
||||
{
|
||||
gchar *utf8_filename = utils_get_utf8_from_locale(filename);
|
||||
GeanyDocument *doc = documents_find_by_filename(utf8_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 = documents_open_file(filename, FALSE, NULL, NULL);
|
||||
doc = document_open_file(filename, FALSE, NULL, NULL);
|
||||
|
||||
if (doc != NULL)
|
||||
{
|
||||
if (! doc->changed) /* if modified, line may be wrong */
|
||||
editor_set_indicator_on_line(DOC_IDX(doc), line - 1);
|
||||
editor_set_indicator_on_line(doc, line - 1);
|
||||
|
||||
ret = navqueue_goto_line(old_doc, doc, line);
|
||||
}
|
||||
@ -819,7 +819,7 @@ gboolean msgwin_goto_messages_file_line()
|
||||
if (filename != NULL && line > -1)
|
||||
{
|
||||
/* use document_open_file to find an already open file, or open it in place */
|
||||
doc = documents_open_file(filename, FALSE, NULL, NULL);
|
||||
doc = document_open_file(filename, FALSE, NULL, NULL);
|
||||
if (doc != NULL)
|
||||
ret = navqueue_goto_line(old_doc, doc, line);
|
||||
}
|
||||
|
@ -167,17 +167,18 @@ gboolean navqueue_goto_line(GeanyDocument *old_doc, GeanyDocument *new_doc, gint
|
||||
add_new_position(new_doc->file_name, pos);
|
||||
}
|
||||
|
||||
return editor_goto_pos(DOC_IDX(new_doc), pos, TRUE);
|
||||
return editor_goto_pos(new_doc, pos, TRUE);
|
||||
}
|
||||
|
||||
|
||||
static gboolean goto_file_pos(const gchar *file, gint pos)
|
||||
{
|
||||
gint file_idx = document_find_by_filename(file);
|
||||
GeanyDocument *doc = document_find_by_filename(file);
|
||||
|
||||
if (file_idx < 0) return FALSE;
|
||||
if (doc == NULL)
|
||||
return FALSE;
|
||||
|
||||
return editor_goto_pos(file_idx, pos, TRUE);
|
||||
return editor_goto_pos(doc, pos, TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,11 +79,12 @@ static void setup_tab_dnd(void);
|
||||
|
||||
static void focus_sci(GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc != NULL)
|
||||
return;
|
||||
|
||||
gtk_widget_grab_focus(GTK_WIDGET(documents[idx]->sci));
|
||||
gtk_widget_grab_focus(GTK_WIDGET(doc->sci));
|
||||
}
|
||||
|
||||
|
||||
@ -308,26 +309,26 @@ gboolean notebook_tab_label_cb(GtkWidget *widget, GdkEventButton *event, gpointe
|
||||
on_menu_toggle_all_additional_widgets1_activate(NULL, NULL);
|
||||
/* close tab on middle click */
|
||||
if (event->button == 2)
|
||||
document_remove(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), GTK_WIDGET(user_data)));
|
||||
document_remove_page(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
GTK_WIDGET(user_data)));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* Returns page number of notebook page, or -1 on error */
|
||||
gint notebook_new_tab(gint doc_idx)
|
||||
gint notebook_new_tab(GeanyDocument *this)
|
||||
{
|
||||
GtkWidget *hbox, *ebox;
|
||||
gint tabnum;
|
||||
gchar *title;
|
||||
GeanyDocument *this = documents[doc_idx];
|
||||
Document *fdoc = DOCUMENT(this);
|
||||
GtkWidget *page;
|
||||
|
||||
g_return_val_if_fail(doc_idx >= 0 && this != NULL, -1);
|
||||
g_return_val_if_fail(this != NULL, -1);
|
||||
|
||||
page = GTK_WIDGET(this->sci);
|
||||
title = g_path_get_basename(DOC_FILENAME(doc_idx));
|
||||
title = g_path_get_basename(DOC_FILENAME(this));
|
||||
|
||||
fdoc->tab_label = gtk_label_new(title);
|
||||
|
||||
@ -404,7 +405,7 @@ notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data)
|
||||
gint cur_page = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
GTK_WIDGET(user_data));
|
||||
|
||||
document_remove(cur_page);
|
||||
document_remove_page(cur_page);
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
void notebook_init(void);
|
||||
|
||||
/* Returns page number of notebook page, or -1 on error */
|
||||
gint notebook_new_tab(gint doc_idx);
|
||||
gint notebook_new_tab(GeanyDocument *doc);
|
||||
|
||||
/* Always use this instead of gtk_notebook_remove_page(). */
|
||||
void notebook_remove_page(gint page_num);
|
||||
|
@ -427,9 +427,9 @@ NavQueueFuncs;
|
||||
/* See editor.h */
|
||||
typedef struct EditorFuncs
|
||||
{
|
||||
void (*set_indicator) (gint idx, gint start, gint end);
|
||||
void (*set_indicator_on_line) (gint idx, gint line);
|
||||
void (*clear_indicators) (gint idx);
|
||||
void (*set_indicator) (struct GeanyDocument *doc, gint start, gint end);
|
||||
void (*set_indicator_on_line) (struct GeanyDocument *doc, gint line);
|
||||
void (*clear_indicators) (struct GeanyDocument *doc);
|
||||
}
|
||||
EditorFuncs;
|
||||
|
||||
|
@ -94,19 +94,19 @@ static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data);
|
||||
|
||||
|
||||
static DocumentFuncs doc_funcs = {
|
||||
&documents_new_file,
|
||||
&document_new_file,
|
||||
&document_get_current,
|
||||
&document_get_from_page,
|
||||
&documents_find_by_filename,
|
||||
&documents_find_by_real_path,
|
||||
&documents_save_file,
|
||||
&documents_open_file,
|
||||
&document_find_by_filename,
|
||||
&document_find_by_real_path,
|
||||
&document_save_file,
|
||||
&document_open_file,
|
||||
&document_open_files,
|
||||
&document_remove_page,
|
||||
&documents_reload_file,
|
||||
&documents_set_encoding,
|
||||
&documents_set_text_changed,
|
||||
&documents_set_filetype
|
||||
&document_reload_file,
|
||||
&document_set_encoding,
|
||||
&document_set_text_changed,
|
||||
&document_set_filetype
|
||||
};
|
||||
|
||||
static EditorFuncs editor_funcs = {
|
||||
|
@ -825,7 +825,7 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
for (i = 0; i < documents_array->len; i++)
|
||||
{
|
||||
if (documents[i]->is_valid)
|
||||
editor_set_use_tabs(i, editor_prefs.use_tabs);
|
||||
editor_set_use_tabs(documents[i], editor_prefs.use_tabs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -979,12 +979,12 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
{
|
||||
if (documents[i]->is_valid)
|
||||
{
|
||||
document_apply_update_prefs(i);
|
||||
document_apply_update_prefs(documents[i]);
|
||||
if (! editor_prefs.folding)
|
||||
editor_unfold_all(i);
|
||||
editor_unfold_all(documents[i]);
|
||||
}
|
||||
}
|
||||
ui_document_show_hide(-1);
|
||||
ui_document_show_hide(NULL);
|
||||
|
||||
/* store all settings */
|
||||
configuration_save();
|
||||
|
@ -72,7 +72,7 @@ enum
|
||||
/* document-related variables */
|
||||
typedef struct
|
||||
{
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
gint font_width;
|
||||
gint lines;
|
||||
gint n_pages;
|
||||
@ -213,7 +213,7 @@ static gint get_page_count(GtkPrintContext *context, DocInfo *dinfo)
|
||||
gint lines = 1;
|
||||
gint line_width;
|
||||
|
||||
line_buf = sci_get_line(documents[dinfo->idx]->sci, j);
|
||||
line_buf = sci_get_line(dinfo->doc->sci, j);
|
||||
line_width = (g_utf8_strlen(line_buf, -1) + 1) * dinfo->font_width;
|
||||
if (line_width > width)
|
||||
lines = ceil(line_width / width);
|
||||
@ -240,8 +240,8 @@ static void add_page_header(PangoLayout *layout, cairo_t *cr, DocInfo *dinfo, gi
|
||||
gint ph_height = dinfo->line_height * 3;
|
||||
gchar *data;
|
||||
gchar *datetime;
|
||||
gchar *tmp_file_name = (documents[dinfo->idx]->file_name != NULL) ?
|
||||
documents[dinfo->idx]->file_name : GEANY_STRING_UNTITLED;
|
||||
gchar *tmp_file_name = (dinfo->doc->file_name != NULL) ?
|
||||
dinfo->doc->file_name : GEANY_STRING_UNTITLED;
|
||||
gchar *file_name = (printing_prefs.page_header_basename) ?
|
||||
g_path_get_basename(tmp_file_name) : g_strdup(tmp_file_name);
|
||||
|
||||
@ -418,7 +418,7 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
desc = pango_font_description_from_string(interface_prefs.editor_font);
|
||||
|
||||
/* init dinfo fields */
|
||||
dinfo->lines = sci_get_line_count(documents[dinfo->idx]->sci);
|
||||
dinfo->lines = sci_get_line_count(dinfo->doc->sci);
|
||||
dinfo->lines_per_page = 0;
|
||||
dinfo->cur_line = 0;
|
||||
dinfo->cur_pos = 0;
|
||||
@ -434,7 +434,7 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
dinfo->n_pages = get_page_count(context, dinfo);
|
||||
|
||||
/* read all styles from Scintilla */
|
||||
style_max = pow(2, scintilla_send_message(documents[dinfo->idx]->sci, SCI_GETSTYLEBITS, 0, 0));
|
||||
style_max = pow(2, scintilla_send_message(dinfo->doc->sci, SCI_GETSTYLEBITS, 0, 0));
|
||||
/* if the lexer uses only the first 32 styles(style bits = 5),
|
||||
* we need to add the pre-defined styles */
|
||||
if (style_max == 32)
|
||||
@ -442,21 +442,21 @@ static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
for (i = 0; i < style_max; i++)
|
||||
{
|
||||
dinfo->styles[i][FORE] = ROTATE_RGB(scintilla_send_message(
|
||||
documents[dinfo->idx]->sci, SCI_STYLEGETFORE, i, 0));
|
||||
dinfo->doc->sci, SCI_STYLEGETFORE, i, 0));
|
||||
if (i == STYLE_LINENUMBER)
|
||||
{ /* ignore background colour for line number margin to avoid trouble with wrapped lines */
|
||||
dinfo->styles[STYLE_LINENUMBER][BACK] = ROTATE_RGB(scintilla_send_message(
|
||||
documents[dinfo->idx]->sci, SCI_STYLEGETBACK, STYLE_DEFAULT, 0));
|
||||
dinfo->doc->sci, SCI_STYLEGETBACK, STYLE_DEFAULT, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
dinfo->styles[i][BACK] = ROTATE_RGB(scintilla_send_message(
|
||||
documents[dinfo->idx]->sci, SCI_STYLEGETBACK, i, 0));
|
||||
dinfo->doc->sci, SCI_STYLEGETBACK, i, 0));
|
||||
}
|
||||
dinfo->styles[i][BOLD] =
|
||||
scintilla_send_message(documents[dinfo->idx]->sci, SCI_STYLEGETBOLD, i, 0);
|
||||
scintilla_send_message(dinfo->doc->sci, SCI_STYLEGETBOLD, i, 0);
|
||||
dinfo->styles[i][ITALIC] =
|
||||
scintilla_send_message(documents[dinfo->idx]->sci, SCI_STYLEGETITALIC, i, 0);
|
||||
scintilla_send_message(dinfo->doc->sci, SCI_STYLEGETITALIC, i, 0);
|
||||
}
|
||||
|
||||
if (dinfo->n_pages >= 0)
|
||||
@ -550,8 +550,8 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
/* data */
|
||||
else
|
||||
{
|
||||
style = sci_get_style_at(documents[dinfo->idx]->sci, dinfo->cur_pos);
|
||||
c = sci_get_char_at(documents[dinfo->idx]->sci, dinfo->cur_pos);
|
||||
style = sci_get_style_at(dinfo->doc->sci, dinfo->cur_pos);
|
||||
c = sci_get_char_at(dinfo->doc->sci, dinfo->cur_pos);
|
||||
if (c == '\0' || style == -1)
|
||||
{ /* if c gets 0, we are probably out of document boundaries,
|
||||
* so stop to break out of outer loop */
|
||||
@ -560,7 +560,6 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
}
|
||||
dinfo->cur_pos++;
|
||||
|
||||
|
||||
/* convert tabs to spaces which seems to be better than using Pango tabs */
|
||||
if (c == '\t')
|
||||
{
|
||||
@ -571,7 +570,7 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
/* don't add line breaks, they are handled manually below */
|
||||
else if (c == '\r' || c == '\n')
|
||||
{
|
||||
gchar c_next = sci_get_char_at(documents[dinfo->idx]->sci, dinfo->cur_pos);
|
||||
gchar c_next = sci_get_char_at(dinfo->doc->sci, dinfo->cur_pos);
|
||||
at_eol = TRUE;
|
||||
if (c == '\r' && c_next == '\n')
|
||||
dinfo->cur_pos++; /* skip LF part of CR/LF */
|
||||
@ -587,7 +586,7 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
|
||||
* style doesn't change since it is only one character with multiple bytes. */
|
||||
while (c < 0)
|
||||
{
|
||||
c = sci_get_char_at(documents[dinfo->idx]->sci, dinfo->cur_pos);
|
||||
c = sci_get_char_at(dinfo->doc->sci, dinfo->cur_pos);
|
||||
if (c < 0)
|
||||
{ /* only add the byte when it is part of the UTF-8 character
|
||||
* otherwise we could add e.g. a '\n' and it won't be visible in the
|
||||
@ -731,7 +730,7 @@ static void status_changed(GtkPrintOperation *op, gpointer data)
|
||||
}
|
||||
|
||||
|
||||
static void printing_print_gtk(gint idx)
|
||||
static void printing_print_gtk(GeanyDocument *doc)
|
||||
{
|
||||
GtkPrintOperation *op;
|
||||
GtkPrintOperationResult res = GTK_PRINT_OPERATION_RESULT_ERROR;
|
||||
@ -745,7 +744,7 @@ static void printing_print_gtk(gint idx)
|
||||
widgets = g_new0(PrintWidgets, 1);
|
||||
dinfo = g_new0(DocInfo, 1);
|
||||
/* all other fields are initialised in begin_print() */
|
||||
dinfo->idx = idx;
|
||||
dinfo->doc = doc;
|
||||
|
||||
op = gtk_print_operation_new();
|
||||
|
||||
@ -755,7 +754,7 @@ static void printing_print_gtk(gint idx)
|
||||
g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), dinfo);
|
||||
g_signal_connect(op, "end-print", G_CALLBACK(end_print), dinfo);
|
||||
g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), dinfo);
|
||||
g_signal_connect(op, "status-changed", G_CALLBACK(status_changed), documents[idx]->file_name);
|
||||
g_signal_connect(op, "status-changed", G_CALLBACK(status_changed), doc->file_name);
|
||||
g_signal_connect(op, "create-custom-widget", G_CALLBACK(create_custom_widget), widgets);
|
||||
g_signal_connect(op, "custom-widget-apply", G_CALLBACK(custom_widget_apply), widgets);
|
||||
|
||||
@ -777,7 +776,7 @@ static void printing_print_gtk(gint idx)
|
||||
else if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
|
||||
{
|
||||
dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of %s failed (%s)."),
|
||||
documents[idx]->file_name, error->message);
|
||||
doc->file_name, error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
@ -806,11 +805,11 @@ void printing_page_setup_gtk(void)
|
||||
|
||||
|
||||
/* simple file print using an external tool */
|
||||
static void print_external(gint idx)
|
||||
static void print_external(GeanyDocument *doc)
|
||||
{
|
||||
gchar *cmdline;
|
||||
|
||||
if (documents[idx]->file_name == NULL)
|
||||
if (doc->file_name == NULL)
|
||||
return;
|
||||
|
||||
if (! NZV(printing_prefs.external_print_cmd))
|
||||
@ -821,11 +820,11 @@ static void print_external(gint idx)
|
||||
}
|
||||
|
||||
cmdline = g_strdup(printing_prefs.external_print_cmd);
|
||||
cmdline = utils_str_replace(cmdline, "%f", documents[idx]->file_name);
|
||||
cmdline = utils_str_replace(cmdline, "%f", doc->file_name);
|
||||
|
||||
if (dialogs_show_question(
|
||||
_("The file \"%s\" will be printed with the following command:\n\n%s"),
|
||||
documents[idx]->file_name, cmdline))
|
||||
doc->file_name, cmdline))
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
@ -841,12 +840,12 @@ static void print_external(gint idx)
|
||||
{
|
||||
dialogs_show_msgbox(GTK_MESSAGE_ERROR,
|
||||
_("Printing of \"%s\" failed (return code: %s)."),
|
||||
documents[idx]->file_name, error->message);
|
||||
doc->file_name, error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgwin_status_add(_("File %s printed."), documents[idx]->file_name);
|
||||
msgwin_status_add(_("File %s printed."), doc->file_name);
|
||||
}
|
||||
g_free(tmp_cmdline);
|
||||
}
|
||||
@ -854,16 +853,16 @@ static void print_external(gint idx)
|
||||
}
|
||||
|
||||
|
||||
void printing_print_doc(gint idx)
|
||||
void printing_print_doc(GeanyDocument *doc)
|
||||
{
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
#if GTK_CHECK_VERSION(2, 10, 0)
|
||||
if (gtk_check_version(2, 10, 0) == NULL && printing_prefs.use_gtk_printing)
|
||||
printing_print_gtk(idx);
|
||||
printing_print_gtk(doc);
|
||||
else
|
||||
#endif
|
||||
print_external(idx);
|
||||
print_external(doc);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,6 @@ extern PrintingPrefs printing_prefs;
|
||||
void printing_page_setup_gtk(void);
|
||||
#endif
|
||||
|
||||
void printing_print_doc(gint idx);
|
||||
void printing_print_doc(GeanyDocument *doc);
|
||||
|
||||
#endif
|
||||
|
@ -297,8 +297,8 @@ void project_open()
|
||||
/* Called when opening, closing and updating projects. */
|
||||
static void update_ui(void)
|
||||
{
|
||||
ui_set_window_title(-1);
|
||||
build_menu_update(-1);
|
||||
ui_set_window_title(NULL);
|
||||
build_menu_update(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
119
src/search.c
119
src/search.c
@ -227,14 +227,14 @@ static void setup_find_next(const gchar *text)
|
||||
* the scintilla selection or current token instead.
|
||||
* Search flags are always zero.
|
||||
*/
|
||||
void search_find_selection(gint idx, gboolean search_backwards)
|
||||
void search_find_selection(GeanyDocument *doc, gboolean search_backwards)
|
||||
{
|
||||
gchar *s = NULL;
|
||||
#ifdef G_OS_UNIX
|
||||
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
|
||||
#endif
|
||||
|
||||
g_return_if_fail(DOC_IDX_VALID(idx));
|
||||
g_return_if_fail(doc == NULL);
|
||||
|
||||
#ifdef G_OS_UNIX
|
||||
s=gtk_clipboard_wait_for_text(clipboard);
|
||||
@ -249,14 +249,14 @@ void search_find_selection(gint idx, gboolean search_backwards)
|
||||
#endif
|
||||
|
||||
if (!s)
|
||||
s=editor_get_default_selection(idx, TRUE, NULL);
|
||||
s=editor_get_default_selection(doc, TRUE, NULL);
|
||||
|
||||
if (s)
|
||||
{
|
||||
setup_find_next(s); /* allow find next/prev */
|
||||
|
||||
if (document_find_text(idx, s, 0, search_backwards, FALSE, NULL) > -1)
|
||||
editor_display_current_line(idx, 0.3F);
|
||||
if (document_find_text(doc, s, 0, search_backwards, FALSE, NULL) > -1)
|
||||
editor_display_current_line(doc, 0.3F);
|
||||
g_free(s);
|
||||
}
|
||||
}
|
||||
@ -286,12 +286,12 @@ static void load_monospace_style()
|
||||
|
||||
void search_show_find_dialog(void)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gchar *sel = NULL;
|
||||
|
||||
g_return_if_fail(DOC_IDX_VALID(idx));
|
||||
g_return_if_fail(doc != NULL);
|
||||
|
||||
sel = editor_get_default_selection(idx, search_prefs.use_current_word, NULL);
|
||||
sel = editor_get_default_selection(doc, search_prefs.use_current_word, NULL);
|
||||
|
||||
if (widgets.find_dialog == NULL)
|
||||
{
|
||||
@ -407,12 +407,13 @@ static void send_replace_dialog_response(GtkButton *button, gpointer user_data)
|
||||
|
||||
void search_show_replace_dialog(void)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gchar *sel = NULL;
|
||||
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
sel = editor_get_default_selection(idx, search_prefs.use_current_word, NULL);
|
||||
sel = editor_get_default_selection(doc, search_prefs.use_current_word, NULL);
|
||||
|
||||
if (widgets.replace_dialog == NULL)
|
||||
{
|
||||
@ -559,7 +560,7 @@ void search_show_find_in_files_dialog(const gchar *dir)
|
||||
static GtkWidget *combo = NULL;
|
||||
static GtkWidget *dir_combo;
|
||||
GtkWidget *entry; /* the child GtkEntry of combo (or dir_combo) */
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gchar *sel = NULL;
|
||||
gchar *cur_dir;
|
||||
|
||||
@ -711,13 +712,13 @@ void search_show_find_in_files_dialog(const gchar *dir)
|
||||
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
gtk_widget_show_all(widgets.find_in_files_dialog);
|
||||
sel = editor_get_default_selection(idx, search_prefs.use_current_word, NULL);
|
||||
sel = editor_get_default_selection(doc, search_prefs.use_current_word, 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 = editor_get_default_selection(idx, search_prefs.use_current_word, NULL);
|
||||
sel = editor_get_default_selection(doc, search_prefs.use_current_word, NULL);
|
||||
if (sel)
|
||||
gtk_entry_set_text(GTK_ENTRY(entry), sel);
|
||||
g_free(sel);
|
||||
@ -790,23 +791,23 @@ on_find_replace_checkbutton_toggled(GtkToggleButton *togglebutton, gpointer user
|
||||
}
|
||||
|
||||
|
||||
static gint search_mark(gint idx, const gchar *search_text, gint flags)
|
||||
static gint search_mark(GeanyDocument *doc, const gchar *search_text, gint flags)
|
||||
{
|
||||
gint pos, line, count = 0;
|
||||
struct TextToFind ttf;
|
||||
|
||||
g_return_val_if_fail(DOC_IDX_VALID(idx), 0);
|
||||
g_return_val_if_fail(doc != NULL, 0);
|
||||
|
||||
ttf.chrg.cpMin = 0;
|
||||
ttf.chrg.cpMax = sci_get_length(documents[idx]->sci);
|
||||
ttf.chrg.cpMax = sci_get_length(doc->sci);
|
||||
ttf.lpstrText = (gchar *)search_text;
|
||||
while (1)
|
||||
{
|
||||
pos = sci_find_text(documents[idx]->sci, flags, &ttf);
|
||||
pos = sci_find_text(doc->sci, flags, &ttf);
|
||||
if (pos == -1) break;
|
||||
|
||||
line = sci_get_line_from_position(documents[idx]->sci, pos);
|
||||
sci_set_marker_at_line(documents[idx]->sci, line, TRUE, 1);
|
||||
line = sci_get_line_from_position(doc->sci, pos);
|
||||
sci_set_marker_at_line(doc->sci, line, TRUE, 1);
|
||||
|
||||
ttf.chrg.cpMin = ttf.chrgText.cpMax + 1;
|
||||
count++;
|
||||
@ -850,7 +851,7 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
gtk_widget_hide(widgets.find_dialog);
|
||||
else
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gboolean search_replace_escape;
|
||||
gboolean check_close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||
lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_close")));
|
||||
@ -860,7 +861,8 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
search_data.backwards = FALSE;
|
||||
search_data.search_bar = FALSE;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (DOC_VALID(doc))
|
||||
return;
|
||||
|
||||
g_free(search_data.text);
|
||||
search_data.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))));
|
||||
@ -880,7 +882,7 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
{
|
||||
case GEANY_RESPONSE_FIND:
|
||||
case GEANY_RESPONSE_FIND_PREVIOUS:
|
||||
document_find_text(idx, search_data.text, search_data.flags,
|
||||
document_find_text(doc, search_data.text, search_data.flags,
|
||||
(response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE, GTK_WIDGET(widgets.find_dialog));
|
||||
check_close = FALSE;
|
||||
if (search_prefs.suppress_dialogs)
|
||||
@ -896,19 +898,18 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
break;
|
||||
|
||||
case GEANY_RESPONSE_MARK:
|
||||
if (DOC_IDX_VALID(idx))
|
||||
{
|
||||
gint count = search_mark(idx, search_data.text, search_data.flags);
|
||||
{
|
||||
gint count = search_mark(doc, search_data.text, search_data.flags);
|
||||
|
||||
if (count == 0)
|
||||
ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), search_data.text);
|
||||
else
|
||||
ui_set_statusbar(FALSE,
|
||||
ngettext("Found %d match for \"%s\".",
|
||||
"Found %d matches for \"%s\".", count),
|
||||
count, search_data.text);
|
||||
}
|
||||
break;
|
||||
if (count == 0)
|
||||
ui_set_statusbar(FALSE, _("No matches found for \"%s\"."), search_data.text);
|
||||
else
|
||||
ui_set_statusbar(FALSE,
|
||||
ngettext("Found %d match for \"%s\".",
|
||||
"Found %d matches for \"%s\".", count),
|
||||
count, search_data.text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (check_close)
|
||||
gtk_widget_hide(widgets.find_dialog);
|
||||
@ -926,7 +927,7 @@ on_replace_entry_activate(GtkEntry *entry, gpointer user_data)
|
||||
static void
|
||||
on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
GtkWidget *entry_find = lookup_widget(GTK_WIDGET(widgets.replace_dialog), "entry_find");
|
||||
GtkWidget *entry_replace = lookup_widget(GTK_WIDGET(widgets.replace_dialog), "entry_replace");
|
||||
gint search_flags_re;
|
||||
@ -974,28 +975,28 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
{
|
||||
case GEANY_RESPONSE_REPLACE_AND_FIND:
|
||||
{
|
||||
gint rep = document_replace_text(idx, find, replace, search_flags_re,
|
||||
gint rep = document_replace_text(doc, find, replace, search_flags_re,
|
||||
search_backwards_re);
|
||||
if (rep != -1)
|
||||
document_find_text(idx, find, search_flags_re, search_backwards_re,
|
||||
document_find_text(doc, find, search_flags_re, search_backwards_re,
|
||||
TRUE, NULL);
|
||||
break;
|
||||
}
|
||||
case GEANY_RESPONSE_REPLACE:
|
||||
{
|
||||
document_replace_text(idx, find, replace, search_flags_re,
|
||||
document_replace_text(doc, find, replace, search_flags_re,
|
||||
search_backwards_re);
|
||||
break;
|
||||
}
|
||||
case GEANY_RESPONSE_FIND:
|
||||
{
|
||||
document_find_text(idx, find, search_flags_re, search_backwards_re, TRUE,
|
||||
document_find_text(doc, find, search_flags_re, search_backwards_re, TRUE,
|
||||
GTK_WIDGET(dialog));
|
||||
break;
|
||||
}
|
||||
case GEANY_RESPONSE_REPLACE_IN_FILE:
|
||||
{
|
||||
if (! document_replace_all(idx, find, replace, search_flags_re,
|
||||
if (! document_replace_all(doc, find, replace, search_flags_re,
|
||||
search_replace_escape_re))
|
||||
{
|
||||
utils_beep();
|
||||
@ -1009,11 +1010,11 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
/* replace in all documents following notebook tab order */
|
||||
for (n = 0; (gint) n < gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); n++)
|
||||
{
|
||||
gint ix = document_get_n_idx(n);
|
||||
GeanyDocument *tmp_doc = document_get_from_page(n);
|
||||
|
||||
if (! documents[ix]->is_valid) continue;
|
||||
if (! tmp_doc->is_valid) continue;
|
||||
|
||||
if (document_replace_all(ix, find, replace, search_flags_re,
|
||||
if (document_replace_all(tmp_doc, find, replace, search_flags_re,
|
||||
search_replace_escape_re)) count++;
|
||||
}
|
||||
if (count == 0)
|
||||
@ -1025,12 +1026,12 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
/* show which docs had replacements: */
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_STATUS);
|
||||
|
||||
ui_save_buttons_toggle(documents[idx]->changed); /* update save all */
|
||||
ui_save_buttons_toggle(doc->changed); /* update save all */
|
||||
break;
|
||||
}
|
||||
case GEANY_RESPONSE_REPLACE_IN_SEL:
|
||||
{
|
||||
document_replace_sel(idx, find, replace, search_flags_re, search_replace_escape_re);
|
||||
document_replace_sel(doc, find, replace, search_flags_re, search_replace_escape_re);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1349,24 +1350,24 @@ static void search_close_pid(GPid child_pid, gint status, gpointer user_data)
|
||||
}
|
||||
|
||||
|
||||
static gint find_document_usage(gint idx, const gchar *search_text, gint flags)
|
||||
static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, gint flags)
|
||||
{
|
||||
gchar *buffer, *short_file_name;
|
||||
struct TextToFind ttf;
|
||||
gint count = 0;
|
||||
|
||||
g_return_val_if_fail(DOC_IDX_VALID(idx), 0);
|
||||
g_return_val_if_fail(doc != NULL, 0);
|
||||
|
||||
short_file_name = g_path_get_basename(DOC_FILENAME(idx));
|
||||
short_file_name = g_path_get_basename(DOC_FILENAME(doc));
|
||||
|
||||
ttf.chrg.cpMin = 0;
|
||||
ttf.chrg.cpMax = sci_get_length(documents[idx]->sci);
|
||||
ttf.chrg.cpMax = sci_get_length(doc->sci);
|
||||
ttf.lpstrText = (gchar *)search_text;
|
||||
while (1)
|
||||
{
|
||||
gint pos, line, start, find_len;
|
||||
|
||||
pos = sci_find_text(documents[idx]->sci, flags, &ttf);
|
||||
pos = sci_find_text(doc->sci, flags, &ttf);
|
||||
if (pos == -1)
|
||||
break; /* no more matches */
|
||||
find_len = ttf.chrgText.cpMax - ttf.chrgText.cpMin;
|
||||
@ -1374,9 +1375,9 @@ static gint find_document_usage(gint idx, const gchar *search_text, gint flags)
|
||||
break; /* Ignore regex ^ or $ */
|
||||
|
||||
count++;
|
||||
line = sci_get_line_from_position(documents[idx]->sci, pos);
|
||||
buffer = sci_get_line(documents[idx]->sci, line);
|
||||
msgwin_msg_add_fmt(COLOR_BLACK, line + 1, documents[idx],
|
||||
line = sci_get_line_from_position(doc->sci, pos);
|
||||
buffer = sci_get_line(doc->sci, line);
|
||||
msgwin_msg_add_fmt(COLOR_BLACK, line + 1, doc,
|
||||
"%s:%d : %s", short_file_name, line + 1, g_strstrip(buffer));
|
||||
g_free(buffer);
|
||||
|
||||
@ -1390,18 +1391,18 @@ static gint find_document_usage(gint idx, const gchar *search_text, gint flags)
|
||||
|
||||
void search_find_usage(const gchar *search_text, gint flags, gboolean in_session)
|
||||
{
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
gboolean found = FALSE;
|
||||
|
||||
idx = document_get_cur_idx();
|
||||
g_return_if_fail(DOC_IDX_VALID(idx));
|
||||
doc = document_get_current();
|
||||
g_return_if_fail(doc != NULL);
|
||||
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_MESSAGE);
|
||||
gtk_list_store_clear(msgwindow.store_msg);
|
||||
|
||||
if (! in_session)
|
||||
{ /* use current document */
|
||||
found = (find_document_usage(idx, search_text, flags) > 0);
|
||||
found = (find_document_usage(doc, search_text, flags) > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1409,7 +1410,7 @@ void search_find_usage(const gchar *search_text, gint flags, gboolean in_session
|
||||
for (i = 0; i < documents_array->len; i++)
|
||||
{
|
||||
if (documents[i]->is_valid)
|
||||
if (find_document_usage(i, search_text, flags) > 0) found = TRUE;
|
||||
if (find_document_usage(documents[i], search_text, flags) > 0) found = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,6 @@ void search_show_find_in_files_dialog(const gchar *dir);
|
||||
|
||||
void search_find_usage(const gchar *search_text, gint flags, gboolean in_session);
|
||||
|
||||
void search_find_selection(gint idx, gboolean search_backwards);
|
||||
void search_find_selection(GeanyDocument *doc, gboolean search_backwards);
|
||||
|
||||
#endif
|
||||
|
@ -499,11 +499,11 @@ gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpoint
|
||||
document_open_file(buf, FALSE, NULL, NULL);
|
||||
else
|
||||
{ /* create new file if it doesn't exist */
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
|
||||
idx = document_new_file(buf, NULL, NULL);
|
||||
if (DOC_IDX_VALID(idx))
|
||||
ui_add_recent_file(documents[idx]->file_name);
|
||||
doc = document_new_file(buf, NULL, NULL);
|
||||
if (doc != NULL)
|
||||
ui_add_recent_file(doc->file_name);
|
||||
else
|
||||
geany_debug("got data from socket, but it does not look like a filename");
|
||||
}
|
||||
|
@ -400,12 +400,12 @@ static gint compare_symbol_lines(const GeanySymbol *a, const GeanySymbol *b)
|
||||
}
|
||||
|
||||
|
||||
static const GList *get_tag_list(gint idx, guint tag_types, gint sort_mode)
|
||||
static const GList *get_tag_list(GeanyDocument *doc, guint tag_types, gint sort_mode)
|
||||
{
|
||||
static GList *tag_names = NULL;
|
||||
|
||||
if (DOC_IDX_VALID(idx) && documents[idx]->tm_file &&
|
||||
documents[idx]->tm_file->tags_array)
|
||||
if (doc != NULL && doc->tm_file &&
|
||||
doc->tm_file->tags_array)
|
||||
{
|
||||
TMTag *tag;
|
||||
guint i;
|
||||
@ -413,7 +413,7 @@ static const GList *get_tag_list(gint idx, guint tag_types, gint sort_mode)
|
||||
gboolean doc_is_utf8 = FALSE;
|
||||
gchar *utf8_name;
|
||||
const gchar *cosep =
|
||||
symbols_get_context_separator(FILETYPE_ID(documents[idx]->file_type));
|
||||
symbols_get_context_separator(FILETYPE_ID(doc->file_type));
|
||||
|
||||
if (tag_names)
|
||||
{
|
||||
@ -429,20 +429,20 @@ static const GList *get_tag_list(gint idx, guint tag_types, gint sort_mode)
|
||||
|
||||
/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
|
||||
* for None at this point completely */
|
||||
if (utils_str_equal(documents[idx]->encoding, "UTF-8") ||
|
||||
utils_str_equal(documents[idx]->encoding, "None"))
|
||||
if (utils_str_equal(doc->encoding, "UTF-8") ||
|
||||
utils_str_equal(doc->encoding, "None"))
|
||||
doc_is_utf8 = TRUE;
|
||||
|
||||
for (i = 0; i < (documents[idx]->tm_file)->tags_array->len; ++i)
|
||||
for (i = 0; i < (doc->tm_file)->tags_array->len; ++i)
|
||||
{
|
||||
tag = TM_TAG((documents[idx]->tm_file)->tags_array->pdata[i]);
|
||||
tag = TM_TAG((doc->tm_file)->tags_array->pdata[i]);
|
||||
if (tag == NULL)
|
||||
return NULL;
|
||||
|
||||
if (tag->type & tag_types)
|
||||
{
|
||||
if (! doc_is_utf8) utf8_name = encodings_convert_to_utf8_from_charset(tag->name,
|
||||
(gsize)-1, documents[idx]->encoding, TRUE);
|
||||
(gsize)-1, doc->encoding, TRUE);
|
||||
else utf8_name = tag->name;
|
||||
|
||||
if (utf8_name == NULL)
|
||||
@ -562,10 +562,10 @@ tag_list_add_groups(GtkTreeStore *tree_store, ...)
|
||||
}
|
||||
|
||||
|
||||
static void init_tag_list(gint idx)
|
||||
static void init_tag_list(GeanyDocument *doc)
|
||||
{
|
||||
filetype_id ft_id = documents[idx]->file_type->id;
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
filetype_id ft_id = doc->file_type->id;
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
GtkTreeStore *tag_store = fdoc->tag_store;
|
||||
|
||||
init_tag_iters();
|
||||
@ -837,24 +837,27 @@ static void hide_empty_rows(GtkTreeStore *store)
|
||||
}
|
||||
|
||||
|
||||
gboolean symbols_recreate_tag_list(gint idx, gint sort_mode)
|
||||
gboolean symbols_recreate_tag_list(GeanyDocument *doc, gint sort_mode)
|
||||
{
|
||||
GList *tmp;
|
||||
const GList *tags;
|
||||
GtkTreeIter iter;
|
||||
static gint prev_sort_mode = SYMBOLS_SORT_BY_NAME;
|
||||
filetype_id ft_id = FILETYPE_ID(documents[idx]->file_type);
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
filetype_id ft_id;
|
||||
Document *fdoc;
|
||||
|
||||
g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE);
|
||||
g_return_val_if_fail(DOC_VALID(doc), FALSE);
|
||||
|
||||
ft_id = FILETYPE_ID(doc->file_type);
|
||||
fdoc = DOCUMENT(doc);
|
||||
|
||||
if (sort_mode == SYMBOLS_SORT_USE_PREVIOUS)
|
||||
sort_mode = prev_sort_mode;
|
||||
else
|
||||
prev_sort_mode = sort_mode;
|
||||
|
||||
tags = get_tag_list(idx, tm_tag_max_t, sort_mode);
|
||||
if (documents[idx]->tm_file == NULL || tags == NULL)
|
||||
tags = get_tag_list(doc, tm_tag_max_t, sort_mode);
|
||||
if (doc->tm_file == NULL || tags == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Make sure the model stays with us after the tree view unrefs it */
|
||||
@ -864,7 +867,7 @@ gboolean symbols_recreate_tag_list(gint idx, gint sort_mode)
|
||||
/* Clear all contents */
|
||||
gtk_tree_store_clear(fdoc->tag_store);
|
||||
|
||||
init_tag_list(idx);
|
||||
init_tag_list(doc);
|
||||
for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp))
|
||||
{
|
||||
gchar buf[100];
|
||||
@ -1182,14 +1185,14 @@ gboolean symbols_goto_tag(const gchar *name, gboolean definition)
|
||||
const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t;
|
||||
gint type;
|
||||
TMTag *tmtag = NULL;
|
||||
gint old_idx = document_get_cur_idx();
|
||||
GeanyDocument *old_doc = document_get_current();
|
||||
|
||||
/* goto tag definition: all except prototypes / forward declarations / externs */
|
||||
type = (definition) ? tm_tag_max_t - forward_types : forward_types;
|
||||
|
||||
/* first look in the current document */
|
||||
if (documents[old_idx]->tm_file)
|
||||
tmtag = find_work_object_tag(documents[old_idx]->tm_file, name, type);
|
||||
if (old_doc != NULL && old_doc->tm_file)
|
||||
tmtag = find_work_object_tag(old_doc->tm_file, name, type);
|
||||
|
||||
/* if not found, look in the workspace */
|
||||
if (tmtag == NULL)
|
||||
@ -1197,16 +1200,16 @@ gboolean symbols_goto_tag(const gchar *name, gboolean definition)
|
||||
|
||||
if (tmtag != NULL)
|
||||
{
|
||||
gint new_idx = document_find_by_real_path(
|
||||
GeanyDocument *new_doc = document_find_by_real_path(
|
||||
tmtag->atts.entry.file->work_object.file_name);
|
||||
|
||||
/* not found in opened document, should open */
|
||||
if (new_idx == -1)
|
||||
if (new_doc == NULL)
|
||||
{
|
||||
new_idx = document_open_file(tmtag->atts.entry.file->work_object.file_name, FALSE, NULL, NULL);
|
||||
new_doc = document_open_file(tmtag->atts.entry.file->work_object.file_name, FALSE, NULL, NULL);
|
||||
}
|
||||
|
||||
if (navqueue_goto_line(documents[old_idx], documents[new_idx], tmtag->atts.entry.line))
|
||||
if (navqueue_goto_line(old_doc, new_doc, tmtag->atts.entry.line))
|
||||
return TRUE;
|
||||
}
|
||||
/* if we are here, there was no match and we are beeping ;-) */
|
||||
|
@ -41,7 +41,7 @@ GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types, gin
|
||||
|
||||
const gchar *symbols_get_context_separator(gint ft_id);
|
||||
|
||||
const GList *symbols_get_tag_list(gint idx, guint tag_types);
|
||||
const GList *symbols_get_tag_list(GeanyDocument *doc, guint tag_types);
|
||||
|
||||
GString *symbols_get_macro_list(void);
|
||||
|
||||
@ -49,7 +49,7 @@ const gchar **symbols_get_html_entities(void);
|
||||
|
||||
void symbols_finalize(void);
|
||||
|
||||
gboolean symbols_recreate_tag_list(gint idx, gint sort_mode);
|
||||
gboolean symbols_recreate_tag_list(GeanyDocument *doc, gint sort_mode);
|
||||
|
||||
gint symbols_generate_global_tags(gint argc, gchar **argv, gboolean want_preprocess);
|
||||
|
||||
|
54
src/tools.c
54
src/tools.c
@ -164,7 +164,7 @@ static gboolean cc_iofunc_err(GIOChannel *ioc, GIOCondition cond, gpointer data)
|
||||
|
||||
static gboolean cc_replace_sel_cb(gpointer user_data)
|
||||
{
|
||||
gint idx = GPOINTER_TO_INT(user_data);
|
||||
GeanyDocument *doc = user_data;
|
||||
|
||||
if (! cc_reading_finished)
|
||||
{ /* keep this function in the main loop until cc_iofunc_err() has finished */
|
||||
@ -173,7 +173,7 @@ static gboolean cc_replace_sel_cb(gpointer user_data)
|
||||
|
||||
if (! cc_error_occurred && cc_buffer != NULL)
|
||||
{ /* Command completed successfully */
|
||||
sci_replace_sel(documents[idx]->sci, cc_buffer->str);
|
||||
sci_replace_sel(doc->sci, cc_buffer->str);
|
||||
g_string_free(cc_buffer, TRUE);
|
||||
cc_buffer = NULL;
|
||||
}
|
||||
@ -227,7 +227,7 @@ static void cc_exit_cb(GPid child_pid, gint status, gpointer user_data)
|
||||
/* Executes command (which should include all necessary command line args) and passes the current
|
||||
* selection through the standard input of command. The whole output of command replaces the
|
||||
* current selection. */
|
||||
void tools_execute_custom_command(gint idx, const gchar *command)
|
||||
void tools_execute_custom_command(GeanyDocument *doc, const gchar *command)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GPid pid;
|
||||
@ -236,9 +236,9 @@ void tools_execute_custom_command(gint idx, const gchar *command)
|
||||
gint stdout_fd;
|
||||
gint stderr_fd;
|
||||
|
||||
g_return_if_fail(DOC_IDX_VALID(idx) && command != NULL);
|
||||
g_return_if_fail(doc != NULL && command != NULL);
|
||||
|
||||
if (! sci_can_copy(documents[idx]->sci))
|
||||
if (! sci_can_copy(doc->sci))
|
||||
return;
|
||||
|
||||
argv = g_strsplit(command, " ", -1);
|
||||
@ -253,7 +253,7 @@ void tools_execute_custom_command(gint idx, const gchar *command)
|
||||
gint len, remaining, wrote;
|
||||
|
||||
if (pid > 0)
|
||||
g_child_watch_add(pid, (GChildWatchFunc) cc_exit_cb, GINT_TO_POINTER(idx));
|
||||
g_child_watch_add(pid, (GChildWatchFunc) cc_exit_cb, doc);
|
||||
|
||||
/* use GIOChannel to monitor stdout */
|
||||
utils_set_up_io_channel(stdout_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
|
||||
@ -263,9 +263,9 @@ void tools_execute_custom_command(gint idx, const gchar *command)
|
||||
FALSE, cc_iofunc_err, (gpointer)command);
|
||||
|
||||
/* get selection */
|
||||
len = sci_get_selected_text_length(documents[idx]->sci);
|
||||
len = sci_get_selected_text_length(doc->sci);
|
||||
sel = g_malloc0(len + 1);
|
||||
sci_get_selected_text(documents[idx]->sci, sel);
|
||||
sci_get_selected_text(doc->sci, sel);
|
||||
|
||||
/* write data to the command */
|
||||
remaining = len - 1;
|
||||
@ -396,14 +396,15 @@ static void cc_show_dialog_custom_commands(void)
|
||||
/* enable or disable all custom command menu items when the sub menu is opened */
|
||||
static void cc_on_custom_command_menu_activate(GtkMenuItem *menuitem, gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gint i, len;
|
||||
gboolean enable;
|
||||
GList *children;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
enable = sci_can_copy(documents[idx]->sci) && (ui_prefs.custom_commands != NULL);
|
||||
enable = sci_can_copy(doc->sci) && (ui_prefs.custom_commands != NULL);
|
||||
|
||||
children = gtk_container_get_children(GTK_CONTAINER(user_data));
|
||||
len = g_list_length(children);
|
||||
@ -422,10 +423,11 @@ static void cc_on_custom_command_menu_activate(GtkMenuItem *menuitem, gpointer u
|
||||
|
||||
static void cc_on_custom_command_activate(GtkMenuItem *menuitem, gpointer user_data)
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gint command_idx;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
command_idx = GPOINTER_TO_INT(user_data);
|
||||
|
||||
@ -438,7 +440,7 @@ static void cc_on_custom_command_activate(GtkMenuItem *menuitem, gpointer user_d
|
||||
|
||||
/* send it through the command and when the command returned the output the current selection
|
||||
* will be replaced */
|
||||
tools_execute_custom_command(idx, ui_prefs.custom_commands[command_idx]);
|
||||
tools_execute_custom_command(doc, ui_prefs.custom_commands[command_idx]);
|
||||
}
|
||||
|
||||
|
||||
@ -600,12 +602,13 @@ static void word_count(gchar *text, guint *chars, guint *lines, guint *words)
|
||||
void tools_word_count(void)
|
||||
{
|
||||
GtkWidget *dialog, *label, *vbox, *table;
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
guint chars = 0, lines = 0, words = 0;
|
||||
gchar *text, *range;
|
||||
|
||||
idx = document_get_cur_idx();
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
doc = document_get_current();
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons(_("Word Count"), GTK_WINDOW(main_widgets.window),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
@ -613,16 +616,16 @@ void tools_word_count(void)
|
||||
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
|
||||
gtk_widget_set_name(dialog, "GeanyDialog");
|
||||
|
||||
if (sci_can_copy(documents[idx]->sci))
|
||||
if (sci_can_copy(doc->sci))
|
||||
{
|
||||
text = g_malloc0(sci_get_selected_text_length(documents[idx]->sci) + 1);
|
||||
sci_get_selected_text(documents[idx]->sci, text);
|
||||
text = g_malloc0(sci_get_selected_text_length(doc->sci) + 1);
|
||||
sci_get_selected_text(doc->sci, text);
|
||||
range = _("selection");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = g_malloc(sci_get_length(documents[idx]->sci) + 1);
|
||||
sci_get_text(documents[idx]->sci, sci_get_length(documents[idx]->sci) + 1 , text);
|
||||
text = g_malloc(sci_get_length(doc->sci) + 1);
|
||||
sci_get_text(doc->sci, sci_get_length(doc->sci) + 1 , text);
|
||||
range = _("whole document");
|
||||
}
|
||||
word_count(text, &chars, &lines, &words);
|
||||
@ -712,17 +715,18 @@ on_color_ok_button_clicked (GtkButton *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
GdkColor color;
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
gchar *hex;
|
||||
|
||||
gtk_widget_hide(ui_widgets.open_colorsel);
|
||||
if (idx == -1 || ! documents[idx]->is_valid) return;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
gtk_color_selection_get_current_color(
|
||||
GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), &color);
|
||||
|
||||
hex = utils_get_hex_from_color(&color);
|
||||
editor_insert_color(idx, hex);
|
||||
editor_insert_color(doc, hex);
|
||||
g_free(hex);
|
||||
}
|
||||
#endif
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
void tools_create_insert_custom_command_menu_items(void);
|
||||
|
||||
void tools_execute_custom_command(gint idx, const gchar *command);
|
||||
void tools_execute_custom_command(GeanyDocument *doc, const gchar *command);
|
||||
|
||||
|
||||
void tools_word_count(void);
|
||||
|
101
src/treeviews.c
101
src/treeviews.c
@ -150,10 +150,10 @@ on_default_tag_tree_button_press_event(GtkWidget *widget, GdkEventButton *event,
|
||||
}
|
||||
|
||||
|
||||
/* update = rescan the tags for document[idx].filename */
|
||||
void treeviews_update_tag_list(gint idx, gboolean update)
|
||||
/* update = rescan the tags for doc->filename */
|
||||
void treeviews_update_tag_list(GeanyDocument *doc, gboolean update)
|
||||
{
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
|
||||
if (gtk_bin_get_child(GTK_BIN(tag_window)))
|
||||
gtk_container_remove(GTK_CONTAINER(tag_window), gtk_bin_get_child(GTK_BIN(tag_window)));
|
||||
@ -177,8 +177,8 @@ void treeviews_update_tag_list(gint idx, gboolean update)
|
||||
}
|
||||
|
||||
/* show default empty tag tree if there are no tags */
|
||||
if (idx == -1 || documents[idx]->file_type == NULL ||
|
||||
! filetype_has_tags(documents[idx]->file_type))
|
||||
if (doc == NULL || doc->file_type == NULL ||
|
||||
! filetype_has_tags(doc->file_type))
|
||||
{
|
||||
gtk_container_add(GTK_CONTAINER(tag_window), tv.default_tag_tree);
|
||||
return;
|
||||
@ -196,10 +196,10 @@ void treeviews_update_tag_list(gint idx, gboolean update)
|
||||
g_object_ref((gpointer)fdoc->tag_tree); /* to hold it after removing */
|
||||
}
|
||||
|
||||
documents[idx]->has_tags = symbols_recreate_tag_list(idx, SYMBOLS_SORT_USE_PREVIOUS);
|
||||
doc->has_tags = symbols_recreate_tag_list(doc, SYMBOLS_SORT_USE_PREVIOUS);
|
||||
}
|
||||
|
||||
if (documents[idx]->has_tags)
|
||||
if (doc->has_tags)
|
||||
{
|
||||
gtk_container_add(GTK_CONTAINER(tag_window), fdoc->tag_tree);
|
||||
}
|
||||
@ -252,9 +252,9 @@ static void prepare_openfiles(void)
|
||||
/* store the short filename to show, and the index as reference,
|
||||
* the colour (black/red/green) and the full name for the tooltip */
|
||||
#if GTK_CHECK_VERSION(2, 12, 0)
|
||||
store_openfiles = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_INT, GDK_TYPE_COLOR, G_TYPE_STRING);
|
||||
store_openfiles = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_POINTER, GDK_TYPE_COLOR, G_TYPE_STRING);
|
||||
#else
|
||||
store_openfiles = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, GDK_TYPE_COLOR);
|
||||
store_openfiles = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_POINTER, GDK_TYPE_COLOR);
|
||||
#endif
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(tv.tree_openfiles), GTK_TREE_MODEL(store_openfiles));
|
||||
|
||||
@ -299,31 +299,31 @@ static void prepare_openfiles(void)
|
||||
|
||||
/* Also sets documents[idx]->iter.
|
||||
* This is called recursively in treeviews_openfiles_update_all(). */
|
||||
void treeviews_openfiles_add(gint idx)
|
||||
void treeviews_openfiles_add(GeanyDocument *doc)
|
||||
{
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
GtkTreeIter *iter = &fdoc->iter;
|
||||
|
||||
gtk_list_store_append(store_openfiles, iter);
|
||||
treeviews_openfiles_update(idx);
|
||||
treeviews_openfiles_update(doc);
|
||||
}
|
||||
|
||||
|
||||
void treeviews_openfiles_update(gint idx)
|
||||
void treeviews_openfiles_update(GeanyDocument *doc)
|
||||
{
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
gchar *basename;
|
||||
GdkColor *color = document_get_status_color(idx);
|
||||
GdkColor *color = document_get_status_color(doc);
|
||||
|
||||
if (interface_prefs.sidebar_openfiles_fullpath)
|
||||
basename = DOC_FILENAME(idx);
|
||||
basename = DOC_FILENAME(doc);
|
||||
else
|
||||
basename = g_path_get_basename(DOC_FILENAME(idx));
|
||||
basename = g_path_get_basename(DOC_FILENAME(doc));
|
||||
gtk_list_store_set(store_openfiles, &fdoc->iter,
|
||||
#if GTK_CHECK_VERSION(2, 12, 0)
|
||||
0, basename, 1, idx, 2, color, 3, DOC_FILENAME(idx), -1);
|
||||
0, basename, 1, doc, 2, color, 3, DOC_FILENAME(doc), -1);
|
||||
#else
|
||||
0, basename, 1, idx, 2, color, -1);
|
||||
0, basename, 1, doc, 2, color, -1);
|
||||
#endif
|
||||
if (! interface_prefs.sidebar_openfiles_fullpath)
|
||||
g_free(basename);
|
||||
@ -333,22 +333,23 @@ void treeviews_openfiles_update(gint idx)
|
||||
void treeviews_openfiles_update_all()
|
||||
{
|
||||
guint i;
|
||||
gint idx;
|
||||
GeanyDocument *doc;
|
||||
|
||||
gtk_list_store_clear(store_openfiles);
|
||||
for (i = 0; i < (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); i++)
|
||||
{
|
||||
idx = document_get_n_idx(i);
|
||||
if (! documents[idx]->is_valid) continue;
|
||||
doc = document_get_from_page(i);
|
||||
if (doc == NULL)
|
||||
continue;
|
||||
|
||||
treeviews_openfiles_add(idx);
|
||||
treeviews_openfiles_add(doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void treeviews_remove_document(gint idx)
|
||||
void treeviews_remove_document(GeanyDocument *doc)
|
||||
{
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
GtkTreeIter *iter = &fdoc->iter;
|
||||
|
||||
gtk_list_store_remove(store_openfiles, iter);
|
||||
@ -499,17 +500,17 @@ static void create_openfiles_popup_menu(void)
|
||||
}
|
||||
|
||||
|
||||
/* compares the given data (GINT_TO_PONTER(idx)) with the idx from the selected row of openfiles
|
||||
/* compares the given data with the doc pointer from the selected row of openfiles
|
||||
* treeview, in case of a match the row is selected and TRUE is returned
|
||||
* (called indirectly from gtk_tree_model_foreach()) */
|
||||
static gboolean tree_model_find_node(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
gint idx = -1;
|
||||
GeanyDocument *doc;
|
||||
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(store_openfiles), iter, 1, &idx, -1);
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(store_openfiles), iter, 1, &doc, -1);
|
||||
|
||||
if (idx == GPOINTER_TO_INT(data))
|
||||
if (doc == data)
|
||||
{
|
||||
gtk_tree_view_set_cursor(GTK_TREE_VIEW(tv.tree_openfiles), path, NULL, FALSE);
|
||||
return TRUE;
|
||||
@ -518,10 +519,9 @@ static gboolean tree_model_find_node(GtkTreeModel *model, GtkTreePath *path,
|
||||
}
|
||||
|
||||
|
||||
void treeviews_select_openfiles_item(gint idx)
|
||||
void treeviews_select_openfiles_item(GeanyDocument *doc)
|
||||
{
|
||||
gtk_tree_model_foreach(GTK_TREE_MODEL(store_openfiles), tree_model_find_node,
|
||||
GINT_TO_POINTER(idx));
|
||||
gtk_tree_model_foreach(GTK_TREE_MODEL(store_openfiles), tree_model_find_node, doc);
|
||||
}
|
||||
|
||||
|
||||
@ -532,23 +532,24 @@ static void on_openfiles_document_action(GtkMenuItem *menuitem, gpointer user_da
|
||||
GtkTreeIter iter;
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv.tree_openfiles));
|
||||
GtkTreeModel *model;
|
||||
gint idx = -1;
|
||||
GeanyDocument *doc;
|
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter))
|
||||
{
|
||||
gtk_tree_model_get(model, &iter, 1, &idx, -1);
|
||||
if (idx >= 0)
|
||||
gtk_tree_model_get(model, &iter, 1, &doc, -1);
|
||||
if (DOC_VALID(doc))
|
||||
{
|
||||
switch (GPOINTER_TO_INT(user_data))
|
||||
{
|
||||
case OPENFILES_ACTION_REMOVE:
|
||||
{
|
||||
document_remove(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), GTK_WIDGET(documents[idx]->sci)));
|
||||
document_remove_page(gtk_notebook_page_num(
|
||||
GTK_NOTEBOOK(main_widgets.notebook), GTK_WIDGET(doc->sci)));
|
||||
break;
|
||||
}
|
||||
case OPENFILES_ACTION_SAVE:
|
||||
{
|
||||
if (documents[idx]->changed) document_save_file(idx, FALSE);
|
||||
document_save_file(doc, FALSE);
|
||||
break;
|
||||
}
|
||||
case OPENFILES_ACTION_RELOAD:
|
||||
@ -571,13 +572,13 @@ static void on_openfiles_hide_item_clicked(GtkMenuItem *menuitem, gpointer user_
|
||||
|
||||
static gboolean change_focus(gpointer data)
|
||||
{
|
||||
gint idx = GPOINTER_TO_INT(data);
|
||||
GeanyDocument *doc = data;
|
||||
|
||||
/* idx might not be valid e.g. if user closed a tab whilst Geany is opening files */
|
||||
if (DOC_IDX_VALID(idx))
|
||||
if (DOC_VALID(doc))
|
||||
{
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
GtkWidget *sci = GTK_WIDGET(documents[idx]->sci);
|
||||
GtkWidget *sci = GTK_WIDGET(doc->sci);
|
||||
|
||||
if (focusw == tv.tree_openfiles)
|
||||
gtk_widget_grab_focus(sci);
|
||||
@ -590,16 +591,16 @@ static void on_openfiles_tree_selection_changed(GtkTreeSelection *selection, gpo
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
gint idx = 0;
|
||||
GeanyDocument *doc = NULL;
|
||||
|
||||
/* use switch_notebook_page to ignore changing the notebook page because it is already done */
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter) && ! ignore_callback)
|
||||
{
|
||||
gtk_tree_model_get(model, &iter, 1, &idx, -1);
|
||||
gtk_tree_model_get(model, &iter, 1, &doc, -1);
|
||||
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
|
||||
(GtkWidget*) documents[idx]->sci));
|
||||
g_idle_add((GSourceFunc) change_focus, GINT_TO_POINTER(idx));
|
||||
(GtkWidget*) doc->sci));
|
||||
g_idle_add((GSourceFunc) change_focus, doc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,16 +611,16 @@ static void on_taglist_tree_popup_clicked(GtkMenuItem *menuitem, gpointer user_d
|
||||
{
|
||||
case SYMBOL_ACTION_SORT_BY_NAME:
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (DOC_IDX_VALID(idx))
|
||||
documents[idx]->has_tags = symbols_recreate_tag_list(idx, SYMBOLS_SORT_BY_NAME);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
doc->has_tags = symbols_recreate_tag_list(doc, SYMBOLS_SORT_BY_NAME);
|
||||
break;
|
||||
}
|
||||
case SYMBOL_ACTION_SORT_BY_APPEARANCE:
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
if (DOC_IDX_VALID(idx))
|
||||
documents[idx]->has_tags = symbols_recreate_tag_list(idx, SYMBOLS_SORT_BY_APPEARANCE);
|
||||
GeanyDocument *doc = document_get_current();
|
||||
if (doc != NULL)
|
||||
doc->has_tags = symbols_recreate_tag_list(doc, SYMBOLS_SORT_BY_APPEARANCE);
|
||||
break;
|
||||
}
|
||||
case SYMBOL_ACTION_HIDE:
|
||||
|
@ -47,16 +47,16 @@ enum
|
||||
|
||||
void treeviews_init(void);
|
||||
|
||||
void treeviews_update_tag_list(gint idx, gboolean update);
|
||||
void treeviews_update_tag_list(GeanyDocument *doc, gboolean update);
|
||||
|
||||
void treeviews_openfiles_add(gint idx);
|
||||
void treeviews_openfiles_add(GeanyDocument *doc);
|
||||
|
||||
void treeviews_openfiles_update(gint idx);
|
||||
void treeviews_openfiles_update(GeanyDocument *doc);
|
||||
|
||||
void treeviews_openfiles_update_all(void);
|
||||
|
||||
void treeviews_select_openfiles_item(gint idx);
|
||||
void treeviews_select_openfiles_item(GeanyDocument *doc);
|
||||
|
||||
void treeviews_remove_document(gint idx);
|
||||
void treeviews_remove_document(GeanyDocument *doc);
|
||||
|
||||
#endif
|
||||
|
145
src/ui_utils.c
145
src/ui_utils.c
@ -118,14 +118,15 @@ void ui_set_statusbar(gboolean log, const gchar *format, ...)
|
||||
|
||||
|
||||
/* updates the status bar document statistics */
|
||||
void ui_update_statusbar(gint idx, gint pos)
|
||||
void ui_update_statusbar(GeanyDocument *doc, gint pos)
|
||||
{
|
||||
if (! interface_prefs.statusbar_visible)
|
||||
return; /* just do nothing if statusbar is not visible */
|
||||
|
||||
if (idx == -1) idx = document_get_cur_idx();
|
||||
if (doc == NULL)
|
||||
doc = document_get_current();
|
||||
|
||||
if (DOC_IDX_VALID(idx))
|
||||
if (doc != NULL)
|
||||
{
|
||||
static GString *stats_str = NULL;
|
||||
const gchar sp[] = " ";
|
||||
@ -134,57 +135,57 @@ void ui_update_statusbar(gint idx, gint pos)
|
||||
gchar *filetype_name;
|
||||
|
||||
/* workaround to make the name of filetype GEANY_FILETYPES_NONE translatable */
|
||||
if (documents[idx]->file_type == NULL || documents[idx]->file_type->id == GEANY_FILETYPES_NONE)
|
||||
if (doc->file_type == NULL || doc->file_type->id == GEANY_FILETYPES_NONE)
|
||||
filetype_name = _("None");
|
||||
else
|
||||
filetype_name = documents[idx]->file_type->name;
|
||||
filetype_name = doc->file_type->name;
|
||||
|
||||
if (stats_str == NULL)
|
||||
stats_str = g_string_sized_new(120);
|
||||
|
||||
if (pos == -1) pos = sci_get_current_position(documents[idx]->sci);
|
||||
line = sci_get_line_from_position(documents[idx]->sci, pos);
|
||||
if (pos == -1) pos = sci_get_current_position(doc->sci);
|
||||
line = sci_get_line_from_position(doc->sci, pos);
|
||||
|
||||
/* Add temporary fix for sci infinite loop in Document::GetColumn(int)
|
||||
* when current pos is beyond document end (can occur when removing
|
||||
* blocks of selected lines especially esp. brace sections near end of file). */
|
||||
if (pos <= sci_get_length(documents[idx]->sci))
|
||||
col = sci_get_col_from_position(documents[idx]->sci, pos);
|
||||
if (pos <= sci_get_length(doc->sci))
|
||||
col = sci_get_col_from_position(doc->sci, pos);
|
||||
else
|
||||
col = 0;
|
||||
|
||||
/* Status bar statistics: col = column, sel = selection. */
|
||||
g_string_printf(stats_str, _("line: %d\t col: %d\t sel: %d\t "),
|
||||
(line + 1), col,
|
||||
sci_get_selected_text_length(documents[idx]->sci) - 1);
|
||||
sci_get_selected_text_length(doc->sci) - 1);
|
||||
|
||||
g_string_append(stats_str,
|
||||
/* RO = read-only */
|
||||
(documents[idx]->readonly) ? _("RO ") :
|
||||
(doc->readonly) ? _("RO ") :
|
||||
/* OVR = overwrite/overtype, INS = insert */
|
||||
(sci_get_overtype(documents[idx]->sci) ? _("OVR") : _("INS")));
|
||||
(sci_get_overtype(doc->sci) ? _("OVR") : _("INS")));
|
||||
g_string_append(stats_str, sp);
|
||||
g_string_append(stats_str,
|
||||
(documents[idx]->use_tabs) ? _("TAB") : _("SP ")); /* SP = space */
|
||||
(doc->use_tabs) ? _("TAB") : _("SP ")); /* SP = space */
|
||||
g_string_append(stats_str, sp);
|
||||
g_string_append_printf(stats_str, _("mode: %s"),
|
||||
editor_get_eol_char_name(idx));
|
||||
editor_get_eol_char_name(doc));
|
||||
g_string_append(stats_str, sp);
|
||||
g_string_append_printf(stats_str, _("encoding: %s %s"),
|
||||
(documents[idx]->encoding) ? documents[idx]->encoding : _("unknown"),
|
||||
(encodings_is_unicode_charset(documents[idx]->encoding)) ?
|
||||
(doc->encoding) ? doc->encoding : _("unknown"),
|
||||
(encodings_is_unicode_charset(doc->encoding)) ?
|
||||
/* BOM = byte order mark */
|
||||
((documents[idx]->has_bom) ? _("(with BOM)") : "") : "");
|
||||
((doc->has_bom) ? _("(with BOM)") : "") : "");
|
||||
g_string_append(stats_str, sp);
|
||||
g_string_append_printf(stats_str, _("filetype: %s"), filetype_name);
|
||||
g_string_append(stats_str, sp);
|
||||
if (documents[idx]->changed)
|
||||
if (doc->changed)
|
||||
{
|
||||
g_string_append(stats_str, _("MOD")); /* MOD = modified */
|
||||
g_string_append(stats_str, sp);
|
||||
}
|
||||
|
||||
utils_get_current_function(idx, &cur_tag);
|
||||
utils_get_current_function(doc, &cur_tag);
|
||||
g_string_append_printf(stats_str, _("scope: %s"),
|
||||
cur_tag);
|
||||
|
||||
@ -204,26 +205,26 @@ void ui_update_statusbar(gint idx, gint pos)
|
||||
|
||||
|
||||
/* This sets the window title according to the current filename. */
|
||||
void ui_set_window_title(gint idx)
|
||||
void ui_set_window_title(GeanyDocument *doc)
|
||||
{
|
||||
GString *str;
|
||||
GeanyProject *project = app->project;
|
||||
|
||||
if (idx < 0)
|
||||
idx = document_get_cur_idx();
|
||||
if (doc == NULL)
|
||||
doc = document_get_current();
|
||||
|
||||
str = g_string_new(NULL);
|
||||
|
||||
if (idx >= 0)
|
||||
if (doc != NULL)
|
||||
{
|
||||
g_string_append(str, documents[idx]->changed ? "*" : "");
|
||||
g_string_append(str, doc->changed ? "*" : "");
|
||||
|
||||
if (documents[idx]->file_name == NULL)
|
||||
g_string_append(str, DOC_FILENAME(idx));
|
||||
if (doc->file_name == NULL)
|
||||
g_string_append(str, DOC_FILENAME(doc));
|
||||
else
|
||||
{
|
||||
gchar *base_name = g_path_get_basename(DOC_FILENAME(idx));
|
||||
gchar *dirname = g_path_get_dirname(DOC_FILENAME(idx));
|
||||
gchar *base_name = g_path_get_basename(DOC_FILENAME(doc));
|
||||
gchar *dirname = g_path_get_dirname(DOC_FILENAME(doc));
|
||||
|
||||
g_string_append(str, base_name);
|
||||
g_string_append(str, " - ");
|
||||
@ -270,7 +271,7 @@ void ui_set_editor_font(const gchar *font_name)
|
||||
{
|
||||
if (documents[i]->sci)
|
||||
{
|
||||
editor_set_font(i, fname, size);
|
||||
editor_set_font(documents[i], fname, size);
|
||||
}
|
||||
}
|
||||
pango_font_description_free(font_desc);
|
||||
@ -293,20 +294,20 @@ void ui_set_fullscreen(void)
|
||||
}
|
||||
|
||||
|
||||
void ui_update_popup_reundo_items(gint idx)
|
||||
void ui_update_popup_reundo_items(GeanyDocument *doc)
|
||||
{
|
||||
gboolean enable_undo;
|
||||
gboolean enable_redo;
|
||||
|
||||
if (idx == -1)
|
||||
if (doc == NULL)
|
||||
{
|
||||
enable_undo = FALSE;
|
||||
enable_redo = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
enable_undo = document_can_undo(idx);
|
||||
enable_redo = document_can_redo(idx);
|
||||
enable_undo = document_can_undo(doc);
|
||||
enable_redo = document_can_redo(doc);
|
||||
}
|
||||
|
||||
/* index 0 is the popup menu, 1 is the menubar, 2 is the toolbar */
|
||||
@ -320,13 +321,15 @@ void ui_update_popup_reundo_items(gint idx)
|
||||
}
|
||||
|
||||
|
||||
void ui_update_popup_copy_items(gint idx)
|
||||
void ui_update_popup_copy_items(GeanyDocument *doc)
|
||||
{
|
||||
gboolean enable;
|
||||
guint i;
|
||||
|
||||
if (idx == -1) enable = FALSE;
|
||||
else enable = sci_can_copy(documents[idx]->sci);
|
||||
if (doc == NULL)
|
||||
enable = FALSE;
|
||||
else
|
||||
enable = sci_can_copy(doc->sci);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(ui_widgets.popup_copy_items); i++)
|
||||
gtk_widget_set_sensitive(ui_widgets.popup_copy_items[i], enable);
|
||||
@ -341,14 +344,14 @@ void ui_update_popup_goto_items(gboolean enable)
|
||||
}
|
||||
|
||||
|
||||
void ui_update_menu_copy_items(gint idx)
|
||||
void ui_update_menu_copy_items(GeanyDocument *doc)
|
||||
{
|
||||
gboolean enable = FALSE;
|
||||
guint i;
|
||||
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
||||
|
||||
if (IS_SCINTILLA(focusw))
|
||||
enable = (idx == -1) ? FALSE : sci_can_copy(documents[idx]->sci);
|
||||
enable = (doc == NULL) ? FALSE : sci_can_copy(doc->sci);
|
||||
else
|
||||
if (GTK_IS_EDITABLE(focusw))
|
||||
enable = gtk_editable_get_selection_bounds(GTK_EDITABLE(focusw), NULL, NULL);
|
||||
@ -365,13 +368,14 @@ void ui_update_menu_copy_items(gint idx)
|
||||
}
|
||||
|
||||
|
||||
void ui_update_insert_include_item(gint idx, gint item)
|
||||
void ui_update_insert_include_item(GeanyDocument *doc, gint item)
|
||||
{
|
||||
gboolean enable = FALSE;
|
||||
|
||||
if (idx == -1 || documents[idx]->file_type == NULL) enable = FALSE;
|
||||
else if (documents[idx]->file_type->id == GEANY_FILETYPES_C ||
|
||||
documents[idx]->file_type->id == GEANY_FILETYPES_CPP)
|
||||
if (doc == NULL || doc->file_type == NULL)
|
||||
enable = FALSE;
|
||||
else if (doc->file_type->id == GEANY_FILETYPES_C ||
|
||||
doc->file_type->id == GEANY_FILETYPES_CPP)
|
||||
{
|
||||
enable = TRUE;
|
||||
}
|
||||
@ -671,46 +675,43 @@ void ui_sidebar_show_hide(void)
|
||||
}
|
||||
|
||||
|
||||
void ui_document_show_hide(gint idx)
|
||||
void ui_document_show_hide(GeanyDocument *doc)
|
||||
{
|
||||
gchar *widget_name;
|
||||
GtkWidget *item;
|
||||
|
||||
if (idx == -1)
|
||||
idx = document_get_cur_idx();
|
||||
if (doc == NULL)
|
||||
doc = document_get_current();
|
||||
|
||||
if (! DOC_IDX_VALID(idx))
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
ignore_callback = TRUE;
|
||||
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, "menu_line_wrapping1")),
|
||||
documents[idx]->line_wrapping);
|
||||
doc->line_wrapping);
|
||||
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, "line_breaking1")),
|
||||
documents[idx]->line_breaking);
|
||||
doc->line_breaking);
|
||||
|
||||
item = lookup_widget(main_widgets.window, "menu_use_auto_indentation1");
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
|
||||
documents[idx]->auto_indent);
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->auto_indent);
|
||||
gtk_widget_set_sensitive(item, editor_prefs.indent_mode != INDENT_NONE);
|
||||
|
||||
item = lookup_widget(main_widgets.window,
|
||||
documents[idx]->use_tabs ? "tabs1" : "spaces1");
|
||||
item = lookup_widget(main_widgets.window, doc->use_tabs ? "tabs1" : "spaces1");
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
|
||||
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, "set_file_readonly1")),
|
||||
documents[idx]->readonly);
|
||||
doc->readonly);
|
||||
|
||||
item = lookup_widget(main_widgets.window, "menu_write_unicode_bom1");
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
|
||||
documents[idx]->has_bom);
|
||||
gtk_widget_set_sensitive(item, encodings_is_unicode_charset(documents[idx]->encoding));
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->has_bom);
|
||||
gtk_widget_set_sensitive(item, encodings_is_unicode_charset(doc->encoding));
|
||||
|
||||
switch (sci_get_eol_mode(documents[idx]->sci))
|
||||
switch (sci_get_eol_mode(doc->sci))
|
||||
{
|
||||
case SC_EOL_CR: widget_name = "cr"; break;
|
||||
case SC_EOL_LF: widget_name = "lf"; break;
|
||||
@ -719,8 +720,8 @@ void ui_document_show_hide(gint idx)
|
||||
gtk_check_menu_item_set_active(
|
||||
GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, widget_name)), TRUE);
|
||||
|
||||
encodings_select_radio_item(documents[idx]->encoding);
|
||||
filetypes_select_radio_item(documents[idx]->file_type);
|
||||
encodings_select_radio_item(doc->encoding);
|
||||
filetypes_select_radio_item(doc->file_type);
|
||||
|
||||
ignore_callback = FALSE;
|
||||
}
|
||||
@ -896,7 +897,7 @@ recent_file_activate_cb (GtkMenuItem *menuitem,
|
||||
gchar *utf8_filename = ui_menu_item_get_text(menuitem);
|
||||
gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
|
||||
|
||||
if (document_open_file(locale_filename, FALSE, NULL, NULL) > -1)
|
||||
if (document_open_file(locale_filename, FALSE, NULL, NULL) != NULL)
|
||||
recent_file_loaded(utf8_filename);
|
||||
|
||||
g_free(locale_filename);
|
||||
@ -1056,24 +1057,26 @@ static void update_recent_menu(void)
|
||||
|
||||
void ui_show_markers_margin(void)
|
||||
{
|
||||
gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
gint i, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
GeanyDocument *doc;
|
||||
|
||||
for(i = 0; i < max; i++)
|
||||
{
|
||||
idx = document_get_n_idx(i);
|
||||
sci_set_symbol_margin(documents[idx]->sci, editor_prefs.show_markers_margin);
|
||||
doc = document_get_from_page(i);
|
||||
sci_set_symbol_margin(doc->sci, editor_prefs.show_markers_margin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ui_show_linenumber_margin(void)
|
||||
{
|
||||
gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
gint i, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
||||
GeanyDocument *doc;
|
||||
|
||||
for(i = 0; i < max; i++)
|
||||
{
|
||||
idx = document_get_n_idx(i);
|
||||
sci_set_line_numbers(documents[idx]->sci, editor_prefs.show_linenumber_margin, 0);
|
||||
doc = document_get_from_page(i);
|
||||
sci_set_line_numbers(doc->sci, editor_prefs.show_linenumber_margin, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1203,10 +1206,10 @@ void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text)
|
||||
|
||||
/* Changes the color of the notebook tab text and open files items according to
|
||||
* document status. */
|
||||
void ui_update_tab_status(gint idx)
|
||||
void ui_update_tab_status(GeanyDocument *doc)
|
||||
{
|
||||
GdkColor *color = document_get_status_color(idx);
|
||||
Document *fdoc = DOCUMENT(documents[idx]);
|
||||
GdkColor *color = document_get_status_color(doc);
|
||||
Document *fdoc = DOCUMENT(doc);
|
||||
|
||||
/* NULL color will reset to default */
|
||||
gtk_widget_modify_fg(fdoc->tab_label, GTK_STATE_NORMAL, color);
|
||||
@ -1214,7 +1217,7 @@ void ui_update_tab_status(gint idx)
|
||||
gtk_widget_modify_fg(fdoc->tabmenu_label, GTK_STATE_NORMAL, color);
|
||||
gtk_widget_modify_fg(fdoc->tabmenu_label, GTK_STATE_ACTIVE, color);
|
||||
|
||||
treeviews_openfiles_update(idx);
|
||||
treeviews_openfiles_update(doc);
|
||||
}
|
||||
|
||||
|
||||
@ -1396,7 +1399,7 @@ void ui_statusbar_showhide(gboolean state)
|
||||
if (state)
|
||||
{
|
||||
gtk_widget_show(ui_widgets.statusbar);
|
||||
ui_update_statusbar(-1, -1);
|
||||
ui_update_statusbar(NULL, -1);
|
||||
}
|
||||
else
|
||||
gtk_widget_hide(ui_widgets.statusbar);
|
||||
|
@ -166,27 +166,27 @@ void ui_init(void);
|
||||
|
||||
void ui_set_statusbar(gboolean log, const gchar *format, ...) G_GNUC_PRINTF (2, 3);
|
||||
|
||||
void ui_update_statusbar(gint idx, gint pos);
|
||||
void ui_update_statusbar(GeanyDocument *doc, gint pos);
|
||||
|
||||
|
||||
/* This sets the window title according to the current filename. */
|
||||
void ui_set_window_title(gint index);
|
||||
void ui_set_window_title(GeanyDocument *doc);
|
||||
|
||||
void ui_set_editor_font(const gchar *font_name);
|
||||
|
||||
void ui_set_fullscreen(void);
|
||||
|
||||
|
||||
void ui_update_popup_reundo_items(gint idx);
|
||||
void ui_update_popup_reundo_items(GeanyDocument *doc);
|
||||
|
||||
void ui_update_popup_copy_items(gint idx);
|
||||
void ui_update_popup_copy_items(GeanyDocument *doc);
|
||||
|
||||
void ui_update_popup_goto_items(gboolean enable);
|
||||
|
||||
|
||||
void ui_update_menu_copy_items(gint idx);
|
||||
void ui_update_menu_copy_items(GeanyDocument *doc);
|
||||
|
||||
void ui_update_insert_include_item(gint idx, gint item);
|
||||
void ui_update_insert_include_item(GeanyDocument *doc, gint item);
|
||||
|
||||
void ui_update_fold_items(void);
|
||||
|
||||
@ -203,7 +203,7 @@ void ui_document_buttons_update(void);
|
||||
|
||||
void ui_sidebar_show_hide(void);
|
||||
|
||||
void ui_document_show_hide(gint idx);
|
||||
void ui_document_show_hide(GeanyDocument *doc);
|
||||
|
||||
|
||||
void ui_update_toolbar_icons(GtkIconSize size);
|
||||
@ -226,7 +226,7 @@ void ui_show_markers_margin(void);
|
||||
void ui_show_linenumber_margin(void);
|
||||
|
||||
|
||||
void ui_update_tab_status(gint idx);
|
||||
void ui_update_tab_status(GeanyDocument *doc);
|
||||
|
||||
|
||||
typedef gboolean TVMatchCallback(void);
|
||||
|
146
src/utils.c
146
src/utils.c
@ -289,86 +289,11 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag)
|
||||
}
|
||||
|
||||
|
||||
static gboolean check_reload(gint idx)
|
||||
{
|
||||
gchar *base_name = g_path_get_basename(documents[idx]->file_name);
|
||||
gboolean want_reload;
|
||||
|
||||
want_reload = dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
|
||||
_("Do you want to reload it?"),
|
||||
_("The file '%s' on the disk is more recent than\n"
|
||||
"the current buffer."), base_name);
|
||||
if (want_reload)
|
||||
{
|
||||
document_reload_file(idx, NULL);
|
||||
}
|
||||
g_free(base_name);
|
||||
return want_reload;
|
||||
}
|
||||
|
||||
|
||||
/* Set force to force a disk check, otherwise it is ignored if there was a check
|
||||
* in the last file_prefs.disk_check_timeout seconds.
|
||||
* @return @c TRUE if the file has changed. */
|
||||
gboolean utils_check_disk_status(gint idx, gboolean force)
|
||||
{
|
||||
struct stat st;
|
||||
time_t t;
|
||||
gchar *locale_filename;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (file_prefs.disk_check_timeout == 0) return FALSE;
|
||||
if (! DOC_IDX_VALID(idx)) return FALSE;
|
||||
/* ignore documents that have never been saved to disk */
|
||||
if (documents[idx]->real_path == NULL) return FALSE;
|
||||
|
||||
t = time(NULL);
|
||||
|
||||
if (! force && documents[idx]->last_check > (t - file_prefs.disk_check_timeout))
|
||||
return FALSE;
|
||||
|
||||
documents[idx]->last_check = t;
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(documents[idx]->file_name);
|
||||
if (g_stat(locale_filename, &st) != 0)
|
||||
{
|
||||
/* file is missing - set unsaved state */
|
||||
documents[idx]->changed = TRUE;
|
||||
document_set_text_changed(idx);
|
||||
|
||||
if (dialogs_show_question_full(NULL, GTK_STOCK_SAVE, GTK_STOCK_CANCEL,
|
||||
_("Try to resave the file?"),
|
||||
_("File \"%s\" was not found on disk!"), documents[idx]->file_name))
|
||||
{
|
||||
dialogs_show_save_as();
|
||||
}
|
||||
}
|
||||
else if (documents[idx]->mtime > t || st.st_mtime > t)
|
||||
{
|
||||
geany_debug("Strange: Something is wrong with the time stamps.");
|
||||
}
|
||||
else if (documents[idx]->mtime < st.st_mtime)
|
||||
{
|
||||
if (check_reload(idx))
|
||||
{
|
||||
/* Update the modification time */
|
||||
documents[idx]->mtime = st.st_mtime;
|
||||
}
|
||||
else
|
||||
documents[idx]->mtime = st.st_mtime; /* Ignore this change on disk completely */
|
||||
|
||||
ret = TRUE; /* file has changed */
|
||||
}
|
||||
g_free(locale_filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* This could perhaps be improved to check for #if, class etc. */
|
||||
static gint get_function_fold_number(gint idx)
|
||||
static gint get_function_fold_number(GeanyDocument *doc)
|
||||
{
|
||||
/* for Java the functions are always one fold level above the class scope */
|
||||
if (FILETYPE_ID(documents[idx]->file_type) == GEANY_FILETYPES_JAVA)
|
||||
if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_JAVA)
|
||||
return SC_FOLDLEVELBASE + 1;
|
||||
else
|
||||
return SC_FOLDLEVELBASE;
|
||||
@ -376,16 +301,16 @@ static gint get_function_fold_number(gint idx)
|
||||
|
||||
|
||||
/* Should be used only with utils_get_current_function. */
|
||||
static gboolean current_function_changed(gint cur_idx, gint cur_line, gint fold_level)
|
||||
static gboolean current_function_changed(GeanyDocument *doc, gint cur_line, gint fold_level)
|
||||
{
|
||||
static gint old_line = -2;
|
||||
static gint old_idx = -1;
|
||||
static GeanyDocument *old_doc = NULL;
|
||||
static gint old_fold_num = -1;
|
||||
const gint fold_num = fold_level & SC_FOLDLEVELNUMBERMASK;
|
||||
gboolean ret;
|
||||
|
||||
/* check if the cached line and file index have changed since last time: */
|
||||
if (cur_idx < 0 || cur_idx != old_idx)
|
||||
if (doc == NULL || doc != old_doc)
|
||||
ret = TRUE;
|
||||
else
|
||||
if (cur_line == old_line)
|
||||
@ -396,7 +321,7 @@ static gboolean current_function_changed(gint cur_idx, gint cur_line, gint fold_
|
||||
if (abs(cur_line - old_line) == 1)
|
||||
{
|
||||
const gint fn_fold =
|
||||
get_function_fold_number(cur_idx);
|
||||
get_function_fold_number(doc);
|
||||
/* It's the same function if the fold number hasn't changed, or both the new
|
||||
* and old fold numbers are above the function fold number. */
|
||||
gboolean same =
|
||||
@ -410,7 +335,7 @@ static gboolean current_function_changed(gint cur_idx, gint cur_line, gint fold_
|
||||
|
||||
/* record current line and file index for next time */
|
||||
old_line = cur_line;
|
||||
old_idx = cur_idx;
|
||||
old_doc = doc;
|
||||
old_fold_num = fold_num;
|
||||
return ret;
|
||||
}
|
||||
@ -492,10 +417,10 @@ static gchar *parse_cpp_function_at_line(ScintillaObject *sci, gint tag_line)
|
||||
|
||||
|
||||
/* Sets *tagname to point at the current function or tag name.
|
||||
* If idx is -1, reset the cached current tag data to ensure it will be reparsed on the next
|
||||
* If doc is NULL, reset the cached current tag data to ensure it will be reparsed on the next
|
||||
* call to this function.
|
||||
* Returns: line number of the current tag, or -1 if unknown. */
|
||||
gint utils_get_current_function(gint idx, const gchar **tagname)
|
||||
gint utils_get_current_function(GeanyDocument *doc, const gchar **tagname)
|
||||
{
|
||||
static gint tag_line = -1;
|
||||
static gchar *cur_tag = NULL;
|
||||
@ -503,9 +428,9 @@ gint utils_get_current_function(gint idx, const gchar **tagname)
|
||||
gint fold_level;
|
||||
TMWorkObject *tm_file;
|
||||
|
||||
if (! DOC_IDX_VALID(idx)) /* reset current function */
|
||||
if (doc == NULL) /* reset current function */
|
||||
{
|
||||
current_function_changed(-1, -1, -1);
|
||||
current_function_changed(NULL, -1, -1);
|
||||
g_free(cur_tag);
|
||||
cur_tag = g_strdup(_("unknown"));
|
||||
if (tagname != NULL)
|
||||
@ -514,10 +439,10 @@ gint utils_get_current_function(gint idx, const gchar **tagname)
|
||||
return tag_line;
|
||||
}
|
||||
|
||||
line = sci_get_current_line(documents[idx]->sci);
|
||||
fold_level = sci_get_fold_level(documents[idx]->sci, line);
|
||||
line = sci_get_current_line(doc->sci);
|
||||
fold_level = sci_get_fold_level(doc->sci, line);
|
||||
/* check if the cached line and file index have changed since last time: */
|
||||
if (! current_function_changed(idx, line, fold_level))
|
||||
if (! current_function_changed(doc, line, fold_level))
|
||||
{
|
||||
/* we can assume same current function as before */
|
||||
*tagname = cur_tag;
|
||||
@ -533,10 +458,10 @@ gint utils_get_current_function(gint idx, const gchar **tagname)
|
||||
tag_line = -1;
|
||||
return tag_line;
|
||||
}
|
||||
tm_file = documents[idx]->tm_file;
|
||||
tm_file = doc->tm_file;
|
||||
|
||||
/* if the document has no changes, get the previous function name from TM */
|
||||
if(! documents[idx]->changed && tm_file != NULL && tm_file->tags_array != NULL)
|
||||
if(! doc->changed && tm_file != NULL && tm_file->tags_array != NULL)
|
||||
{
|
||||
const TMTag *tag = (const TMTag*) tm_get_current_function(tm_file->tags_array, line);
|
||||
|
||||
@ -553,25 +478,24 @@ gint utils_get_current_function(gint idx, const gchar **tagname)
|
||||
|
||||
/* parse the current function name here because TM line numbers may have changed,
|
||||
* and it would take too long to reparse the whole file. */
|
||||
if (documents[idx]->file_type != NULL &&
|
||||
documents[idx]->file_type->id != GEANY_FILETYPES_NONE)
|
||||
if (doc->file_type != NULL && doc->file_type->id != GEANY_FILETYPES_NONE)
|
||||
{
|
||||
const gint fn_fold = get_function_fold_number(idx);
|
||||
const gint fn_fold = get_function_fold_number(doc);
|
||||
|
||||
tag_line = line;
|
||||
do /* find the top level fold point */
|
||||
{
|
||||
tag_line = sci_get_fold_parent(documents[idx]->sci, tag_line);
|
||||
fold_level = sci_get_fold_level(documents[idx]->sci, tag_line);
|
||||
tag_line = sci_get_fold_parent(doc->sci, tag_line);
|
||||
fold_level = sci_get_fold_level(doc->sci, tag_line);
|
||||
} while (tag_line >= 0 &&
|
||||
(fold_level & SC_FOLDLEVELNUMBERMASK) != fn_fold);
|
||||
|
||||
if (tag_line >= 0)
|
||||
{
|
||||
if (sci_get_lexer(documents[idx]->sci) == SCLEX_CPP)
|
||||
cur_tag = parse_cpp_function_at_line(documents[idx]->sci, tag_line);
|
||||
if (sci_get_lexer(doc->sci) == SCLEX_CPP)
|
||||
cur_tag = parse_cpp_function_at_line(doc->sci, tag_line);
|
||||
else
|
||||
cur_tag = parse_function_at_line(documents[idx]->sci, tag_line);
|
||||
cur_tag = parse_function_at_line(doc->sci, tag_line);
|
||||
|
||||
if (cur_tag != NULL)
|
||||
{
|
||||
@ -1029,27 +953,27 @@ gchar *utils_get_setting_string(GKeyFile *config, const gchar *section, const gc
|
||||
}
|
||||
|
||||
|
||||
void utils_replace_filename(gint idx)
|
||||
void utils_replace_filename(GeanyDocument *doc)
|
||||
{
|
||||
gchar *filebase;
|
||||
gchar *filename;
|
||||
struct TextToFind ttf;
|
||||
|
||||
if (idx == -1 || documents[idx]->file_type == NULL) return;
|
||||
if (doc == NULL || doc->file_type == NULL) return;
|
||||
|
||||
filebase = g_strconcat(GEANY_STRING_UNTITLED, ".", (documents[idx]->file_type)->extension, NULL);
|
||||
filename = g_path_get_basename(documents[idx]->file_name);
|
||||
filebase = g_strconcat(GEANY_STRING_UNTITLED, ".", (doc->file_type)->extension, NULL);
|
||||
filename = g_path_get_basename(doc->file_name);
|
||||
|
||||
/* only search the first 3 lines */
|
||||
ttf.chrg.cpMin = 0;
|
||||
ttf.chrg.cpMax = sci_get_position_from_line(documents[idx]->sci, 3);
|
||||
ttf.chrg.cpMax = sci_get_position_from_line(doc->sci, 3);
|
||||
ttf.lpstrText = (gchar*)filebase;
|
||||
|
||||
if (sci_find_text(documents[idx]->sci, SCFIND_MATCHCASE, &ttf) != -1)
|
||||
if (sci_find_text(doc->sci, SCFIND_MATCHCASE, &ttf) != -1)
|
||||
{
|
||||
sci_target_start(documents[idx]->sci, ttf.chrgText.cpMin);
|
||||
sci_target_end(documents[idx]->sci, ttf.chrgText.cpMax);
|
||||
sci_target_replace(documents[idx]->sci, filename, FALSE);
|
||||
sci_target_start(doc->sci, ttf.chrgText.cpMin);
|
||||
sci_target_end(doc->sci, ttf.chrgText.cpMax);
|
||||
sci_target_replace(doc->sci, filename, FALSE);
|
||||
}
|
||||
|
||||
g_free(filebase);
|
||||
@ -1077,12 +1001,12 @@ gchar *utils_get_hex_from_color(GdkColor *color)
|
||||
* Returned string is in UTF-8 encoding */
|
||||
gchar *utils_get_current_file_dir_utf8(void)
|
||||
{
|
||||
gint cur_idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
if (DOC_IDX_VALID(cur_idx)) /* if valid page found */
|
||||
if (doc != NULL)
|
||||
{
|
||||
/* get current filename */
|
||||
const gchar *cur_fname = documents[cur_idx]->file_name;
|
||||
const gchar *cur_fname = doc->file_name;
|
||||
|
||||
if (cur_fname != NULL)
|
||||
{
|
||||
|
@ -58,9 +58,7 @@ gint utils_write_file(const gchar *filename, const gchar *text);
|
||||
|
||||
gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag);
|
||||
|
||||
gboolean utils_check_disk_status(gint idx, gboolean force);
|
||||
|
||||
gint utils_get_current_function(gint idx, const gchar **tagname);
|
||||
gint utils_get_current_function(GeanyDocument *doc, const gchar **tagname);
|
||||
|
||||
const gchar *utils_get_eol_name(gint eol_mode);
|
||||
|
||||
@ -96,7 +94,7 @@ gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gch
|
||||
|
||||
gchar *utils_get_setting_string(GKeyFile *config, const gchar *section, const gchar *key, const gchar *default_value);
|
||||
|
||||
void utils_replace_filename(gint idx);
|
||||
void utils_replace_filename(GeanyDocument *doc);
|
||||
|
||||
gchar *utils_get_hex_from_color(GdkColor *color);
|
||||
|
||||
|
@ -404,11 +404,11 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
|
||||
}
|
||||
else
|
||||
{
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
/* convert the resulting filename into UTF-8 */
|
||||
gchar *utf8 = g_locale_to_utf8(fname, -1, NULL, NULL, NULL);
|
||||
|
||||
document_save_file_as(idx, utf8);
|
||||
document_save_file_as(doc, utf8);
|
||||
g_free(utf8);
|
||||
}
|
||||
g_free(fname);
|
||||
@ -455,7 +455,7 @@ void win32_show_color_dialog(const gchar *colour)
|
||||
static COLORREF acr_cust_clr[16];
|
||||
static DWORD rgb_current;
|
||||
gchar *hex = g_malloc0(12);
|
||||
gint idx = document_get_cur_idx();
|
||||
GeanyDocument *doc = document_get_current();
|
||||
|
||||
/* Initialize CHOOSECOLOR */
|
||||
memset(&cc, 0, sizeof cc);
|
||||
@ -473,7 +473,7 @@ void win32_show_color_dialog(const gchar *colour)
|
||||
(guint) (utils_scale_round(GetGValue(rgb_current), 255)),
|
||||
(guint) (utils_scale_round(GetBValue(rgb_current), 255)));
|
||||
|
||||
editor_insert_color(idx, hex);
|
||||
editor_insert_color(doc, hex);
|
||||
}
|
||||
g_free(hex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user