Permalink
Browse files

markdown: Massive refactoring

* Make MarkdownViewer a GObject, and a subclass of WebKitWebView
* A MarkdownViewer "has a" MarkdownConfig property
* Optimize (somewhat) string handling/duplication also using changes
  to Discount code.
* Main plugin code manages the scrolled window holding the
  MarkdownViewer and monitors the MarkdownViewer's MarkdownConfig
  for property changes to know when to move the scrolled window
  between the sidebar and message window notebooks.
* Various other cleanups and changes
  • Loading branch information...
1 parent 9e68cc2 commit bc9b59029b5263600b3ce56e9e03fa9059680b47 @codebrainz committed Jul 17, 2012
Showing with 470 additions and 278 deletions.
  1. +26 −3 markdown/src/conf.c
  2. +9 −7 markdown/src/conf.h
  3. +128 −117 markdown/src/plugin.c
  4. +276 −136 markdown/src/viewer.c
  5. +31 −15 markdown/src/viewer.h
View
@@ -1,5 +1,5 @@
/*
- * markdownconfig.c
+ * config.c - Part of the Geany Markdown plugin
*
* Copyright 2012 Matthew Brush <mbrush@codebrainz.ca>
*
@@ -83,6 +83,7 @@ struct _MarkdownConfigPrivate
gchar filename[PATH_MAX];
GKeyFile *kf;
guint handle;
+ guint dlg_handle;
gboolean initialized;
gchar *tmpl_text;
gsize tmpl_text_len;
@@ -432,7 +433,7 @@ markdown_config_save(MarkdownConfig *conf)
contents = g_key_file_to_data(conf->priv->kf, &len, &error);
- g_debug("Saving: %s\n%s", conf->priv->filename, contents);
+ //g_debug("Saving: %s\n%s", conf->priv->filename, contents);
if (error) {
g_warning("Error getting config data as string: %s", error->message);
@@ -666,7 +667,8 @@ GtkWidget *markdown_config_gui(MarkdownConfig *conf, GtkDialog *dialog)
g_free(tmpl_file);
}
- g_signal_connect_swapped(dialog, "response", G_CALLBACK(on_dialog_response), conf);
+ conf->priv->dlg_handle = g_signal_connect_swapped(dialog, "response",
+ G_CALLBACK(on_dialog_response), conf);
gtk_widget_show_all(table);
@@ -682,3 +684,24 @@ markdown_config_get_template_text(MarkdownConfig *conf)
}
return (const gchar *) conf->priv->tmpl_text;
}
+
+gchar *
+markdown_config_get_dirname(MarkdownConfig *conf)
+{
+ g_return_val_if_fail(conf, NULL);
+ return g_path_get_dirname(conf->priv->filename);
+}
+
+MarkdownConfigViewPos markdown_config_get_view_pos(MarkdownConfig *conf)
+{
+ guint view_pos;
+ g_return_val_if_fail(MARKDOWN_IS_CONFIG(conf), MARKDOWN_CONFIG_VIEW_POS_SIDEBAR);
+ g_object_get(conf, "view-pos", &view_pos, NULL);
+ return (MarkdownConfigViewPos) view_pos;
+}
+
+void markdown_config_set_view_pos(MarkdownConfig *conf, MarkdownConfigViewPos view_pos)
+{
+ g_return_if_fail(MARKDOWN_IS_CONFIG(conf));
+ g_object_set(conf, "view-pos", view_pos, NULL);
+}
View
@@ -1,5 +1,5 @@
/*
- * markdownconfig.h
+ * config.h - Part of the Geany Markdown plugin
*
* Copyright 2012 Matthew Brush <mbrush@codebrainz.ca>
*
@@ -21,16 +21,14 @@
*
*/
-
-#ifndef __MARKDOWNCONFIG_H__
-#define __MARKDOWNCONFIG_H__
+#ifndef MARKDOWN_CONF_H
+#define MARKDOWN_CONF_H 1
#include <gtk/gtk.h>
#include <glib-object.h>
G_BEGIN_DECLS
-
#define MARKDOWN_TYPE_CONFIG (markdown_config_get_type ())
#define MARKDOWN_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MARKDOWN_TYPE_CONFIG, MarkdownConfig))
#define MARKDOWN_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MARKDOWN_TYPE_CONFIG, MarkdownConfigClass))
@@ -59,14 +57,18 @@ struct _MarkdownConfigClass
GObjectClass parent_class;
};
-
GType markdown_config_get_type(void);
MarkdownConfig *markdown_config_new(const gchar *filename);
gboolean markdown_config_save(MarkdownConfig *conf);
GtkWidget *markdown_config_gui(MarkdownConfig *conf, GtkDialog *dialog);
const gchar *markdown_config_get_template_text(MarkdownConfig *conf);
+gchar *markdown_config_get_dirname(MarkdownConfig *conf);
+
+/* Property accessors */
+MarkdownConfigViewPos markdown_config_get_view_pos(MarkdownConfig *conf);
+void markdown_config_set_view_pos(MarkdownConfig *conf, MarkdownConfigViewPos view_pos);
G_END_DECLS
-#endif /* __MARKDOWNCONFIG_H__ */
+#endif /* MARKDOWN_CONF_H */
Oops, something went wrong.

0 comments on commit bc9b590

Please sign in to comment.