Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete plugin extensions patches #3850

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/pluginsignals.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ signal void (*document_reload)(GObject *obj, GeanyDocument *doc, gpointer user_d
*/
signal void (*document_before_save)(GObject *obj, GeanyDocument *doc, gpointer user_data);

/** Sent before save as is performed with the original document.
*
* @param obj a GeanyObject instance, should be ignored.
* @param doc the original document. The document with the new file name is still
* reported by the "document-save" signal sent afterwards.
* @param user_data user data.
*
* @since TODO
*/
signal void (*document_before_save_as)(GObject *obj, GeanyDocument *doc, gpointer user_data);

/** Sent when a new document is saved.
*
* @param obj a GeanyObject instance, should be ignored.
Expand Down Expand Up @@ -210,6 +221,18 @@ signal void (*project_dialog_close)(GObject *obj, GtkWidget *notebook, gpointer
*/
signal void (*geany_startup_complete)(GObject *obj, gpointer user_data);

/** Sent when Geany starts or stops batch-opening session files from the global session
* or the project session.
*
* @param obj a GeanyObject instance, should be ignored.
* @param opening set to @c TRUE when session file opening starts and to @c FALSE when
* it is completed.
* @param user_data user data.
*
* @since TODO
*/
signal void (*session_opening)(GObject *obj, gboolean opening, gpointer user_data);

/** Sent before build is started. A plugin could use this signal e.g. to save all unsaved documents
* before the build starts.
*
Expand Down
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ install_headers(
'src/msgwindow.h',
'src/navqueue.h',
'src/plugindata.h',
'src/pluginextension.h',
'src/pluginutils.h',
'src/prefs.h',
'src/project.h',
Expand Down Expand Up @@ -820,6 +821,8 @@ libgeany = shared_library('geany',
'src/navqueue.h',
'src/notebook.c',
'src/notebook.h',
'src/pluginextension.c',
'src/pluginextension.h',
'src/plugins.c',
'src/plugins.h',
'src/pluginutils.c',
Expand Down
1 change: 1 addition & 0 deletions plugins/geanyplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "msgwindow.h"
#include "navqueue.h"
#include "plugindata.h"
#include "pluginextension.h"
#include "pluginutils.h"
#include "prefs.h"
#include "project.h"
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ geany_include_HEADERS = \
msgwindow.h \
navqueue.h \
plugindata.h \
pluginextension.h \
pluginutils.h \
prefs.h \
project.h \
Expand Down Expand Up @@ -89,6 +90,7 @@ libgeany_la_SOURCES = \
msgwindow.c msgwindow.h \
navqueue.c navqueue.h \
notebook.c notebook.h \
pluginextension.c pluginextension.h \
plugins.c plugins.h \
pluginutils.c pluginutils.h \
prefs.c prefs.h \
Expand Down
21 changes: 19 additions & 2 deletions src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "msgwindow.h"
#include "navqueue.h"
#include "notebook.h"
#include "pluginextension.h"
#include "project.h"
#include "sciwrappers.h"
#include "sidebar.h"
Expand Down Expand Up @@ -1836,6 +1837,8 @@ gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname)

g_return_val_if_fail(doc != NULL, FALSE);

g_signal_emit_by_name(geany_object, "document-before-save-as", doc);

new_file = document_need_save_as(doc) || (utf8_fname != NULL && strcmp(doc->file_name, utf8_fname) != 0);
if (utf8_fname != NULL)
SETPTR(doc->file_name, g_strdup(utf8_fname));
Expand Down Expand Up @@ -2653,6 +2656,17 @@ gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gcha
}


/* Indicates whether there is a tag parser for the document's filetype or not.
* Only works for custom filetypes if the filetype settings have been loaded. */
gboolean document_has_tags(GeanyDocument *doc)
{
if (plugin_extension_doc_symbols_provided(doc))
return TRUE;

return doc != NULL && doc->file_type != NULL && doc->file_type->lang != TM_PARSER_NONE;
}


/*
* Parses or re-parses the document's buffer and updates the type
* keywords and symbol list.
Expand All @@ -2668,7 +2682,7 @@ void document_update_tags(GeanyDocument *doc)
g_return_if_fail(app->tm_workspace != NULL);

/* early out if it's a new file or doesn't support tags */
if (! doc->file_name || ! doc->file_type || !filetype_has_tags(doc->file_type))
if (!doc->file_name || !document_has_tags(doc))
{
/* We must call sidebar_update_tag_list() before returning,
* to ensure that the symbol list is always updated properly (e.g.
Expand Down Expand Up @@ -2719,6 +2733,9 @@ void document_highlight_tags(GeanyDocument *doc)
GString *keywords_str;
gint keyword_idx;

if (plugin_extension_symbol_highlight_provided(doc))
return;

/* some filetypes support type keywords (such as struct names), but not
* necessarily all filetypes for a particular scintilla lexer. this
* tells us whether the filetype supports keywords, and if so
Expand Down Expand Up @@ -2786,7 +2803,7 @@ static gboolean on_document_update_tag_list_idle(gpointer data)

void document_update_tag_list_in_idle(GeanyDocument *doc)
{
if (editor_prefs.autocompletion_update_freq <= 0 || ! filetype_has_tags(doc->file_type))
if (editor_prefs.autocompletion_update_freq <= 0 || !document_has_tags(doc))
return;

/* prevent "stacking up" callback handlers, we only need one to run soon */
Expand Down
2 changes: 2 additions & 0 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ void document_set_data(GeanyDocument *doc, const gchar *key, gpointer data);
void document_set_data_full(GeanyDocument *doc, const gchar *key,
gpointer data, GDestroyNotify free_func);

gboolean document_has_tags(GeanyDocument *doc);

#endif /* GEANY_PRIVATE */

G_END_DECLS
Expand Down
34 changes: 23 additions & 11 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "highlighting.h"
#include "keybindings.h"
#include "main.h"
#include "pluginextension.h"
#include "prefs.h"
#include "projectprivate.h"
#include "sciwrappers.h"
Expand Down Expand Up @@ -319,7 +320,7 @@ static gboolean on_editor_button_press_event(GtkWidget *widget, GdkEventButton *
editor_find_current_word(editor, editor_info.click_pos,
current_word, sizeof current_word, NULL);
if (*current_word)
return symbols_goto_tag(current_word, TRUE);
return symbols_goto_tag(current_word, editor_info.click_pos, TRUE);
else
keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_MATCHINGBRACE);
return TRUE;
Expand Down Expand Up @@ -671,9 +672,13 @@ static gboolean reshow_calltip(gpointer data)

g_return_val_if_fail(calltip.sci != NULL, FALSE);

SSM(calltip.sci, SCI_CALLTIPCANCEL, 0, 0);
doc = document_get_current();

if (plugin_extension_calltips_provided(doc))
return FALSE;

SSM(calltip.sci, SCI_CALLTIPCANCEL, 0, 0);

if (doc && doc->editor->sci == calltip.sci)
{
/* we use the position where the calltip was previously started as SCI_GETCURRENTPOS
Expand Down Expand Up @@ -821,13 +826,15 @@ static void on_char_added(GeanyEditor *editor, SCNotification *nt)
case '(':
{
auto_close_chars(sci, pos, nt->ch);
/* show calltips */
editor_show_calltip(editor, --pos);
if (!plugin_extension_calltips_provided(editor->document))
/* show calltips */
editor_show_calltip(editor, --pos);
break;
}
case ')':
{ /* hide calltips */
if (SSM(sci, SCI_CALLTIPACTIVE, 0, 0))
if (SSM(sci, SCI_CALLTIPACTIVE, 0, 0) &&
!plugin_extension_calltips_provided(editor->document))
{
SSM(sci, SCI_CALLTIPCANCEL, 0, 0);
}
Expand Down Expand Up @@ -857,13 +864,15 @@ static void on_char_added(GeanyEditor *editor, SCNotification *nt)
case ':': /* C/C++ class:: syntax */
/* tag autocompletion */
default:
#if 0
if (! editor_start_auto_complete(editor, pos, FALSE))
request_reshowing_calltip(nt);
#else
editor_start_auto_complete(editor, pos, FALSE);
#endif
}

if (plugin_extension_calltips_provided(editor->document))
plugin_extension_calltips_show(editor->document, FALSE);

if (plugin_extension_autocomplete_provided(editor->document))
plugin_extension_autocomplete_perform(editor->document);

check_line_breaking(editor, pos);
}

Expand Down Expand Up @@ -1171,7 +1180,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi
break;

case SCN_CALLTIPCLICK:
if (nt->position > 0)
if (!plugin_extension_calltips_provided(doc) && nt->position > 0)
{
switch (nt->position)
{
Expand Down Expand Up @@ -2222,6 +2231,9 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc

g_return_val_if_fail(editor != NULL, FALSE);

if (plugin_extension_autocomplete_provided(editor->document))
return FALSE;

if (! editor_prefs.auto_complete_symbols && ! force)
return FALSE;

Expand Down
10 changes: 0 additions & 10 deletions src/filetypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,16 +1224,6 @@ GtkFileFilter *filetypes_create_file_filter(const GeanyFiletype *ft)
}


/* Indicates whether there is a tag parser for the filetype or not.
* Only works for custom filetypes if the filetype settings have been loaded. */
gboolean filetype_has_tags(GeanyFiletype *ft)
{
g_return_val_if_fail(ft != NULL, FALSE);

return ft->lang != TM_PARSER_NONE;
}


/** Finds a filetype pointer from its @a name field.
* @param name Filetype name.
* @return @transfer{none} @nullable The filetype found, or @c NULL.
Expand Down
2 changes: 0 additions & 2 deletions src/filetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ GtkFileFilter *filetypes_create_file_filter(const GeanyFiletype *ft);

GtkFileFilter *filetypes_create_file_filter_all_source(void);

gboolean filetype_has_tags(GeanyFiletype *ft);

gboolean filetypes_parse_error_message(GeanyFiletype *ft, const gchar *message,
gchar **filename, gint *line);

Expand Down
14 changes: 14 additions & 0 deletions src/geanyobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ static void create_signals(GObjectClass *g_object_class)
0, NULL, NULL, g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
GEANY_TYPE_DOCUMENT);
geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE_AS] = g_signal_new (
"document-before-save-as",
G_OBJECT_CLASS_TYPE (g_object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
GEANY_TYPE_DOCUMENT);
geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
"document-save",
G_OBJECT_CLASS_TYPE (g_object_class),
Expand Down Expand Up @@ -206,6 +213,13 @@ static void create_signals(GObjectClass *g_object_class)
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
geany_object_signals[GCB_SESSION_OPENING] = g_signal_new (
"session-opening",
G_OBJECT_CLASS_TYPE (g_object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
geany_object_signals[GCB_BUILD_START] = g_signal_new (
"build-start",
G_OBJECT_CLASS_TYPE (g_object_class),
Expand Down
2 changes: 2 additions & 0 deletions src/geanyobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ typedef enum
GCB_UPDATE_EDITOR_MENU,
GCB_EDITOR_NOTIFY,
GCB_GEANY_STARTUP_COMPLETE,
GCB_SESSION_OPENING,
GCB_BUILD_START,
GCB_SAVE_SETTINGS,
GCB_LOAD_SETTINGS,
GCB_KEY_PRESS_NOTIFY,
GCB_DOCUMENT_BEFORE_SAVE_AS,
GCB_MAX
}
GeanyCallbackId;
Expand Down
13 changes: 10 additions & 3 deletions src/keybindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "msgwindow.h"
#include "navqueue.h"
#include "notebook.h"
#include "pluginextension.h"
#include "prefs.h"
#include "sciwrappers.h"
#include "sidebar.h"
Expand Down Expand Up @@ -1974,7 +1975,7 @@ static void goto_tag(GeanyDocument *doc, gboolean definition)
gchar *text = get_current_word_or_sel(doc, FALSE);

if (text)
symbols_goto_tag(text, definition);
symbols_goto_tag(text, sci_get_current_position(doc->editor->sci), definition);
else
utils_beep();

Expand Down Expand Up @@ -2151,10 +2152,16 @@ static gboolean cb_func_editor_action(guint key_id)
sci_send_command(doc->editor->sci, SCI_LINETRANSPOSE);
break;
case GEANY_KEYS_EDITOR_AUTOCOMPLETE:
editor_start_auto_complete(doc->editor, sci_get_current_position(doc->editor->sci), TRUE);
if (plugin_extension_autocomplete_provided(doc))
plugin_extension_autocomplete_perform(doc);
else
editor_start_auto_complete(doc->editor, sci_get_current_position(doc->editor->sci), TRUE);
break;
case GEANY_KEYS_EDITOR_CALLTIP:
editor_show_calltip(doc->editor, -1);
if (plugin_extension_calltips_provided(doc))
plugin_extension_calltips_show(doc, TRUE);
else
editor_show_calltip(doc->editor, -1);
break;
case GEANY_KEYS_EDITOR_CONTEXTACTION:
if (check_current_word(doc, FALSE))
Expand Down
4 changes: 2 additions & 2 deletions src/keyfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ void configuration_open_files(GPtrArray *session_files)
gboolean failure = FALSE;

/* necessary to set it to TRUE for project session support */
main_status.opening_session_files++;
main_opening_session_files(TRUE);

for (guint i = 0; i < session_files->len; i++)
{
Expand All @@ -1382,7 +1382,7 @@ void configuration_open_files(GPtrArray *session_files)
document_show_tab_idle(session_notebook_page >= 0 ? document_get_from_page(session_notebook_page) : document_get_current());

session_notebook_page = -1;
main_status.opening_session_files--;
main_opening_session_files(FALSE);
}


Expand Down
16 changes: 14 additions & 2 deletions src/libmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,9 @@ gint main_lib(gint argc, gchar **argv)
tools_create_insert_custom_command_menu_items();

/* load any command line files or session files */
main_status.opening_session_files++;
main_opening_session_files(TRUE);
load_startup_files(argc, argv);
main_status.opening_session_files--;
main_opening_session_files(FALSE);

/* open a new file if no other file was opened */
document_new_file_if_non_open();
Expand Down Expand Up @@ -1448,3 +1448,15 @@ void main_reload_configuration(void)

ui_set_statusbar(TRUE, _("Configuration files reloaded."));
}


void main_opening_session_files(gboolean opening)
{
if (opening && !main_status.opening_session_files)
g_signal_emit_by_name(geany_object, "session-opening", TRUE);

main_status.opening_session_files += opening ? 1 : -1;

if (!opening && !main_status.opening_session_files)
g_signal_emit_by_name(geany_object, "session-opening", FALSE);
}
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ gint main_lib(gint argc, gchar **argv);

void main_init_headless(void);

void main_opening_session_files(gboolean opening);

#endif /* GEANY_PRIVATE */

G_END_DECLS
Expand Down
Loading