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

Markdown: Update using known GeanyDocument when available #1064

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions markdown/src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static GtkWidget *g_scrolled_win = NULL;
static GtkWidget *g_export_html = NULL;

/* Forward declarations */
static void update_markdown_viewer(MarkdownViewer *viewer);
static void update_markdown_viewer(MarkdownViewer *viewer, GeanyDocument *doc);
static gboolean on_editor_notify(GObject *obj, GeanyEditor *editor, SCNotification *notif, MarkdownViewer *viewer);
static void on_document_signal(GObject *obj, GeanyDocument *doc, MarkdownViewer *viewer);
static void on_document_filetype_set(GObject *obj, GeanyDocument *doc, GeanyFiletype *ft_old, MarkdownViewer *viewer);
Expand Down Expand Up @@ -120,7 +120,7 @@ void plugin_init(GeanyData *data)
* and when reloaded tries to re-register the GTypes. */
plugin_module_make_resident(geany_plugin);

update_markdown_viewer(MARKDOWN_VIEWER(viewer));
update_markdown_viewer(MARKDOWN_VIEWER(viewer), NULL);
}

/* Cleanup resources on plugin unload. */
Expand Down Expand Up @@ -162,9 +162,10 @@ void plugin_help(void)
* editor's text contents change and not on other editor events.
*/
static void
update_markdown_viewer(MarkdownViewer *viewer)
update_markdown_viewer(MarkdownViewer *viewer, GeanyDocument *doc)
{
GeanyDocument *doc = document_get_current();
if (!DOC_VALID(doc))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't simply doc == NULL work here? Do you really get non-NULL doc pointers that have doc->valid == FALSE?

doc = document_get_current();

if (DOC_VALID(doc) && g_strcmp0(doc->file_type->name, "Markdown") == 0) {
gchar *text;
Expand Down Expand Up @@ -192,7 +193,7 @@ static gboolean on_editor_notify(GObject *obj, GeanyEditor *editor,
SCNotification *notif, MarkdownViewer *viewer)
{
if (IS_MOD_NOTIF(notif)) {
update_markdown_viewer(viewer);
update_markdown_viewer(viewer, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
update_markdown_viewer(viewer, NULL);
update_markdown_viewer(viewer, editor->document);

}
return FALSE; /* Allow others to handle this event too */
}
Expand All @@ -201,14 +202,14 @@ static gboolean on_editor_notify(GObject *obj, GeanyEditor *editor,
* activate, etc.) */
static void on_document_signal(GObject *obj, GeanyDocument *doc, MarkdownViewer *viewer)
{
update_markdown_viewer(viewer);
update_markdown_viewer(viewer, doc);
}

/* Queue update of the markdown preview when a document's filetype is set */
static void on_document_filetype_set(GObject *obj, GeanyDocument *doc, GeanyFiletype *ft_old,
MarkdownViewer *viewer)
{
update_markdown_viewer(viewer);
update_markdown_viewer(viewer, doc);
}

/* Move the MarkdownViewer to the correct notebook when the view position
Expand Down Expand Up @@ -248,7 +249,7 @@ on_view_pos_notify(GObject *obj, GParamSpec *pspec, MarkdownViewer *viewer)

g_object_unref(g_scrolled_win); /* The new notebook owns it now */

update_markdown_viewer(viewer);
update_markdown_viewer(viewer, NULL);
}

static gchar *replace_extension(const gchar *utf8_fn, const gchar *new_ext)
Expand Down