Added additional render mode + settings dialog
This commit is contained in:
parent
3e03b512e1
commit
a6299aa7ac
@ -492,4 +492,58 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkWindow" id="settingsDialog">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="destroy_with_parent">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">4</property>
|
||||||
|
<property name="margin_right">4</property>
|
||||||
|
<property name="margin_top">4</property>
|
||||||
|
<property name="margin_bottom">4</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Entry display mode:</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkComboBoxText" id="comboDisplayMode">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
@ -20,8 +20,9 @@ static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_da
|
|||||||
static void settings_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
static void settings_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
|
struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
|
||||||
|
struct mainWindow *a = user_data;
|
||||||
|
|
||||||
g_print("nTODO\n");
|
mainWindow_settings_show(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
const GActionEntry app_actions[] = {
|
const GActionEntry app_actions[] = {
|
||||||
|
103
src/mainwindow.c
103
src/mainwindow.c
@ -430,9 +430,9 @@ static void mainWindow_init_to_default(struct mainWindow *mainWindow)
|
|||||||
* @param mainWindow the mainWindow
|
* @param mainWindow the mainWindow
|
||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state)
|
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state)
|
||||||
{
|
{
|
||||||
if (state) {
|
if (state == RENDERER_HTML) {
|
||||||
if (!mainWindow->webkitView) {
|
if (!mainWindow->webkitView) {
|
||||||
mainWindow->webkitView = webkit_web_view_new();
|
mainWindow->webkitView = webkit_web_view_new();
|
||||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", "");
|
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", "");
|
||||||
@ -450,6 +450,66 @@ void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state
|
|||||||
gtk_stack_set_visible_child(GTK_STACK(mainWindow->stackRenderMode),
|
gtk_stack_set_visible_child(GTK_STACK(mainWindow->stackRenderMode),
|
||||||
mainWindow->entryTextScrollArea);
|
mainWindow->entryTextScrollArea);
|
||||||
}
|
}
|
||||||
|
mainWindow->renderer = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mainWindow_settings_combo_changed(GtkComboBox *widget, gpointer user_data)
|
||||||
|
{
|
||||||
|
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||||
|
|
||||||
|
if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "text"))
|
||||||
|
mainWindow_renderer_set(mainWindow, RENDERER_TEXT);
|
||||||
|
else if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "basic"))
|
||||||
|
mainWindow_renderer_set(mainWindow, RENDERER_BASIC);
|
||||||
|
else if (!strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode)), "html"))
|
||||||
|
mainWindow_renderer_set(mainWindow, RENDERER_HTML);
|
||||||
|
|
||||||
|
|
||||||
|
mainWindow_entrySelected(NULL, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean mainWindow_settings_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
||||||
|
{
|
||||||
|
gtk_widget_hide(widget);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainWindow_settings_show(struct mainWindow *mainWindow)
|
||||||
|
{
|
||||||
|
switch (mainWindow->renderer) {
|
||||||
|
case RENDERER_TEXT:
|
||||||
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "text");
|
||||||
|
break;
|
||||||
|
case RENDERER_BASIC:
|
||||||
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "basic");
|
||||||
|
break;
|
||||||
|
case RENDERER_HTML:
|
||||||
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboDisplayMode), "html");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
gtk_widget_show(mainWindow->settingsDialog.settingsDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mainWindow_configure_settings_dialog(struct mainWindow *mainWindow)
|
||||||
|
{
|
||||||
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
|
||||||
|
"text", "Text only");
|
||||||
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
|
||||||
|
"basic", "Basic formatting");
|
||||||
|
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboDisplayMode),
|
||||||
|
"html", "Full HTML with images");
|
||||||
|
|
||||||
|
g_signal_connect(mainWindow->settingsDialog.comboDisplayMode,
|
||||||
|
"changed",
|
||||||
|
(GCallback) mainWindow_settings_combo_changed,
|
||||||
|
mainWindow);
|
||||||
|
|
||||||
|
g_signal_connect(mainWindow->settingsDialog.settingsDialog,
|
||||||
|
"delete-event",
|
||||||
|
(GCallback) mainWindow_settings_delete_event,
|
||||||
|
mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -495,6 +555,9 @@ struct mainWindow *mainWindow_new()
|
|||||||
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
|
mainWindow->workspaceListSelection = GTK_TREE_SELECTION(gtk_builder_get_object(builder,
|
||||||
"treeWorkspaceSelection"));
|
"treeWorkspaceSelection"));
|
||||||
|
|
||||||
|
mainWindow->settingsDialog.settingsDialog = GTK_WIDGET(gtk_builder_get_object(builder, "settingsDialog"));
|
||||||
|
mainWindow->settingsDialog.comboDisplayMode = GTK_WIDGET(gtk_builder_get_object(builder, "comboDisplayMode"));
|
||||||
|
|
||||||
mainWindow->filterSettings.time_start = 0;
|
mainWindow->filterSettings.time_start = 0;
|
||||||
mainWindow->filterSettings.time_end = -1;
|
mainWindow->filterSettings.time_end = -1;
|
||||||
mainWindow->filterSettings.hide_all = TRUE;
|
mainWindow->filterSettings.hide_all = TRUE;
|
||||||
@ -506,6 +569,7 @@ struct mainWindow *mainWindow_new()
|
|||||||
g_object_unref(G_OBJECT(builder));
|
g_object_unref(G_OBJECT(builder));
|
||||||
|
|
||||||
mainWindow_configure_treeView(mainWindow);
|
mainWindow_configure_treeView(mainWindow);
|
||||||
|
mainWindow_configure_settings_dialog(mainWindow);
|
||||||
mainWindow->webkitView = NULL;
|
mainWindow->webkitView = NULL;
|
||||||
mainWindow->webkitScrollArea = NULL;
|
mainWindow->webkitScrollArea = NULL;
|
||||||
mainWindow_connect_signals(mainWindow);
|
mainWindow_connect_signals(mainWindow);
|
||||||
@ -515,7 +579,7 @@ struct mainWindow *mainWindow_new()
|
|||||||
mainWindow_configure_entry_completion(mainWindow);
|
mainWindow_configure_entry_completion(mainWindow);
|
||||||
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
|
mainWindow_set_meta_information(mainWindow, 0, 0, TRUE);
|
||||||
|
|
||||||
mainWindow_webkit_set_enabled(mainWindow, TRUE);
|
mainWindow_renderer_set(mainWindow, RENDERER_HTML);
|
||||||
|
|
||||||
return mainWindow;
|
return mainWindow;
|
||||||
}
|
}
|
||||||
@ -601,11 +665,12 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
|||||||
gchar *cmd_stderr = NULL;
|
gchar *cmd_stderr = NULL;
|
||||||
gint exit_status = 0;
|
gint exit_status = 0;
|
||||||
gchar *base_url = NULL;
|
gchar *base_url = NULL;
|
||||||
GFileOutputStream *stream;
|
GFileOutputStream *stream = NULL;
|
||||||
GFile *file;
|
GFile *file = NULL;
|
||||||
|
|
||||||
if (mainWindow->webkitView &&
|
if (mainWindow->renderer == RENDERER_TEXT) {
|
||||||
gtk_stack_get_visible_child(GTK_STACK(mainWindow->stackRenderMode)) == mainWindow->webkitScrollArea) {
|
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
||||||
|
} else {
|
||||||
if (text[0] != '\0') {
|
if (text[0] != '\0') {
|
||||||
base_url = g_strdup_printf("file://%s", file_url);
|
base_url = g_strdup_printf("file://%s", file_url);
|
||||||
file = g_file_new_for_path(tempfile_path);
|
file = g_file_new_for_path(tempfile_path);
|
||||||
@ -619,28 +684,46 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
|||||||
cmd = g_strdup_printf("markdown %s", tempfile_path);
|
cmd = g_strdup_printf("markdown %s", tempfile_path);
|
||||||
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
|
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
|
||||||
exit_status == 0) {
|
exit_status == 0) {
|
||||||
|
if (mainWindow->renderer == RENDERER_BASIC) {
|
||||||
|
/* TODO: This renderer is broken. Pango does not like HTML... */
|
||||||
|
GtkTextIter iter;
|
||||||
|
gtk_text_buffer_set_text(mainWindow->textBuffer, "", 0);
|
||||||
|
gtk_text_buffer_get_start_iter(mainWindow->textBuffer, &iter);
|
||||||
|
gtk_text_buffer_insert_markup(mainWindow->textBuffer,
|
||||||
|
&iter,
|
||||||
|
cmd_stdout,
|
||||||
|
strlen(cmd_stdout));
|
||||||
|
} else {
|
||||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||||
cmd_stdout, base_url);
|
cmd_stdout, base_url);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g_warning("Could not render markdown for file. Showing plain text instead.\n");
|
g_warning("Could not render markdown for file. Showing plain text instead.\n");
|
||||||
|
if (mainWindow->renderer == RENDERER_BASIC) {
|
||||||
|
gtk_text_buffer_set_text(mainWindow->textBuffer,
|
||||||
|
cmd_stdout, strlen(cmd_stdout));
|
||||||
|
} else {
|
||||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||||
text, base_url);
|
text, base_url);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_free(base_url);
|
g_free(base_url);
|
||||||
} else {
|
} else {
|
||||||
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||||
text, "");
|
text, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
|
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
|
||||||
g_file_delete(file, NULL, NULL);
|
|
||||||
g_object_unref(stream);
|
g_object_unref(stream);
|
||||||
|
}
|
||||||
|
if (file) {
|
||||||
|
g_file_delete(file, NULL, NULL);
|
||||||
g_object_unref(file);
|
g_object_unref(file);
|
||||||
|
}
|
||||||
g_free(cmd);
|
g_free(cmd);
|
||||||
g_free(cmd_stdout);
|
g_free(cmd_stdout);
|
||||||
g_free(cmd_stderr);
|
g_free(cmd_stderr);
|
||||||
} else {
|
|
||||||
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@ enum {
|
|||||||
WSCOL_COUNT
|
WSCOL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum renderer_mode {
|
||||||
|
RENDERER_TEXT = 0,
|
||||||
|
RENDERER_BASIC,
|
||||||
|
RENDERER_HTML
|
||||||
|
};
|
||||||
|
|
||||||
struct mainWindow {
|
struct mainWindow {
|
||||||
GtkWidget *mainWindow;
|
GtkWidget *mainWindow;
|
||||||
GtkWidget *mainPane;
|
GtkWidget *mainPane;
|
||||||
@ -47,6 +53,8 @@ struct mainWindow {
|
|||||||
GtkWidget *selectedDateEntry;
|
GtkWidget *selectedDateEntry;
|
||||||
GtkTreeModelFilter *entryListFiltered;
|
GtkTreeModelFilter *entryListFiltered;
|
||||||
|
|
||||||
|
enum renderer_mode renderer;
|
||||||
|
|
||||||
gint64 time_earliest;
|
gint64 time_earliest;
|
||||||
gint64 time_latest;
|
gint64 time_latest;
|
||||||
|
|
||||||
@ -67,6 +75,11 @@ struct mainWindow {
|
|||||||
GtkTreeSelection *workspaceListSelection;
|
GtkTreeSelection *workspaceListSelection;
|
||||||
GtkListStore *workspaceListStore;
|
GtkListStore *workspaceListStore;
|
||||||
GtkTreeModelFilter *workspaceListFiltered;
|
GtkTreeModelFilter *workspaceListFiltered;
|
||||||
|
|
||||||
|
struct settingsDialog {
|
||||||
|
GtkWidget *settingsDialog;
|
||||||
|
GtkWidget *comboDisplayMode;
|
||||||
|
} settingsDialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mainWindow *mainWindow_new();
|
struct mainWindow *mainWindow_new();
|
||||||
@ -90,6 +103,7 @@ void mainWindow_dateIconPress(GtkWidget *widget, gint icon_pos, gint event, gpoi
|
|||||||
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append);
|
void mainWindow_add_recent_workspace(struct mainWindow *mainWindow, gchar *path, gboolean append);
|
||||||
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled);
|
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled);
|
||||||
void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data);
|
void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data);
|
||||||
void mainWindow_webkit_set_enabled(struct mainWindow *mainWindow, gboolean state);
|
void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state);
|
||||||
|
void mainWindow_settings_show(struct mainWindow *mainWindow);
|
||||||
|
|
||||||
#endif /* MAINWINDOW_H */
|
#endif /* MAINWINDOW_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user