Merged new-combo branch (again)

svn merge -r 978:985 svn+ssh://svn.berlios.de/svnroot/repos/ggap/moo/branches/new-combo
master
Yevgen Muntyan 2005-11-23 11:10:03 +00:00
parent c64bc0467c
commit 6be577cd37
16 changed files with 894 additions and 42 deletions

View File

@ -33,7 +33,7 @@
<kdevautoproject>
<general>
<activetarget>moo/libmoo.la</activetarget>
<useconfiguration>debug</useconfiguration>
<useconfiguration>optimized</useconfiguration>
</general>
<run>
<mainprogram>./medit</mainprogram>
@ -268,16 +268,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" name="GAP source" create="template" >
<type icon="source" ext="g" create="template" name="GAP source" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" name="C Source" create="template" >
<type icon="source_c" ext="c" create="template" name="C Source" >
<descr>A new empty C file.</descr>
</type>
</filetypes>

View File

@ -4,3 +4,4 @@ mooterm/mootermline.h: #if 0...
mooterm: remove dependency on yacc
mooedit/moohighlighter.c:iter_get_syntax_tag(): #if 0 ...
mooedit/moolang.h; mooedit/moolang-rules.c: Rule::debug_string
mooedit/mooeditprefs.c: remove Courier New

View File

@ -82,6 +82,9 @@ struct _MooAppPrivate {
char *tmpdir;
gboolean use_python_console;
gboolean new_app;
char **open_files;
};
@ -179,7 +182,9 @@ enum {
PROP_RUN_OUTPUT,
PROP_USE_EDITOR,
PROP_USE_TERMINAL,
PROP_USE_PYTHON_CONSOLE
PROP_USE_PYTHON_CONSOLE,
PROP_OPEN_FILES,
PROP_NEW_APP
};
enum {
@ -305,6 +310,21 @@ moo_app_class_init (MooAppClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_OPEN_FILES,
g_param_spec_pointer ("open-files",
"open-files",
"open-files",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_NEW_APP,
g_param_spec_boolean ("new-app",
"new-app",
"new-app",
FALSE,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
signals[INIT] =
g_signal_new ("init",
G_OBJECT_CLASS_TYPE (klass),
@ -312,7 +332,7 @@ moo_app_class_init (MooAppClass *klass)
G_STRUCT_OFFSET (MooAppClass, init),
NULL, NULL,
_moo_marshal_BOOLEAN__VOID,
G_TYPE_STRING, 0);
G_TYPE_BOOLEAN, 0);
signals[RUN] =
g_signal_new ("run",
@ -495,6 +515,20 @@ moo_app_set_property (GObject *object,
app->priv->use_python_console = g_value_get_boolean (value);
break;
case PROP_NEW_APP:
app->priv->new_app = g_value_get_boolean (value);
break;
case PROP_OPEN_FILES:
g_strfreev (app->priv->open_files);
app->priv->open_files = g_strdupv (g_value_get_pointer (value));
if (app->priv->open_files && !*app->priv->open_files)
{
g_strfreev (app->priv->open_files);
app->priv->open_files = NULL;
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -849,6 +883,49 @@ moo_app_init_real (MooApp *app)
MooUIXML *ui_xml;
GError *error = NULL;
if (!app->priv->new_app)
{
char **p;
GString *msg = g_string_new (NULL);
if (!app->priv->open_files || !*(app->priv->open_files))
g_string_append_len (msg, CMD_PRESENT, strlen (CMD_PRESENT) + 1);
for (p = app->priv->open_files; p && *p; ++p)
{
char *freeme = NULL;
const char *basename, *filename;
basename = *p;
if (g_path_is_absolute (basename))
{
filename = basename;
}
else
{
char *dir = g_get_current_dir ();
freeme = g_build_filename (dir, basename, NULL);
filename = freeme;
g_free (dir);
}
g_string_append_len (msg, CMD_OPEN_FILE, strlen (CMD_OPEN_FILE));
g_string_append_len (msg, filename, strlen (filename) + 1);
g_free (freeme);
}
if (moo_app_send_msg (app, msg->str, msg->len))
{
g_string_free (msg, TRUE);
goto exit;
}
g_string_free (msg, TRUE);
}
app->priv->new_app = TRUE;
gdk_set_program_class (app->priv->info->full_name);
#ifdef __WIN32__
@ -939,6 +1016,10 @@ moo_app_init_real (MooApp *app)
start_io (app);
return TRUE;
exit:
app->priv->new_app = FALSE;
return FALSE;
}
@ -1047,14 +1128,37 @@ static gboolean on_gtk_main_quit (MooApp *app)
}
static int moo_app_run_real (MooApp *app)
static int
moo_app_run_real (MooApp *app)
{
g_return_val_if_fail (!app->priv->running, 0);
app->priv->running = TRUE;
if (!app->priv->new_app)
return 0;
app->priv->quit_handler_id =
gtk_quit_add (0, (GtkFunction) on_gtk_main_quit, app);
if (app->priv->open_files)
{
char **file;
MooEditor *editor;
MooEditWindow *window;
editor = moo_app_get_editor (app);
window = moo_editor_get_active_window (editor);
if (!window)
window = moo_editor_new_window (editor);
for (file = app->priv->open_files; file && *file; ++file)
moo_editor_open_file (editor, window, NULL, *file, NULL);
g_strfreev (app->priv->open_files);
app->priv->open_files = NULL;
}
gtk_main ();
return app->priv->exit_code;
@ -1155,19 +1259,23 @@ static void moo_app_quit_real (MooApp *app)
}
void moo_app_init (MooApp *app)
gboolean
moo_app_init (MooApp *app)
{
g_return_if_fail (MOO_IS_APP (app));
MOO_APP_GET_CLASS(app)->init (app);
gboolean retval;
g_return_val_if_fail (MOO_IS_APP (app), FALSE);
g_signal_emit (app, signals[INIT], 0, &retval);
return retval;
}
int moo_app_run (MooApp *app)
int
moo_app_run (MooApp *app)
{
int retval;
g_return_val_if_fail (MOO_IS_APP (app), -1);
return MOO_APP_GET_CLASS(app)->run (app);
g_signal_emit (app, signals[RUN], 0, &retval);
return retval;
}

View File

@ -87,7 +87,7 @@ GType moo_app_window_policy_get_type (void) G_GNUC_CONST;
MooApp *moo_app_get_instance (void);
void moo_app_init (MooApp *app);
gboolean moo_app_init (MooApp *app);
int moo_app_run (MooApp *app);
gboolean moo_app_quit (MooApp *app);

View File

@ -78,6 +78,8 @@ enum {
COMMENT,
UNCOMMENT,
VARIABLE_CHANGED,
SAVE_BEFORE,
SAVE_AFTER,
LAST_SIGNAL
};
@ -163,6 +165,24 @@ moo_edit_class_init (MooEditClass *klass)
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[SAVE_BEFORE] =
g_signal_new ("save-before",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MooEditClass, save_before),
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[SAVE_AFTER] =
g_signal_new ("save-after",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MooEditClass, save_after),
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/* TODO: this is wrong */
_moo_edit_set_default_settings ();
}

View File

@ -87,16 +87,19 @@ struct _MooEditClass
/* emitted when filename, modified status, or file on disk
are changed. for use in editor to adjust title bar, etc. */
void (* doc_status_changed) (MooEdit *edit);
void (* doc_status_changed) (MooEdit *edit);
void (* filename_changed) (MooEdit *edit,
const char *new_filename);
void (* filename_changed) (MooEdit *edit,
const char *new_filename);
void (* lang_changed) (MooEdit *edit);
void (* lang_changed) (MooEdit *edit);
void (* variable_changed) (MooEdit *edit,
const char *variable,
const char *value);
void (* variable_changed) (MooEdit *edit,
const char *variable,
const char *value);
void (* save_before) (MooEdit *edit);
void (* save_after) (MooEdit *edit);
};

View File

@ -274,8 +274,9 @@ _moo_text_view_move_cursor (GtkTextView *text_view,
GtkTextBuffer *buffer;
GtkTextMark *insert;
GtkTextIter iter;
MooTextView *view = MOO_TEXT_VIEW (text_view);
if (!text_view->cursor_visible)
if (!text_view->cursor_visible && !view->priv->overwrite_mode)
return GTK_TEXT_VIEW_CLASS (parent_class())->move_cursor (text_view, step, count, extend_selection);
buffer = gtk_text_view_get_buffer (text_view);
@ -293,10 +294,31 @@ _moo_text_view_move_cursor (GtkTextView *text_view,
break;
default:
return GTK_TEXT_VIEW_CLASS (parent_class())->move_cursor (text_view, step, count, extend_selection);
if (view->priv->overwrite_mode)
gtk_text_view_set_cursor_visible (text_view, TRUE);
GTK_TEXT_VIEW_CLASS (parent_class())->move_cursor (text_view, step, count, extend_selection);
if (view->priv->overwrite_mode)
gtk_text_view_set_cursor_visible (text_view, FALSE);
return;
}
move_cursor_to (text_view, &iter, extend_selection);
_moo_text_view_pend_cursor_blink (view);
}
void
_moo_text_view_page_horizontally (GtkTextView *text_view,
int count,
gboolean extend_selection)
{
MooTextView *view = MOO_TEXT_VIEW (text_view);
if (view->priv->overwrite_mode)
gtk_text_view_set_cursor_visible (text_view, TRUE);
GTK_TEXT_VIEW_CLASS (parent_class())->page_horizontally (text_view, count, extend_selection);
if (view->priv->overwrite_mode)
gtk_text_view_set_cursor_visible (text_view, FALSE);
_moo_text_view_pend_cursor_blink (view);
}
@ -943,6 +965,7 @@ _moo_text_view_key_press_event (GtkWidget *widget,
view->priv->in_key_press = FALSE;
_moo_text_view_check_char_inserted (view);
_moo_text_view_pend_cursor_blink (view);
return handled;
}

View File

@ -1376,6 +1376,7 @@ do_save (MooEditor *editor,
const char *encoding,
GError **error)
{
gboolean result;
gboolean strip_whitespace = FALSE;
const char *var;
@ -1390,8 +1391,12 @@ do_save (MooEditor *editor,
if (strip_whitespace)
moo_text_view_strip_whitespace (MOO_TEXT_VIEW (doc));
return moo_edit_saver_save (saver, doc, filename, encoding,
moo_editor_get_save_flags (editor), error);
g_signal_emit_by_name (doc, "save-before");
result = moo_edit_saver_save (saver, doc, filename, encoding,
moo_editor_get_save_flags (editor), error);
g_signal_emit_by_name (doc, "save-after");
return result;
}

View File

@ -200,7 +200,7 @@ apply_tag (MooHighlighter *hl,
if (tag)
{
line->hl_info->tags = g_slist_prepend (line->hl_info->tags, tag);
line->hl_info->tags = g_slist_prepend (line->hl_info->tags, g_object_ref (tag));
hl->last_tag = tag;
_moo_text_buffer_apply_syntax_tag (MOO_TEXT_BUFFER (hl->buffer), tag, start, end);
}
@ -450,6 +450,7 @@ hl_compute_line (MooHighlighter *hl,
while (tags)
{
gtk_text_buffer_remove_tag (hl->buffer, tags->data, &start, &end);
g_object_unref (tags->data);
tags = g_slist_delete_link (tags, tags);
}
}
@ -820,6 +821,7 @@ moo_highlighter_apply_tags (MooHighlighter *hl,
while (tags)
{
gtk_text_buffer_remove_tag (hl->buffer, tags->data, &t_start, &t_end);
g_object_unref (tags->data);
tags = g_slist_delete_link (tags, tags);
}

View File

@ -853,7 +853,7 @@ lang_mgr_get_lang_for_bak_filename (MooLangMgr *mgr,
if (base)
{
char *opsys_name = g_filename_from_utf8 (utf8_name, len, NULL, NULL, NULL);
char *opsys_name = g_filename_from_utf8 (base, len, NULL, NULL, NULL);
if (opsys_name)
lang = moo_lang_mgr_get_lang_for_filename (mgr, opsys_name);

View File

@ -218,6 +218,7 @@ hl_info_free (HLInfo *info)
{
#ifdef __MOO__
g_free (info->segments);
g_slist_foreach (info->tags, (GFunc) g_object_unref, NULL);
g_slist_free (info->tags);
hl_info_free__ (info);
#endif

View File

@ -57,6 +57,9 @@ void _moo_text_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step,
gint count,
gboolean extend_selection);
void _moo_text_view_page_horizontally (GtkTextView *text_view,
int count,
gboolean extend_selection);
void _moo_text_view_delete_from_cursor (GtkTextView *text_view,
GtkDeleteType type,
gint count);
@ -76,6 +79,7 @@ int _moo_text_view_extend_selection (MooTextView *view,
GtkTextIter *selection_bound);
void _moo_text_view_check_char_inserted (MooTextView *view);
void _moo_text_view_pend_cursor_blink (MooTextView *view);
typedef enum {
@ -91,6 +95,12 @@ struct _MooTextViewPrivate {
/* Clipboard */
gboolean manage_clipboard;
/* Overwrite mode cursor */
gboolean overwrite_mode;
gboolean saved_cursor_visible;
gboolean cursor_visible;
guint blink_timeout;
/***********************************************************************/
/* Drawing
/*/

View File

@ -46,6 +46,10 @@ static void moo_text_view_realize (GtkWidget *widget);
static void moo_text_view_unrealize (GtkWidget *widget);
static gboolean moo_text_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static gboolean moo_text_view_focus_in (GtkWidget *widget,
GdkEventFocus *event);
static gboolean moo_text_view_focus_out (GtkWidget *widget,
GdkEventFocus *event);
static void moo_text_view_cut_clipboard (GtkTextView *text_view);
static void moo_text_view_paste_clipboard (GtkTextView *text_view);
@ -89,6 +93,11 @@ static void highlighting_changed (GtkTextView *view,
const GtkTextIter *start,
const GtkTextIter *end);
static void overwrite_changed (MooTextView *view);
static void check_cursor_blink (MooTextView *view);
static void moo_text_view_draw_cursor (GtkTextView *view,
GdkEventExpose *event);
enum {
DELETE_SELECTION,
@ -148,6 +157,8 @@ static void moo_text_view_class_init (MooTextViewClass *klass)
widget_class->realize = moo_text_view_realize;
widget_class->unrealize = moo_text_view_unrealize;
widget_class->expose_event = moo_text_view_expose;
widget_class->focus_in_event = moo_text_view_focus_in;
widget_class->focus_out_event = moo_text_view_focus_out;
#if 0
widget_class->drag_data_received = _moo_text_view_drag_data_received;
widget_class->drag_drop = _moo_text_view_drag_drop;
@ -156,6 +167,7 @@ static void moo_text_view_class_init (MooTextViewClass *klass)
#endif
text_view_class->move_cursor = _moo_text_view_move_cursor;
text_view_class->page_horizontally = _moo_text_view_page_horizontally;
text_view_class->delete_from_cursor = _moo_text_view_delete_from_cursor;
text_view_class->cut_clipboard = moo_text_view_cut_clipboard;
text_view_class->paste_clipboard = moo_text_view_paste_clipboard;
@ -459,6 +471,8 @@ moo_text_view_constructor (GType type,
view->priv->dnd_mark = gtk_text_buffer_create_mark (get_buffer (view), NULL, &iter, FALSE);
gtk_text_mark_set_visible (view->priv->dnd_mark, FALSE);
g_signal_connect (view, "notify::overwrite", G_CALLBACK (overwrite_changed), NULL);
return object;
}
@ -1269,6 +1283,13 @@ moo_text_view_unrealize (GtkWidget *widget)
add_selection_clipboard (view);
}
if (view->priv->blink_timeout)
{
g_warning ("%s: oops", G_STRLOC);
g_source_remove (view->priv->blink_timeout);
view->priv->blink_timeout = 0;
}
GTK_WIDGET_CLASS(moo_text_view_parent_class)->unrealize (widget);
}
@ -1472,6 +1493,9 @@ moo_text_view_expose (GtkWidget *widget,
if (event->window == text_window && view->priv->draw_trailing_spaces)
moo_text_view_draw_trailing_spaces (text_view, event, &start, &end);
if (event->window == text_window && view->priv->cursor_visible)
moo_text_view_draw_cursor (text_view, event);
return handled;
}
@ -1764,3 +1788,223 @@ moo_text_view_populate_popup (GtkTextView *text_view,
g_signal_connect_swapped (item, "activate", G_CALLBACK (moo_text_view_undo), view);
gtk_widget_set_sensitive (item, moo_text_view_can_undo (view));
}
static void
overwrite_changed (MooTextView *view)
{
GtkTextView *text_view;
text_view = GTK_TEXT_VIEW (view);
if (text_view->overwrite_mode)
{
view->priv->saved_cursor_visible = text_view->cursor_visible != 0;
gtk_text_view_set_cursor_visible (text_view, FALSE);
view->priv->overwrite_mode = TRUE;
}
else
{
gtk_text_view_set_cursor_visible (text_view,
view->priv->saved_cursor_visible);
view->priv->overwrite_mode = FALSE;
}
check_cursor_blink (view);
}
static gboolean
moo_text_view_focus_in (GtkWidget *widget,
GdkEventFocus *event)
{
gboolean ret;
ret = GTK_WIDGET_CLASS(moo_text_view_parent_class)->focus_in_event (widget, event);
check_cursor_blink (MOO_TEXT_VIEW (widget));
return ret;
}
static gboolean
moo_text_view_focus_out (GtkWidget *widget,
GdkEventFocus *event)
{
gboolean ret;
ret = GTK_WIDGET_CLASS(moo_text_view_parent_class)->focus_out_event (widget, event);
check_cursor_blink (MOO_TEXT_VIEW (widget));
return ret;
}
#define CURSOR_ON_MULTIPLIER 0.66
#define CURSOR_OFF_MULTIPLIER 0.34
#define CURSOR_PEND_MULTIPLIER 0.5
static gboolean
get_cursor_rectangle (GtkTextView *view,
GdkRectangle *cursor_rect)
{
GtkTextIter iter;
GdkRectangle visible_rect;
GtkTextBuffer *buffer;
GtkTextMark *insert;
buffer = gtk_text_view_get_buffer (view);
insert = gtk_text_buffer_get_insert (buffer);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
gtk_text_view_get_iter_location (view, &iter, cursor_rect);
gtk_text_view_get_visible_rect (view, &visible_rect);
if (gtk_text_iter_ends_line (&iter))
cursor_rect->width = 6;
if (gdk_rectangle_intersect (cursor_rect, &visible_rect, cursor_rect))
{
gtk_text_view_buffer_to_window_coords (view, GTK_TEXT_WINDOW_TEXT,
cursor_rect->x, cursor_rect->y,
&cursor_rect->x, &cursor_rect->y);
return TRUE;
}
else
{
return FALSE;
}
}
static void
moo_text_view_draw_cursor (GtkTextView *view,
GdkEventExpose *event)
{
GdkRectangle cursor_rect;
if (!get_cursor_rectangle (view, &cursor_rect))
return;
if (!gdk_rectangle_intersect (&cursor_rect, &event->area, &cursor_rect))
return;
gdk_draw_rectangle (event->window,
GTK_WIDGET(view)->style->text_gc[GTK_STATE_NORMAL],
TRUE,
cursor_rect.x,
cursor_rect.y,
cursor_rect.width,
cursor_rect.height);
}
static void
invalidate_cursor (GtkTextView *view)
{
GdkRectangle rect;
if (get_cursor_rectangle (view, &rect))
{
GdkWindow *window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_TEXT);
g_return_if_fail (window != NULL);
gdk_window_invalidate_rect (window, &rect, FALSE);
}
}
static gboolean
cursor_blinks (GtkWidget *widget)
{
gboolean blink;
GtkSettings *settings = gtk_widget_get_settings (widget);
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
return blink;
}
static int
get_cursor_time (GtkWidget *widget)
{
int time;
GtkSettings *settings = gtk_widget_get_settings (widget);
g_object_get (settings, "gtk-cursor-blink-time", &time, NULL);
return time;
}
static gboolean
blink_cb (MooTextView *view)
{
GtkTextView *text_view = GTK_TEXT_VIEW (view);
int time;
g_return_val_if_fail (view->priv->overwrite_mode, FALSE);
time = get_cursor_time (GTK_WIDGET (view));
if (view->priv->cursor_visible)
time *= CURSOR_OFF_MULTIPLIER;
else
time *= CURSOR_ON_MULTIPLIER;
view->priv->blink_timeout = g_timeout_add (time, (GSourceFunc) blink_cb, view);
view->priv->cursor_visible = !view->priv->cursor_visible;
invalidate_cursor (text_view);
return FALSE;
}
static void
stop_cursor_blink (MooTextView *view)
{
if (view->priv->blink_timeout)
{
g_source_remove (view->priv->blink_timeout);
view->priv->blink_timeout = 0;
}
}
static void
check_cursor_blink (MooTextView *view)
{
GtkTextView *text_view = GTK_TEXT_VIEW (view);
if (view->priv->overwrite_mode && GTK_WIDGET_HAS_FOCUS (view))
{
if (cursor_blinks (GTK_WIDGET (view)))
{
if (!view->priv->blink_timeout)
{
int time = get_cursor_time (GTK_WIDGET (view)) * CURSOR_OFF_MULTIPLIER;
view->priv->cursor_visible = TRUE;
view->priv->blink_timeout = g_timeout_add (time, (GSourceFunc) blink_cb, view);
}
}
else
{
view->priv->cursor_visible = TRUE;
}
}
else
{
view->priv->cursor_visible = FALSE;
stop_cursor_blink (view);
if (GTK_WIDGET_DRAWABLE (text_view))
invalidate_cursor (text_view);
}
}
void
_moo_text_view_pend_cursor_blink (MooTextView *view)
{
if (view->priv->overwrite_mode &&
GTK_WIDGET_HAS_FOCUS (view) &&
cursor_blinks (GTK_WIDGET (view)))
{
int time;
if (view->priv->blink_timeout != 0)
{
g_source_remove (view->priv->blink_timeout);
view->priv->blink_timeout = 0;
}
view->priv->cursor_visible = TRUE;
time = get_cursor_time (GTK_WIDGET (view)) * CURSOR_PEND_MULTIPLIER;
view->priv->blink_timeout = g_timeout_add (time, (GSourceFunc) blink_cb, view);
}
}

View File

@ -5,13 +5,16 @@ noinst_PROGRAMS =
EXTRA_DIST += \
tests/pyapp.py.in \
tests/medit-ui.xml
tests/medit-ui.xml \
tests/medit-app.opag
BUILT_SOURCES += medit-ui.h
BUILT_SOURCES += medit-ui.h tests/medit-app.c
medit-ui.h: tests/medit-ui.xml
sh $(srcdir)/moo/mooutils/xml2h.sh MEDIT_UI $(srcdir)/tests/medit-ui.xml > medit-ui.h
tests/medit-app.c: tests/medit-app.opag
opag -f _medit_parse_options -O _medit_opt_ -A _medit_arg_ $(srcdir)/tests/medit-app.opag $(srcdir)/tests/medit-app.c
all-am: tests/pyapp.py medit-ui.h
all-am: tests/pyapp.py
if MOO_BUILD_APP
medit = medit

View File

@ -1,5 +1,6 @@
/* This file has been generated with opag 0.8.0. */
/*
* tests/editor.c.in
* medit-app.c
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
@ -11,40 +12,337 @@
* See COPYING file that comes with this distribution.
*/
#include "mooapp/mooapp.h"
#include "config.h"
#include "medit-ui.h"
#include <mooapp/mooapp.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
int _medit_parse_options (const char *const program_name,
const int argc,
char **const argv);
/********************************************************
* command line parsing code generated by Opag
* http://www.zero-based.org/software/opag/
*/
#ifndef STR_ERR_UNKNOWN_LONG_OPT
# define STR_ERR_UNKNOWN_LONG_OPT "%s: unrecognized option `--%s'\n"
#endif
#ifndef STR_ERR_LONG_OPT_AMBIGUOUS
# define STR_ERR_LONG_OPT_AMBIGUOUS "%s: option `--%s' is ambiguous\n"
#endif
#ifndef STR_ERR_MISSING_ARG_LONG
# define STR_ERR_MISSING_ARG_LONG "%s: option `--%s' requires an argument\n"
#endif
#ifndef STR_ERR_UNEXPEC_ARG_LONG
# define STR_ERR_UNEXPEC_ARG_LONG "%s: option `--%s' doesn't allow an argument\n"
#endif
#ifndef STR_ERR_UNKNOWN_SHORT_OPT
# define STR_ERR_UNKNOWN_SHORT_OPT "%s: unrecognized option `-%c'\n"
#endif
#ifndef STR_ERR_MISSING_ARG_SHORT
# define STR_ERR_MISSING_ARG_SHORT "%s: option `-%c' requires an argument\n"
#endif
#define STR_HELP_NEW_APP "\
-n, --new-app Run new instance of application\n"
#define STR_HELP_LOG "\
-l, --log[=FILE] Show debug output or write it to FILE\n"
#define STR_HELP_LOG_PYTHON "\
-p, --log-python Redirect output to python console\n"
#define STR_HELP_VERSION "\
--version Display version information and exit\n"
#define STR_HELP_HELP "\
-h, --help Display this help text and exit\n"
#define STR_HELP "\
-n, --new-app Run new instance of application\n\
-l, --log[=FILE] Show debug output or write it to FILE\n\
-p, --log-python Redirect output to python console\n\
--version Display version information and exit\n\
-h, --help Display this help text and exit\n"
/* Set to 1 if option --new-app (-n) has been specified. */
char _medit_opt_new_app;
#ifdef __WIN32__
/* Set to 1 if option --log (-l) has been specified. */
char _medit_opt_log;
#endif
#ifdef MOO_USE_PYTHON
/* Set to 1 if option --log-python (-p) has been specified. */
char _medit_opt_log_python;
#endif
/* Set to 1 if option --version has been specified. */
char _medit_opt_version;
/* Set to 1 if option --help (-h) has been specified. */
char _medit_opt_help;
#ifdef __WIN32__
/* Argument to option --log (-l), or a null pointer if no argument. */
const char *_medit_arg_log;
#endif
/* Parse command line options. Return index of first non-option argument,
or -1 if an error is encountered. */
int _medit_parse_options (const char *const program_name, const int argc, char **const argv)
{
static const char *const optstr__new_app = "new-app";
#ifdef MOO_USE_PYTHON
static const char *const optstr__log_python = "log-python";
#endif
static const char *const optstr__version = "version";
static const char *const optstr__help = "help";
int i = 0;
_medit_opt_new_app = 0;
#ifdef __WIN32__
_medit_opt_log = 0;
#endif
#ifdef MOO_USE_PYTHON
_medit_opt_log_python = 0;
#endif
_medit_opt_version = 0;
_medit_opt_help = 0;
#ifdef __WIN32__
_medit_arg_log = 0;
#endif
while (++i < argc)
{
const char *option = argv [i];
if (*option != '-')
return i;
else if (*++option == '\0')
return i;
else if (*option == '-')
{
const char *argument;
size_t option_len;
++option;
if ((argument = strchr (option, '=')) == option)
goto error_unknown_long_opt;
else if (argument == 0)
option_len = strlen (option);
else
option_len = argument++ - option;
switch (*option)
{
case '\0':
return i + 1;
case 'h':
if (strncmp (option + 1, optstr__help + 1, option_len - 1) == 0)
{
if (argument != 0)
{
option = optstr__help;
goto error_unexpec_arg_long;
}
_medit_opt_help = 1;
return i + 1;
}
goto error_unknown_long_opt;
case 'l':
#ifdef __WIN32__
if (strncmp (option + 1, "og", option_len - 1) == 0)
{
if (option_len < 3)
goto error_long_opt_ambiguous;
_medit_arg_log = argument;
_medit_opt_log = 1;
break;
}
#endif
#ifdef MOO_USE_PYTHON
if (strncmp (option + 1, optstr__log_python + 1, option_len - 1) == 0)
{
if (option_len <= 3)
goto error_long_opt_ambiguous;
if (argument != 0)
{
option = optstr__log_python;
goto error_unexpec_arg_long;
}
_medit_opt_log_python = 1;
break;
}
#endif
goto error_unknown_long_opt;
case 'n':
if (strncmp (option + 1, optstr__new_app + 1, option_len - 1) == 0)
{
if (argument != 0)
{
option = optstr__new_app;
goto error_unexpec_arg_long;
}
_medit_opt_new_app = 1;
break;
}
goto error_unknown_long_opt;
case 'v':
if (strncmp (option + 1, optstr__version + 1, option_len - 1) == 0)
{
if (argument != 0)
{
option = optstr__version;
goto error_unexpec_arg_long;
}
_medit_opt_version = 1;
return i + 1;
}
default:
error_unknown_long_opt:
fprintf (stderr, STR_ERR_UNKNOWN_LONG_OPT, program_name, option);
return -1;
error_long_opt_ambiguous:
fprintf (stderr, STR_ERR_LONG_OPT_AMBIGUOUS, program_name, option);
return -1;
error_unexpec_arg_long:
fprintf (stderr, STR_ERR_UNEXPEC_ARG_LONG, program_name, option);
return -1;
}
}
else
do
{
switch (*option)
{
case 'h':
_medit_opt_help = 1;
return i + 1;
#ifdef __WIN32__
case 'l':
if (option [1] != '\0')
{
_medit_arg_log = option + 1;
option = "\0";
}
else
_medit_arg_log = 0;
_medit_opt_log = 1;
break;
#endif
case 'n':
_medit_opt_new_app = 1;
break;
#ifdef MOO_USE_PYTHON
case 'p':
_medit_opt_log_python = 1;
break;
#endif
default:
fprintf (stderr, STR_ERR_UNKNOWN_SHORT_OPT, program_name, *option);
return -1;
}
} while (*++option != '\0');
}
return i;
}
/* end of generated code
********************************************************/
static void usage (void)
{
g_print ("Usage: %s [OPTIONS] [FILES]\n", g_get_prgname ());
g_print ("Options:\n");
g_print ("%s", STR_HELP_NEW_APP);
#ifdef __WIN32__
g_print ("%s", STR_HELP_LOG);
#endif
#ifdef MOO_USE_PYTHON
g_print ("%s", STR_HELP_LOG_PYTHON);
#endif
g_print ("%s", STR_HELP_VERSION);
g_print ("%s", STR_HELP_HELP);
}
static void version (void)
{
g_print ("medit %s\n", MOO_VERSION);
}
int main (int argc, char *argv[])
{
MooApp *app;
int opt_remain;
MooUIXML *xml;
MooEditor *editor;
MooEditWindow *win;
G_GNUC_UNUSED gboolean use_python_console = FALSE;
gtk_init (&argc, &argv);
// gdk_window_set_debug_updates (TRUE);
opt_remain = _medit_parse_options (g_get_prgname (), argc, argv);
if (opt_remain < 0)
{
usage ();
return 1;
}
if (_medit_opt_help)
{
usage ();
return 0;
}
else if (_medit_opt_version)
{
version ();
return 0;
}
#ifdef __WIN32__
if (_medit_opt_log)
{
if (_medit_arg_log)
moo_set_log_func_file (_medit_arg_log);
else
moo_set_log_func_window (TRUE);
}
#endif
#ifdef MOO_USE_PYTHON
if (_medit_opt_log_python)
use_python_console = TRUE;
#endif
app = g_object_new (MOO_TYPE_APP,
"argv", argv,
"short-name", "medit",
"full-name", "medit",
"description", "medit is a text editor",
#ifdef MOO_USE_PYTHON
"use-python-console", use_python_console,
#endif
"open-files", argv + opt_remain,
"new-app", (gboolean) _medit_opt_new_app,
NULL);
xml = moo_app_get_ui_xml (app);
moo_ui_xml_add_ui_from_string (xml, MEDIT_UI, -1);
moo_app_init (app);
if (!moo_app_init (app))
return 0;
editor = moo_app_get_editor (app);
win = moo_editor_new_window (editor);
if (argc > 1)
moo_editor_open_file (editor, MOO_EDIT_WINDOW (win),
GTK_WIDGET (win), argv[1], NULL);
moo_editor_new_window (editor);
return moo_app_run (app);
}

134
tests/medit-app.opag Normal file
View File

@ -0,0 +1,134 @@
/*
* medit-app.c
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#include "config.h"
#include "medit-ui.h"
#include <mooapp/mooapp.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
int _medit_parse_options (const char *const program_name,
const int argc,
char **const argv);
/********************************************************
* command line parsing code generated by Opag
* http://www.zero-based.org/software/opag/
*/
%%
n new-app "Run new instance of application"
#ifdef __WIN32__
l log "[=FILE] Show debug output or write it to FILE" optarg
#endif
#ifdef MOO_USE_PYTHON
p log-python "Redirect output to python console"
#endif
version "Display version information and exit" return
h help "Display this help text and exit" return
%%
/* end of generated code
********************************************************/
static void usage (void)
{
g_print ("Usage: %s [OPTIONS] [FILES]\n", g_get_prgname ());
g_print ("Options:\n");
g_print ("%s", STR_HELP_NEW_APP);
#ifdef __WIN32__
g_print ("%s", STR_HELP_LOG);
#endif
#ifdef MOO_USE_PYTHON
g_print ("%s", STR_HELP_LOG_PYTHON);
#endif
g_print ("%s", STR_HELP_VERSION);
g_print ("%s", STR_HELP_HELP);
}
static void version (void)
{
g_print ("medit %s\n", MOO_VERSION);
}
int main (int argc, char *argv[])
{
MooApp *app;
int opt_remain;
MooUIXML *xml;
MooEditor *editor;
G_GNUC_UNUSED gboolean use_python_console = FALSE;
gtk_init (&argc, &argv);
// gdk_window_set_debug_updates (TRUE);
opt_remain = _medit_parse_options (g_get_prgname (), argc, argv);
if (opt_remain < 0)
{
usage ();
return 1;
}
if (_medit_opt_help)
{
usage ();
return 0;
}
else if (_medit_opt_version)
{
version ();
return 0;
}
#ifdef __WIN32__
if (_medit_opt_log)
{
if (_medit_arg_log)
moo_set_log_func_file (_medit_arg_log);
else
moo_set_log_func_window (TRUE);
}
#endif
#ifdef MOO_USE_PYTHON
if (_medit_opt_log_python)
use_python_console = TRUE;
#endif
app = g_object_new (MOO_TYPE_APP,
"argv", argv,
"short-name", "medit",
"full-name", "medit",
"description", "medit is a text editor",
#ifdef MOO_USE_PYTHON
"use-python-console", use_python_console,
#endif
"open-files", argv + opt_remain,
"new-app", (gboolean) _medit_opt_new_app,
NULL);
xml = moo_app_get_ui_xml (app);
moo_ui_xml_add_ui_from_string (xml, MEDIT_UI, -1);
if (!moo_app_init (app))
return 0;
editor = moo_app_get_editor (app);
moo_editor_new_window (editor);
return moo_app_run (app);
}