1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-05 03:38:05 +02:00

eeshow/: make WebKit optional; add Gtk-based fallback viewer

This commit is contained in:
Werner Almesberger 2016-08-19 17:35:41 -03:00
parent 490a9b9e49
commit c612cd331b
4 changed files with 96 additions and 13 deletions

View File

@ -27,13 +27,19 @@ CFLAGS = -g -Wall -Wextra -Wno-unused-parameter -Wshadow \
-I. \
`pkg-config --cflags cairo` \
`pkg-config --cflags libgit2` \
`pkg-config --cflags gtk+-3.0` \
`pkg-config --cflags webkit2gtk-4.0`
`pkg-config --cflags gtk+-3.0`
LDLIBS = -lm \
`pkg-config --libs cairo` \
`pkg-config --libs libgit2` \
`pkg-config --libs gtk+-3.0` \
`pkg-config --libs webkit2gtk-4.0`
`pkg-config --libs gtk+-3.0`
ifneq ($(USE_WEBKIT),)
CFLAGS += -DUSE_WEBKIT `pkg-config --cflags webkit2gtk-4.0`
LDLIBS += `pkg-config --libs webkit2gtk-4.0`
HELP_TEXT = help.html
else
HELP_TEXT = help.txt
endif
include ../common/Makefile.c-common
@ -44,8 +50,9 @@ all:: $(NAME)
$(NAME): $(OBJS)
$(CC) -o $(NAME) $(OBJS) $(LDLIBS)
help.inc: help.html
$(BUILD) sed 's/.*/"&"/' $< >$@ || { rm -f $@; exit 1; }
help.inc: $(HELP_TEXT) Makefile
$(BUILD) sed 's/"/\\"/g;s/.*/"&\\n"/' $< >$@ || \
{ rm -f $@; exit 1; }
gui/help.c: help.inc

View File

@ -13,7 +13,10 @@
#include <stdbool.h>
#include <gtk/gtk.h>
#ifdef USE_WEBKIT
#include <webkit2/webkit2.h>
#endif
#include "gui/help.h"
@ -29,25 +32,81 @@ static void destroy_help(GtkWidget *object, gpointer user_data)
}
static void new_help_window(void)
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
gpointer data)
{
switch (event->keyval) {
case GDK_KEY_h:
case GDK_KEY_question:
case GDK_KEY_q:
gtk_widget_hide(window);
visible = 0;
break;
}
return TRUE;
}
#ifdef USE_WEBKIT
static GtkWidget *help_content(void)
{
GtkWidget *view;
WebKitSettings *settings;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
view = webkit_web_view_new();
settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(view));
webkit_settings_set_default_font_size(settings, 10);
gtk_container_add(GTK_CONTAINER(window), view);
gtk_window_set_default_size(GTK_WINDOW(window), 480, 360);
gtk_widget_show_all(window);
webkit_web_view_load_html(WEBKIT_WEB_VIEW(view),
#include "../help.inc"
, NULL);
return view;
}
#else /* USE_WEBKIT */
static GtkWidget *help_content(void)
{
GtkWidget *scroll, *label;
scroll = gtk_scrolled_window_new(NULL, NULL);
label = gtk_label_new(NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_markup(GTK_LABEL(label),
#include "../help.inc"
);
gtk_container_add(GTK_CONTAINER(scroll), label);
return scroll;
}
#endif /* !USE_WEBKIT */
static void new_help_window(void)
{
GtkWidget *content;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
content = help_content();
gtk_container_add(GTK_CONTAINER(window), content);
gtk_window_set_default_size(GTK_WINDOW(window), 480, 360);
gtk_widget_show_all(window);
gtk_widget_set_can_focus(content, TRUE);
gtk_widget_add_events(content, GDK_KEY_PRESS_MASK);
g_signal_connect(G_OBJECT(content), "key_press_event",
G_CALLBACK(key_press_event), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(destroy_help), NULL);
gtk_widget_show_all(window);

View File

@ -42,7 +42,7 @@
<TD>show older sheet
<TR>
<TD>Q
<TD>quit the vieweer
<TD>quit the viewer
</TABLE>
</BODY>
</HTML>

17
eeshow/help.txt Normal file
View File

@ -0,0 +1,17 @@
<span font_desc="Mono 10">
+ or = zoom in
- zoom out
* zoom to extents
Home go to the top sheet
Delete or
Backspace go to the next higher sheet in hierarchy
PgUp go to the previous sheet in sequence
PgDn go to the next sheet in sequence
Up or Down invoke the revision history (WIP)
Tab toggle between old and new revision
? or H show/hide help window
D when comparing revisions, show difference
N show newer sheet
O show older sheet
Q quit the viewer
</span>