Moved around some stuff in editor

This commit is contained in:
Yevgen Muntyan 2005-07-31 14:53:10 +00:00
parent 8db0cba133
commit 7986e586d8
16 changed files with 337 additions and 236 deletions

View File

@ -21,14 +21,6 @@ AC_SUBST(MOO_VERSION)
AC_SUBST(MOO_VERSION_MAJOR)
AC_SUBST(MOO_VERSION_MINOR)
AC_SUBST(MOO_VERSION_MICRO)
TERMHELPER_VERSION=$MOO_VERSION
TERMHELPER_VERSION_MAJOR=$MOO_VERSION_MAJOR
TERMHELPER_VERSION_MINOR=$MOO_VERSION_MINOR
TERMHELPER_VERSION_MICRO=$MOO_VERSION_MICRO
AC_SUBST(TERMHELPER_VERSION)
AC_SUBST(TERMHELPER_VERSION_MAJOR)
AC_SUBST(TERMHELPER_VERSION_MINOR)
AC_SUBST(TERMHELPER_VERSION_MICRO)
AC_PROG_CC
AC_PROG_CC_STDC
@ -374,6 +366,7 @@ moo/mooedit/xdgmime/Makefile
moo/mooedit/glade/Makefile
moo/mooedit/language-specs/Makefile
moo/mooterm/Makefile
moo/mooterm/termhelper_res.rc
moo/mooterm/glade/Makefile
moo/mooui/Makefile
moo/mooui/glade/Makefile

View File

@ -33,7 +33,7 @@
<kdevautoproject>
<general>
<activetarget>moo/libmoo.la</activetarget>
<useconfiguration>debug</useconfiguration>
<useconfiguration>mingw</useconfiguration>
</general>
<run>
<mainprogram>tests/editor</mainprogram>
@ -46,7 +46,7 @@
</run>
<configurations>
<debug>
<configargs>--enable-debug=full --enable-all-gcc-warnings=fatal --enable-developer-mode --disable-moo-module --without-python</configargs>
<configargs>--enable-debug=full --enable-all-gcc-warnings=fatal --enable-developer-mode --disable-moo-module</configargs>
<builddir>build/debug</builddir>
<ccompiler>kdevgccoptions</ccompiler>
<cxxcompiler>kdevgppoptions</cxxcompiler>

View File

@ -205,37 +205,47 @@ static void setup_open_dialog (MooEditFileMgr *mgr,
}
MooEditFileInfo *moo_edit_file_mgr_open_dialog (MooEditFileMgr *mgr,
GSList *moo_edit_file_mgr_open_dialog (MooEditFileMgr *mgr,
GtkWidget *parent)
{
const char *filename;
GSList *filenames;
GSList *result = NULL;
const char *title = "Open File";
const char *start = NULL;
MooEditFileInfo *file = NULL;
GtkWidget *dialog;
g_return_val_if_fail (MOO_IS_EDIT_FILE_MGR (mgr), NULL);
start = moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN));
dialog = moo_file_dialog_create (parent, MOO_DIALOG_FILE_OPEN_EXISTING,
dialog = moo_file_dialog_create (parent,
MOO_DIALOG_FILE_OPEN_EXISTING,
TRUE,
title, start);
setup_open_dialog (mgr, dialog);
moo_file_dialog_run (dialog);
filename = moo_file_dialog_get_filename (dialog);
filenames = moo_file_dialog_get_filenames (dialog);
if (filename)
if (filenames)
{
char *new_start = g_path_get_dirname (filename);
GSList *l;
char *new_start = g_path_get_dirname (filenames->data);
moo_prefs_set_string (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN), new_start);
g_free (new_start);
file = moo_edit_file_info_new (filename, NULL);
for (l = filenames; l != NULL; l = l->next)
{
result = g_slist_prepend (result, moo_edit_file_info_new (l->data, NULL));
g_free (l->data);
}
g_slist_free (filenames);
}
gtk_widget_destroy (dialog);
return file;
return g_slist_reverse (result);
}
@ -253,7 +263,7 @@ MooEditFileInfo *moo_edit_file_mgr_save_as_dialog (G_GNUC_UNUSED MooEditFileMg
start = moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN));
dialog = moo_file_dialog_create (GTK_WIDGET (edit), MOO_DIALOG_FILE_SAVE,
title, start);
FALSE, title, start);
moo_file_dialog_run (dialog);

View File

@ -61,8 +61,8 @@ void moo_edit_file_mgr_add_recent (MooEditFileMgr *mgr,
MooEditFileInfo *moo_edit_file_mgr_save_as_dialog (MooEditFileMgr *mgr,
MooEdit *edit);
MooEditFileInfo *moo_edit_file_mgr_open_dialog (MooEditFileMgr *mgr,
GtkWidget *widget);
GSList *moo_edit_file_mgr_open_dialog (MooEditFileMgr *mgr,
GtkWidget *parent);
G_END_DECLS

View File

@ -19,6 +19,8 @@
#include "mooutils/moocompat.h"
#include "mooutils/moomarshals.h"
#include "mooutils/moowin.h"
#include "mooutils/moosignal.h"
#include <string.h>
typedef struct {
@ -32,6 +34,8 @@ static void window_info_add (WindowInfo *win,
MooEdit *doc);
static void window_info_remove (WindowInfo *win,
MooEdit *doc);
static MooEdit *window_info_find (WindowInfo *win,
const char *filename);
static void window_list_free (MooEditor *editor);
static void window_list_delete (MooEditor *editor,
@ -42,6 +46,9 @@ static WindowInfo *window_list_find (MooEditor *editor,
MooEditWindow *win);
static WindowInfo *window_list_find_doc (MooEditor *editor,
MooEdit *edit);
static WindowInfo *window_list_find_filename (MooEditor *editor,
const char *filename,
MooEdit **edit);
static GtkMenuItem *create_recent_menu (MooEditWindow *window,
MooAction *action);
@ -53,6 +60,7 @@ struct _MooEditorPrivate {
MooEditLangMgr *lang_mgr;
MooUIXML *ui_xml;
MooEditFileMgr *file_mgr;
gboolean open_single;
};
@ -67,11 +75,12 @@ static gboolean contains_window (MooEditor *editor,
static MooEditWindow *get_top_window (MooEditor *editor);
static gboolean window_closed (MooEditor *editor,
MooEditWindow *window);
static void new_document (MooEditor *editor,
static void document_new (MooEditor *editor,
MooEdit *edit,
MooEditWindow *window);
static void document_closed (MooEditor *editor,
MooEdit *edit,
MooEditWindow *window);
static gboolean document_closed (MooEditor *editor,
MooEdit *doc);
static void open_recent (MooEditor *editor,
MooEditFileInfo *info,
MooEditWindow *window);
@ -80,8 +89,6 @@ static void file_opened_or_saved(MooEditor *editor,
enum {
NEW_WINDOW,
NEW_DOCUMENT,
ALL_WINDOWS_CLOSED,
LAST_SIGNAL
};
@ -100,37 +107,13 @@ static void moo_editor_class_init (MooEditorClass *klass)
gobject_class->finalize = moo_editor_finalize;
klass->new_window = NULL;
klass->new_document = NULL;
klass->all_windows_closed = NULL;
signals[NEW_WINDOW] =
g_signal_new ("new-window",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooEditorClass, new_window),
NULL, NULL,
_moo_marshal_VOID__OBJECT,
/* G_TYPE_OBJECT to not put MOO_TYPE_WHATEVER into marshals.list */
G_TYPE_NONE, 1, G_TYPE_OBJECT);
signals[NEW_DOCUMENT] =
g_signal_new ("new-document",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooEditorClass, new_window),
NULL, NULL,
_moo_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
signals[ALL_WINDOWS_CLOSED] =
g_signal_new ("all-windows-closed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooEditorClass, all_windows_closed),
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
moo_signal_new_cb ("all-windows-closed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
NULL, NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
edit_window_class = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
moo_ui_object_class_new_action (edit_window_class,
@ -149,7 +132,7 @@ static void moo_editor_init (MooEditor *editor)
editor->priv->file_mgr = moo_edit_file_mgr_new ();
g_signal_connect_swapped (editor->priv->file_mgr, "open-recent",
G_CALLBACK (open_recent), editor);
editor->priv->open_single = TRUE;
editor->priv->window_list = NULL;
}
@ -216,18 +199,9 @@ static void add_window (MooEditor *editor,
info = window_list_add (editor, window);
list = moo_edit_window_list_docs (window);
g_signal_connect_swapped (window, "file-opened",
G_CALLBACK (file_opened_or_saved), editor);
g_signal_connect_swapped (window, "file-saved",
G_CALLBACK (file_opened_or_saved), editor);
for (l = list; l != NULL; l = l->next)
{
MooEdit *edit = l->data;
g_signal_connect_data (edit, "close",
G_CALLBACK (document_closed), editor,
NULL,
G_CONNECT_AFTER | G_CONNECT_SWAPPED);
window_info_add (info, edit);
}
@ -241,10 +215,14 @@ static void add_window (MooEditor *editor,
NULL,
G_CONNECT_AFTER | G_CONNECT_SWAPPED);
g_signal_connect_data (window, "new-document",
G_CALLBACK (new_document), editor,
NULL,
G_CONNECT_AFTER | G_CONNECT_SWAPPED);
g_signal_connect_swapped (window, "file-opened",
G_CALLBACK (file_opened_or_saved), editor);
g_signal_connect_swapped (window, "file-saved",
G_CALLBACK (file_opened_or_saved), editor);
g_signal_connect_swapped (window, "document-new",
G_CALLBACK (document_new), editor);
g_signal_connect_swapped (window, "document-closed",
G_CALLBACK (document_closed), editor);
}
@ -269,7 +247,7 @@ static void remove_window (MooEditor *editor,
}
static void new_document (MooEditor *editor,
static void document_new (MooEditor *editor,
MooEdit *edit,
MooEditWindow *window)
{
@ -279,13 +257,14 @@ static void new_document (MooEditor *editor,
}
static gboolean document_closed (MooEditor *editor,
MooEdit *edit)
static void document_closed (MooEditor *editor,
MooEdit *edit,
MooEditWindow *window)
{
WindowInfo *info = window_list_find_doc (editor, edit);
g_return_val_if_fail (info != NULL, FALSE);
g_return_if_fail (info != NULL);
g_return_if_fail (info->win == window);
window_info_remove (info, edit);
return FALSE;
}
@ -314,34 +293,66 @@ static gboolean window_closed (MooEditor *editor,
}
static void file_info_list_free (GSList *list)
{
g_slist_foreach (list, (GFunc) moo_edit_file_info_free, NULL);
g_slist_free (list);
}
gboolean moo_editor_open (MooEditor *editor,
MooEditWindow *window,
GtkWidget *parent,
const char *filename,
const char *encoding)
{
MooEditFileInfo *info = NULL;
gboolean result;
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
g_return_val_if_fail (window == NULL || MOO_IS_EDIT_WINDOW (window), FALSE);
if (!parent && window)
parent = GTK_WIDGET (window);
if (!filename)
{
info = moo_edit_file_mgr_open_dialog (editor->priv->file_mgr,
parent);
GSList *files, *l;
gboolean result;
if (!info)
{
if (!parent && window)
parent = GTK_WIDGET (window);
files = moo_edit_file_mgr_open_dialog (editor->priv->file_mgr,
parent);
if (!files)
return FALSE;
}
else
for (l = files; l != NULL; l = l->next)
{
filename = info->filename;
encoding = info->encoding;
MooEditFileInfo *info = l->data;
if (!info || !info->filename)
{
file_info_list_free (files);
return FALSE;
}
result = moo_editor_open (editor, window, parent,
info->filename, info->encoding);
if (!result)
break;
}
return result;
}
if (editor->priv->open_single)
{
MooEdit *edit;
WindowInfo *info = window_list_find_filename (editor, filename, &edit);
if (info)
{
gtk_window_present (GTK_WINDOW (info->win));
moo_edit_window_set_active_doc (info->win, edit);
return TRUE;
}
}
@ -351,17 +362,11 @@ gboolean moo_editor_open (MooEditor *editor,
if (!window)
window = moo_editor_new_window (editor);
if (!window)
{
moo_edit_file_info_free (info);
g_return_val_if_reached (FALSE);
}
g_return_val_if_fail (window != NULL, FALSE);
gtk_window_present (GTK_WINDOW (window));
result = moo_edit_window_open (window, filename, encoding);
moo_edit_file_info_free (info);
return result;
return _moo_edit_window_open (window, filename, encoding);
}
@ -506,6 +511,29 @@ static void window_info_remove (WindowInfo *win,
win->docs = g_slist_remove (win->docs, edit);
}
static int edit_and_file_cmp (MooEdit *edit, const char *filename)
{
const char *edit_filename;
g_return_val_if_fail (MOO_IS_EDIT (edit) && filename != NULL, TRUE);
edit_filename = moo_edit_get_filename (edit);
if (edit_filename)
return strcmp (edit_filename, filename);
else
return TRUE;
}
static MooEdit *window_info_find (WindowInfo *win,
const char *filename)
{
GSList *l;
g_return_val_if_fail (win != NULL && filename != NULL, NULL);
l = g_slist_find_custom (win->docs, filename,
(GCompareFunc) edit_and_file_cmp);
return l ? l->data : NULL;
}
static void window_list_free (MooEditor *editor)
{
g_slist_foreach (editor->priv->window_list,
@ -534,7 +562,7 @@ static WindowInfo *window_list_add (MooEditor *editor,
static int window_cmp (WindowInfo *w, MooEditWindow *e)
{
g_return_val_if_fail (w != NULL, 1);
g_return_val_if_fail (w != NULL, TRUE);
return !(w->win == e);
}
@ -567,6 +595,38 @@ static WindowInfo *window_list_find_doc (MooEditor *editor,
}
struct FilenameAndDoc {
const char *filename;
MooEdit *edit;
};
static int filename_and_doc_cmp (WindowInfo *w, struct FilenameAndDoc *data)
{
g_return_val_if_fail (w != NULL, TRUE);
data->edit = window_info_find (w, data->filename);
return data->edit == NULL;
}
static WindowInfo *window_list_find_filename (MooEditor *editor,
const char *filename,
MooEdit **edit)
{
struct FilenameAndDoc data = {filename, NULL};
GSList *l = g_slist_find_custom (editor->priv->window_list, &data,
(GCompareFunc) filename_and_doc_cmp);
if (l)
{
g_assert (data.edit != NULL);
if (edit) *edit = data.edit;
return l->data;
}
else
{
return NULL;
}
}
static GtkMenuItem *create_recent_menu (MooEditWindow *window,
G_GNUC_UNUSED MooAction *action)
{
@ -589,7 +649,8 @@ static void open_recent (MooEditor *editor,
win_info = window_list_find (editor, window);
g_return_if_fail (win_info != NULL);
moo_edit_window_open (window, info->filename, info->encoding);
moo_editor_open (editor, window, GTK_WIDGET (window),
info->filename, info->encoding);
}

View File

@ -64,12 +64,6 @@ struct _MooEditor
struct _MooEditorClass
{
GObjectClass parent_class;
void (*new_window) (MooEditor *editor,
MooEditWindow *window);
void (*new_document) (MooEditor *editor,
MooEdit *doc);
void (*all_windows_closed) (MooEditor *editor);
};
@ -92,6 +86,8 @@ gboolean moo_editor_open (MooEditor *editor,
MooEdit *moo_editor_get_active_doc (MooEditor *editor);
MooEditWindow *moo_editor_get_active_window (MooEditor *editor);
gboolean moo_editor_close_doc (MooEditor *editor,
MooEdit *doc);
gboolean moo_editor_close_all (MooEditor *editor);
void moo_editor_set_app_name (MooEditor *editor,
@ -109,19 +105,20 @@ void moo_editor_set_ui_xml (MooEditor *editor,
/* MooEditWindow
*/
gboolean moo_edit_window_open (MooEditWindow *window,
const char *filename,
const char *encoding);
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window);
void moo_edit_window_set_active_doc (MooEditWindow *window,
MooEdit *edit);
gboolean moo_edit_window_close_doc (MooEditWindow *window,
MooEdit *doc);
GSList *moo_edit_window_list_docs (MooEditWindow *window);
#ifdef MOOEDIT_COMPILATION
gboolean _moo_edit_window_open (MooEditWindow *window,
const char *filename,
const char *encoding);
GtkWidget *_moo_edit_window_new (MooEditor *editor);
gboolean _moo_edit_window_close_doc (MooEditWindow *window,
MooEdit *doc);
void _moo_edit_window_set_app_name (MooEditWindow *window,
const char *name);

View File

@ -53,8 +53,6 @@ static void moo_edit_window_get_property(GObject *object,
static gboolean moo_edit_window_close (MooEditWindow *window);
static void set_active_tab (MooEditWindow *window,
MooEdit *edit);
static void add_tab (MooEditWindow *window,
MooEdit *edit);
static gboolean close_current_tab (MooEditWindow *window);
@ -106,7 +104,8 @@ enum {
};
enum {
NEW_DOCUMENT,
DOCUMENT_NEW,
DOCUMENT_CLOSED,
FILE_OPENED,
FILE_SAVED,
NUM_SIGNALS
@ -365,8 +364,17 @@ static void moo_edit_window_class_init (MooEditWindowClass *klass)
"create-menu-func", create_lang_menu,
NULL);
signals[NEW_DOCUMENT] =
moo_signal_new_cb ("new-document",
signals[DOCUMENT_NEW] =
moo_signal_new_cb ("document-new",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
NULL, NULL, NULL,
_moo_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
MOO_TYPE_EDIT);
signals[DOCUMENT_CLOSED] =
moo_signal_new_cb ("document-closed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
NULL, NULL, NULL,
@ -421,10 +429,11 @@ GObject *moo_edit_window_constructor (GType type,
gtk_widget_show (MOO_WINDOW(window)->statusbar);
window->priv->statusbar_context_id =
gtk_statusbar_get_context_id (window->priv->statusbar,
"MOoEditWindow");
"MooEditWindow");
gtk_widget_show (MOO_WINDOW(window)->vbox);
notebook = gtk_notebook_new ();
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
gtk_widget_show (notebook);
gtk_box_pack_start (GTK_BOX (MOO_WINDOW(window)->vbox), notebook, TRUE, TRUE, 0);
@ -511,7 +520,7 @@ static void add_tab (MooEditWindow *window,
edit_changed (edit, window);
g_signal_emit (window, signals[NEW_DOCUMENT], 0, edit);
g_signal_emit (window, signals[DOCUMENT_NEW], 0, edit);
}
@ -533,13 +542,16 @@ static MooEdit *get_nth_tab (MooEditWindow *window,
}
static void set_active_tab (MooEditWindow *window,
MooEdit *edit)
void moo_edit_window_set_active_doc (MooEditWindow *window,
MooEdit *edit)
{
int num = gtk_notebook_page_num (window->priv->notebook,
g_object_get_qdata (G_OBJECT (edit),
SCROLLED_WINDOW_QUARK));
gtk_notebook_set_current_page (window->priv->notebook, num);
int index;
g_return_if_fail (MOO_IS_EDIT_WINDOW (window) && MOO_IS_EDIT (edit));
index = gtk_notebook_page_num (window->priv->notebook,
g_object_get_qdata (G_OBJECT (edit),
SCROLLED_WINDOW_QUARK));
g_return_if_fail (index >= 0);
gtk_notebook_set_current_page (window->priv->notebook, index);
}
@ -614,20 +626,22 @@ static void edit_can_undo_redo (MooEditWindow *window)
static GtkWidget *create_tab_label (MooEdit *edit)
{
GtkWidget *hbox, *filename, *icon;
GtkWidget *eventbox, *hbox, *filename, *icon;
eventbox = gtk_event_box_new ();
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox);
icon = gtk_image_new ();
filename = gtk_label_new (moo_edit_get_display_basename (edit));
gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), filename, TRUE, TRUE, 3);
g_object_set_data (G_OBJECT (hbox), "filename", filename);
g_object_set_data (G_OBJECT (hbox), "icon", icon);
g_object_set_data (G_OBJECT (eventbox), "filename", filename);
g_object_set_data (G_OBJECT (eventbox), "icon", icon);
gtk_widget_show (filename);
g_signal_connect_swapped (edit, "doc-status-changed",
G_CALLBACK (update_tab_label), hbox);
G_CALLBACK (update_tab_label), eventbox);
return hbox;
}
@ -702,16 +716,25 @@ static gboolean close_current_tab (MooEditWindow *window)
static gboolean close_tab (MooEditWindow *window,
MooEdit *edit)
{
if (moo_edit_close (edit)) {
GtkWidget *label =
gtk_notebook_get_tab_label (window->priv->notebook,
if (moo_edit_close (edit))
{
GtkWidget *label;
g_object_ref (edit);
label = gtk_notebook_get_tab_label (window->priv->notebook,
g_object_get_qdata (G_OBJECT (edit),
SCROLLED_WINDOW_QUARK));
g_signal_handlers_disconnect_by_func(edit, update_tab_label, label);
gtk_notebook_remove_page (window->priv->notebook,
gtk_notebook_get_current_page (window->priv->notebook));
if (gtk_notebook_get_n_pages (window->priv->notebook) <= 1)
gtk_notebook_set_show_tabs (window->priv->notebook, FALSE);
g_signal_emit (window, signals[DOCUMENT_CLOSED], 0, edit);
g_object_unref (edit);
return TRUE;
}
else
@ -737,7 +760,7 @@ static void moo_edit_window_new_tab (MooEditWindow *window)
static void moo_edit_window_open_cb (MooEditWindow *window)
{
moo_edit_window_open (window, NULL, NULL);
_moo_edit_window_open (window, NULL, NULL);
}
@ -779,38 +802,18 @@ GtkWidget *_moo_edit_window_new (MooEditor *editor)
}
gboolean moo_edit_window_open (MooEditWindow *window,
gboolean _moo_edit_window_open (MooEditWindow *window,
const char *filename,
const char *encoding)
{
MooEdit *edit;
MooEditFileInfo *info = NULL;
MooEditFileMgr *mgr;
gboolean result;
gboolean add = FALSE;
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
if (!filename)
{
if (window->priv->editor)
mgr = moo_editor_get_file_mgr (window->priv->editor);
if (mgr)
info = moo_edit_file_mgr_open_dialog (mgr, GTK_WIDGET (window));
else
info = moo_edit_open_dialog (GTK_WIDGET (window));
if (!info)
{
return FALSE;
}
else
{
filename = info->filename;
encoding = info->encoding;
}
}
return moo_editor_open (window->priv->editor, window,
GTK_WIDGET (window), NULL, NULL);
edit = moo_edit_window_get_active_doc (window);

View File

@ -1656,16 +1656,6 @@
)
)
(define-method open
(of-object "MooEditWindow")
(c-name "moo_edit_window_open")
(return-type "gboolean")
(parameters
'("const-char*" "filename")
'("const-char*" "encoding")
)
)
(define-method get_active_doc
(of-object "MooEditWindow")
(c-name "moo_edit_window_get_active_doc")

View File

@ -12,6 +12,18 @@
(gtype-id "MOO_TYPE_TERM")
)
(define-boxed TermCommand
(in-module "Moo")
(c-name "MooTermCommand")
(gtype-id "MOO_TYPE_TERM_COMMAND")
(copy-func "moo_term_command_copy")
(release-func "moo_term_command_free")
(fields
'("char*" "cmd_line")
'("char**" "argv")
)
)
(define-boxed TermProfile
(in-module "Moo")
(c-name "MooTermProfile")
@ -20,8 +32,7 @@
(release-func "moo_term_profile_free")
(fields
'("char*" "name")
'("char*" "cmd_line")
'("char**" "argv")
'("MooTermCommand*" "cmd")
'("char**" "envp")
'("char*" "working_dir")
)
@ -60,14 +71,39 @@
)
)
(define-method fork_command_line
(of-object "MooTerm")
(c-name "moo_term_fork_command_line")
(return-type "gboolean")
(parameters
'("const-gchar*" "cmd_line")
'("const-gchar*" "working_dir" (null-ok) (default "NULL"))
'("char**" "envp" (null-ok) (default "NULL"))
'("GError**" "error" (null-ok) (default "NULL"))
)
)
(define-method fork_argv
(of-object "MooTerm")
(c-name "moo_term_fork_argv")
(return-type "gboolean")
(parameters
'("char**" "argv")
'("const-gchar*" "working_dir" (null-ok) (default "NULL"))
'("char**" "envp" (null-ok) (default "NULL"))
'("GError**" "error" (null-ok) (default "NULL"))
)
)
(define-method fork_command
(of-object "MooTerm")
(c-name "moo_term_fork_command")
(return-type "gboolean")
(parameters
'("const-gchar*" "cmd")
'("const-MooTermCommand*" "cmd")
'("const-gchar*" "working_dir" (null-ok) (default "NULL"))
'("char**" "envp" (null-ok) (default "NULL"))
'("GError**" "error" (null-ok) (default "NULL"))
)
)
@ -80,9 +116,18 @@
(return-type "MooTermProfile*")
(parameters
'("char*" "name" (null-ok) (default "NULL"))
'("char*" "cmd_line" (null-ok) (default "NULL"))
'("char**" "argv" (null-ok) (default "NULL"))
'("const-MooTermCommand*" "cmd" (null-ok) (default "NULL"))
'("char**" "envp" (null-ok) (default "NULL"))
'("char*" "working_dir" (null-ok) (default "NULL"))
)
)
(define-function moo_term_command_new
(c-name "moo_term_command_new")
(is-constructor-of "MooTermCommand")
(return-type "MooTermCommand*")
(parameters
'("char*" "cmd_line" (null-ok) (default "NULL"))
'("char**" "argv" (null-ok) (default "NULL"))
)
)

View File

@ -32,75 +32,21 @@ _wrap_moo_term_new (PyGObject *self, PyObject *args, PyObject *kwargs)
return 0;
}
%%
override moo_term_fork_command kwargs
override moo_term_fork_command_line kwargs
static PyObject *
_wrap_moo_term_fork_command (PyGObject *self, PyObject *args, PyObject *kwargs)
_wrap_moo_term_fork_command_line (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"cmd", "working_dir", NULL};
const char *cmd = NULL;
const char *working_dir = NULL;
gboolean result;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "s|s:Term.fork_command",
kwlist, &cmd, &working_dir))
return NULL;
moo_term_fork_command (MOO_TERM (self->obj), cmd, working_dir, NULL);
result = moo_term_fork_command_line (MOO_TERM (self->obj), cmd,
working_dir, NULL, NULL);
Py_INCREF(Py_None);
return Py_None;
}
%%
override-attr MooTermProfile.argv
static PyObject *
_wrap_moo_term_profile__get_argv (PyObject *self, G_GNUC_UNUSED void *closure)
{
char **argv;
argv = pyg_boxed_get(self, MooTermProfile)->argv;
return moo_strv_to_pyobject (argv);
}
%%
override-attr MooTermProfile.envp
static PyObject *
_wrap_moo_term_profile__get_envp (PyObject *self, G_GNUC_UNUSED void *closure)
{
char **envp;
envp = pyg_boxed_get(self, MooTermProfile)->envp;
return moo_strv_to_pyobject (envp);
}
%%
override moo_term_profile_new kwargs
static int
_wrap_moo_term_profile_new (PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "name", "cmd_line", "argv", "envp", "working_dir", NULL };
char *name = NULL, *cmd_line = NULL, *working_dir = NULL;
char **argv = NULL, **envp = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|zzO&O&z:MooTermProfile.__init__", kwlist,
&name, &cmd_line, moo_pyobject_to_strv, &argv,
moo_pyobject_to_strv, &envp, &working_dir))
{
g_strfreev (argv);
g_strfreev (envp);
return -1;
}
self->gtype = MOO_TYPE_TERM_PROFILE;
self->free_on_dealloc = FALSE;
self->boxed = moo_term_profile_new (name, cmd_line, argv, envp, working_dir);
if (!self->boxed)
{
PyErr_SetString(PyExc_RuntimeError, "could not create MooTermProfile object");
return -1;
}
else
{
self->free_on_dealloc = TRUE;
return 0;
}
return_Bool (result);
}

View File

@ -154,8 +154,12 @@ GtkWidget *file_chooser_dialog_new (const char *title,
return dialog;
}
#define file_chooser_set_select_multiple(dialog,multiple) \
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), multiple)
#define file_chooser_get_filename(dialog) \
(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)))
#define file_chooser_get_filenames(dialog) \
(gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog)))
#else /* !GTK_CHECK_VERSION(2,4,0) */
@ -196,7 +200,7 @@ const char *moo_file_dialog (GtkWidget *parent,
const char *filename;
GtkWidget *dialog;
dialog = moo_file_dialog_create (parent, type, title, start_dir);
dialog = moo_file_dialog_create (parent, type, FALSE, title, start_dir);
g_return_val_if_fail (dialog != NULL, NULL);
moo_file_dialog_run (dialog);
@ -209,6 +213,7 @@ const char *moo_file_dialog (GtkWidget *parent,
GtkWidget *moo_file_dialog_create (GtkWidget *parent,
MooFileDialogType type,
gboolean multiple,
const char *title,
const char *start_dir)
{
@ -230,6 +235,7 @@ GtkWidget *moo_file_dialog_create (GtkWidget *parent,
dialog = file_chooser_dialog_new (title, parent_window, chooser_action,
GTK_STOCK_OPEN, start_dir);
file_chooser_set_select_multiple (dialog, multiple);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
break;
@ -238,6 +244,7 @@ GtkWidget *moo_file_dialog_create (GtkWidget *parent,
dialog = file_chooser_dialog_new (title, parent_window, chooser_action,
GTK_STOCK_SAVE, start_dir);
file_chooser_set_select_multiple (dialog, multiple);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
break;
@ -252,6 +259,9 @@ GtkWidget *moo_file_dialog_create (GtkWidget *parent,
g_object_set_data (G_OBJECT (dialog),
"moo-file-dialog",
GINT_TO_POINTER (1));
g_object_set_data (G_OBJECT (dialog),
"moo-file-dialog-multiple",
GINT_TO_POINTER (multiple));
g_object_set_data_full (G_OBJECT (dialog),
"moo-file-dialog-filename", NULL,
g_free);
@ -260,6 +270,25 @@ GtkWidget *moo_file_dialog_create (GtkWidget *parent,
}
static GSList *string_slist_copy (GSList *list)
{
GSList *copy = NULL;
GSList *l;
for (l = list; l != NULL; l = l->next)
copy = g_slist_prepend (copy, g_strdup (l->data));
return g_slist_reverse (copy);
}
static void string_slist_free (GSList *list)
{
g_slist_foreach (list, (GFunc) g_free, NULL);
g_slist_free (list);
}
gboolean moo_file_dialog_run (GtkWidget *dialog)
{
char *filename;
@ -287,6 +316,11 @@ gboolean moo_file_dialog_run (GtkWidget *dialog)
"moo-file-dialog-filename",
file_chooser_get_filename (dialog),
g_free);
if (g_object_get_data (G_OBJECT (dialog), "moo-file-dialog-multiple"))
g_object_set_data_full (G_OBJECT (dialog),
"moo-file-dialog-filenames",
file_chooser_get_filenames (dialog),
(GDestroyNotify) string_slist_free);
return TRUE;
}
else
@ -349,6 +383,18 @@ const char *moo_file_dialog_get_filename (GtkWidget *dialog)
}
GSList *moo_file_dialog_get_filenames (GtkWidget *dialog)
{
g_return_val_if_fail (dialog != NULL, NULL);
g_return_val_if_fail (GPOINTER_TO_INT (g_object_get_data
(G_OBJECT (dialog), "moo-file-dialog")) == 1, NULL);
g_return_val_if_fail (g_object_get_data (G_OBJECT (dialog),
"moo-file-dialog-multiple"), NULL);
return string_slist_copy (g_object_get_data (G_OBJECT (dialog),
"moo-file-dialog-filenames"));
}
const char *moo_file_dialogp(GtkWidget *parent,
MooFileDialogType type,
const char *title,

View File

@ -39,10 +39,12 @@ const char *moo_file_dialog (GtkWidget *parent,
GtkWidget *moo_file_dialog_create (GtkWidget *parent,
MooFileDialogType type,
gboolean multiple,
const char *title,
const char *start_dir);
gboolean moo_file_dialog_run (GtkWidget *dialog);
const char *moo_file_dialog_get_filename (GtkWidget *dialog);
GSList *moo_file_dialog_get_filenames (GtkWidget *dialog);
const char *moo_file_dialogp(GtkWidget *parent,
MooFileDialogType type,

View File

@ -1043,6 +1043,12 @@ gboolean moo_prefs_save (const char *file)
{
result = moo_save_file_utf8 (file, text, -1, &err);
if (!result)
{
g_critical ("%s: could not save preferences to '%s'",
G_STRLOC, file);
}
if (err)
{
g_critical ("%s: %s", G_STRLOC, err->message);

View File

@ -60,7 +60,8 @@ int main (int argc, char *argv[])
win = moo_editor_new_window (editor);
if (argc > 1)
moo_edit_window_open (MOO_EDIT_WINDOW (win), argv[1], NULL);
moo_editor_open (editor, MOO_EDIT_WINDOW (win),
GTK_WIDGET (win), argv[1], NULL);
return moo_app_run (app);
}
@ -70,7 +71,7 @@ static void terminal_restart (MooTermWindow *win)
{
MooTerm *term = moo_term_window_get_term (win);
moo_term_kill_child (term);
moo_term_start_default_profile (term);
moo_term_start_default_profile (term, NULL);
}

View File

@ -11,6 +11,7 @@
* See COPYING file that comes with this distribution.
*/
#define MOOEDIT_COMPILATION
#line 14 "@srcdir@/medit.c.in"
#include "mooedit/mooeditor.h"
#include "mooedit/mooeditlangmgr.h"
@ -43,7 +44,7 @@ int main (int argc, char **argv)
if (!moo_ui_xml_add_ui_from_file (xml, "meditui.xml", NULL))
g_error ("could not find medui.xml");
if (argc > 1) moo_edit_window_open (MOO_EDIT_WINDOW (win), argv[1], NULL);
if (argc > 1) _moo_edit_window_open (MOO_EDIT_WINDOW (win), argv[1], NULL);
gtk_main ();

View File

@ -133,7 +133,7 @@ int main (int argc, char *argv[])
g_signal_connect_swapped (term, "set-icon-name",
G_CALLBACK (gdk_window_set_icon_name), win->window);
moo_term_fork_command (MOO_TERM (term), cmd, NULL, NULL);
moo_term_fork_command_line (MOO_TERM (term), cmd, NULL, NULL, NULL);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
g_signal_connect_swapped (term, "child-died",