diff --git a/moo.kdevelop b/moo.kdevelop index a05288db..a23d947e 100644 --- a/moo.kdevelop +++ b/moo.kdevelop @@ -234,16 +234,16 @@ - + A new empty GAP source file - + A new empty C++ file. - + A new empty header file for C/C++. - + A new empty C file. diff --git a/moo/mooedit/Makefile.am b/moo/mooedit/Makefile.am index 3bf2e3bf..5bd02b4d 100644 --- a/moo/mooedit/Makefile.am +++ b/moo/mooedit/Makefile.am @@ -60,6 +60,7 @@ libmooedit_la_SOURCES = \ mooeditsearch.h \ mooeditwindow.c \ mooeditwindow.h \ + mooeditwindow-pane.h \ moonotebook.c \ moonotebook.h \ moopaned.c \ diff --git a/moo/mooedit/moobigpaned.c b/moo/mooedit/moobigpaned.c index d87e9bce..e01fa1a0 100644 --- a/moo/mooedit/moobigpaned.c +++ b/moo/mooedit/moobigpaned.c @@ -270,6 +270,13 @@ static void moo_big_paned_finalize (GObject *object) for (i = 0; i < 4; ++i) g_object_unref (paned->paned[i]); + /* XXX */ + if (paned->drop_outline) + { + gdk_window_set_user_data (paned->drop_outline, NULL); + gdk_window_destroy (paned->drop_outline); + } + G_OBJECT_CLASS (moo_big_paned_parent_class)->finalize (object); } @@ -305,34 +312,34 @@ static void child_hide_pane (GtkWidget *child, } -void moo_big_paned_add_pane (MooBigPaned *paned, +int moo_big_paned_add_pane (MooBigPaned *paned, GtkWidget *pane_widget, MooPanePosition position, const char *button_label, const char *button_stock_id, int index_) { - g_return_if_fail (MOO_IS_BIG_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (pane_widget)); - g_return_if_fail (position < 4); + g_return_val_if_fail (MOO_IS_BIG_PANED (paned), -1); + g_return_val_if_fail (GTK_IS_WIDGET (pane_widget), -1); + g_return_val_if_fail (position < 4, -1); - moo_paned_add_pane (MOO_PANED (paned->paned[position]), - pane_widget, button_label, button_stock_id, index_); + return moo_paned_add_pane (MOO_PANED (paned->paned[position]), + pane_widget, button_label, button_stock_id, index_); } -void moo_big_paned_insert_pane (MooBigPaned *paned, +int moo_big_paned_insert_pane (MooBigPaned *paned, GtkWidget *pane_widget, MooPaneLabel *pane_label, MooPanePosition position, int index_) { - g_return_if_fail (MOO_IS_BIG_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (pane_widget)); - g_return_if_fail (position < 4); + g_return_val_if_fail (MOO_IS_BIG_PANED (paned), -1); + g_return_val_if_fail (GTK_IS_WIDGET (pane_widget), -1); + g_return_val_if_fail (position < 4, -1); - moo_paned_insert_pane (MOO_PANED (paned->paned[position]), - pane_widget, pane_label, index_); + return moo_paned_insert_pane (MOO_PANED (paned->paned[position]), + pane_widget, pane_label, index_); } @@ -358,6 +365,73 @@ GtkWidget *moo_big_paned_get_child (MooBigPaned *paned) } +gboolean moo_big_paned_remove_pane (MooBigPaned *paned, + GtkWidget *widget) +{ + int i; + + g_return_val_if_fail (MOO_IS_BIG_PANED (paned), FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + for (i = 0; i < 4; ++i) + if (moo_paned_get_pane_num (MOO_PANED (paned->paned[i]), widget) >= 0) + return moo_paned_remove_pane (MOO_PANED (paned->paned[i]), widget); + + return FALSE; +} + + +void moo_big_paned_open_pane (MooBigPaned *paned, + GtkWidget *widget) +{ + int i, num; + + g_return_if_fail (MOO_IS_BIG_PANED (paned)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + for (i = 0; i < 4; ++i) + { + num = moo_paned_get_pane_num (MOO_PANED (paned->paned[i]), widget); + if (num >= 0) + return moo_paned_open_pane (MOO_PANED (paned->paned[i]), num); + } +} + + +void moo_big_paned_hide_pane (MooBigPaned *paned, + GtkWidget *widget) +{ + int i, num; + + g_return_if_fail (MOO_IS_BIG_PANED (paned)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + for (i = 0; i < 4; ++i) + { + num = moo_paned_get_pane_num (MOO_PANED (paned->paned[i]), widget); + if (num >= 0) + return moo_paned_hide_pane (MOO_PANED (paned->paned[i])); + } +} + + +void moo_big_paned_present_pane (MooBigPaned *paned, + GtkWidget *widget) +{ + int i, num; + + g_return_if_fail (MOO_IS_BIG_PANED (paned)); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + for (i = 0; i < 4; ++i) + { + num = moo_paned_get_pane_num (MOO_PANED (paned->paned[i]), widget); + if (num >= 0) + return moo_paned_present_pane (MOO_PANED (paned->paned[i]), num); + } +} + + static void moo_big_paned_set_property (GObject *object, guint prop_id, const GValue *value, @@ -441,7 +515,7 @@ static void get_drop_area (MooBigPaned *paned, MooPaned *active_child, MooPanePosition position, GdkRectangle *rect); -static void invalidate_drop_rect (MooBigPaned *paned); +static void invalidate_drop_outline (MooBigPaned *paned); static void handle_drag_start (G_GNUC_UNUSED MooPaned *child, @@ -473,7 +547,7 @@ static void handle_drag_motion (MooPaned *child, if (paned->drop_pos >= 0) { - invalidate_drop_rect (paned); + invalidate_drop_outline (paned); g_assert (paned->drop_outline != NULL); gdk_window_set_user_data (paned->drop_outline, NULL); gdk_window_destroy (paned->drop_outline); @@ -485,7 +559,7 @@ static void handle_drag_motion (MooPaned *child, if (pos >= 0) { get_drop_area (paned, child, pos, &paned->drop_rect); - invalidate_drop_rect (paned); + invalidate_drop_outline (paned); g_assert (paned->drop_outline == NULL); create_drop_outline (paned); } @@ -508,7 +582,7 @@ static void handle_drag_end (MooPaned *child, if (paned->drop_pos >= 0) { - invalidate_drop_rect (paned); + invalidate_drop_outline (paned); g_assert (paned->drop_outline != NULL); gdk_window_set_user_data (paned->drop_outline, NULL); gdk_window_destroy (paned->drop_outline); @@ -654,7 +728,7 @@ static int get_drop_position (MooBigPaned *paned, } -static void invalidate_drop_rect (MooBigPaned *paned) +static void invalidate_drop_outline (MooBigPaned *paned) { GdkRectangle line; GdkRegion *outline; @@ -743,6 +817,8 @@ static void create_drop_outline (MooBigPaned *paned) int attributes_mask; GdkBitmap *mask; + g_return_if_fail (paned->drop_outline == NULL); + attributes.x = paned->drop_rect.x; attributes.y = paned->drop_rect.y; attributes.width = paned->drop_rect.width; diff --git a/moo/mooedit/moobigpaned.h b/moo/mooedit/moobigpaned.h index bb4e8937..c45227bd 100644 --- a/moo/mooedit/moobigpaned.h +++ b/moo/mooedit/moobigpaned.h @@ -70,17 +70,26 @@ void moo_big_paned_add_child (MooBigPaned *paned, void moo_big_paned_remove_child (MooBigPaned *paned); GtkWidget *moo_big_paned_get_child (MooBigPaned *paned); -void moo_big_paned_add_pane (MooBigPaned *paned, +int moo_big_paned_add_pane (MooBigPaned *paned, GtkWidget *pane_widget, MooPanePosition position, const char *button_label, const char *button_stock_id, int index_); -void moo_big_paned_insert_pane (MooBigPaned *paned, +int moo_big_paned_insert_pane (MooBigPaned *paned, GtkWidget *pane_widget, MooPaneLabel *pane_label, MooPanePosition position, int index_); +gboolean moo_big_paned_remove_pane (MooBigPaned *paned, + GtkWidget *pane_widget); + +void moo_big_paned_open_pane (MooBigPaned *paned, + GtkWidget *pane_widget); +void moo_big_paned_hide_pane (MooBigPaned *paned, + GtkWidget *pane_widget); +void moo_big_paned_present_pane (MooBigPaned *paned, + GtkWidget *pane_widget); G_END_DECLS diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c index 4e7c7fef..8656c790 100644 --- a/moo/mooedit/mooeditor.c +++ b/moo/mooedit/mooeditor.c @@ -534,7 +534,7 @@ static GtkMenuItem *create_recent_menu (MooEditWindow *window, { GtkMenuItem *item; MooRecentMgr *mgr; - MooEditor *editor = _moo_edit_window_get_editor (window); + MooEditor *editor = moo_edit_window_get_editor (window); g_return_val_if_fail (editor != NULL, NULL); @@ -720,6 +720,10 @@ void moo_editor_open (MooEditor *editor, _moo_edit_window_insert_doc (window, doc, -1); moo_editor_add_doc (editor, window, doc, loader, saver); } + else + { + bring_to_front = doc; + } moo_recent_mgr_add_recent (editor->priv->recent_mgr, info); @@ -730,7 +734,10 @@ void moo_editor_open (MooEditor *editor, } if (bring_to_front) + { moo_editor_set_active_doc (editor, bring_to_front); + gtk_widget_grab_focus (GTK_WIDGET (bring_to_front)); + } } diff --git a/moo/mooedit/mooeditor.h b/moo/mooedit/mooeditor.h index 42846d63..05608adc 100644 --- a/moo/mooedit/mooeditor.h +++ b/moo/mooedit/mooeditor.h @@ -93,10 +93,11 @@ MooUIXML *moo_editor_get_ui_xml (MooEditor *editor); void moo_editor_set_ui_xml (MooEditor *editor, MooUIXML *xml); +MooEditor *moo_edit_window_get_editor (MooEditWindow *window); + #ifdef MOOEDIT_COMPILATION MooEditWindow *_moo_edit_window_new (MooEditor *editor); -// void _moo_edit_window_close (MooEditWindow *window); void _moo_edit_window_insert_doc (MooEditWindow *window, MooEdit *doc, @@ -106,7 +107,6 @@ void _moo_edit_window_remove_doc (MooEditWindow *window, void _moo_edit_window_set_app_name (MooEditWindow *window, const char *name); -MooEditor *_moo_edit_window_get_editor (MooEditWindow *window); void _moo_editor_reload (MooEditor *editor, MooEdit *doc); diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index 1a72891b..a3132732 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -13,19 +13,25 @@ #define MOOEDIT_COMPILATION #include "mooedit-private.h" -#include "mooedit/mooeditwindow.h" +#include "mooedit/mooeditwindowpane.h" #include "mooedit/mooeditor.h" #include "mooedit/moobigpaned.h" #include "mooedit/moonotebook.h" +#include "mooedit/moofileview/moofileview.h" #include "mooutils/moostock.h" #include "mooui/moomenuaction.h" #include "mooui/moouiobject-impl.h" #include +#define MOO_USE_FILE_VIEW 1 + #define ACTIVE_DOC moo_edit_window_get_active_doc #define ACTIVE_PAGE(window) (moo_notebook_get_current_page (window->priv->notebook)) +static GSList *registered_panes = NULL; +static GSList *window_instances = NULL; + struct _MooEditWindowPrivate { MooEditor *editor; @@ -35,6 +41,7 @@ struct _MooEditWindowPrivate { MooNotebook *notebook; char *app_name; gboolean use_fullname; + GHashTable *panes; GtkWidget *languages_menu_item; GHashTable *lang_menu_items; @@ -56,7 +63,13 @@ static void moo_edit_window_get_property(GObject *object, GValue *value, GParamSpec *pspec); -static gboolean moo_edit_window_close (MooEditWindow *window); +static void moo_edit_window_destroy (GtkObject *object); + +static void register_fileview (void); +static void moo_edit_window_add_panes (MooEditWindow *window); +static void moo_edit_window_remove_panes(MooEditWindow *window); + +static gboolean moo_edit_window_close (MooEditWindow *window); static GtkMenuItem *create_lang_menu (MooEditWindow *window); @@ -64,7 +77,6 @@ static void lang_menu_item_toggled (GtkCheckMenuItem *item, MooEditWindow *window); static void active_tab_lang_changed (MooEditWindow *window); -static void setup_paned (MooEditWindow *window); static void setup_notebook (MooEditWindow *window); static void update_window_title (MooEditWindow *window); @@ -125,6 +137,7 @@ enum { static void moo_edit_window_class_init (MooEditWindowClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass); MooWindowClass *window_class = MOO_WINDOW_CLASS (klass); gobject_class->constructor = moo_edit_window_constructor; @@ -132,6 +145,8 @@ static void moo_edit_window_class_init (MooEditWindowClass *klass) gobject_class->set_property = moo_edit_window_set_property; gobject_class->get_property = moo_edit_window_get_property; + gtkobject_class->destroy = moo_edit_window_destroy; + window_class->close = (gboolean (*) (MooWindow*))moo_edit_window_close; g_object_class_install_property (gobject_class, @@ -386,27 +401,25 @@ static void moo_edit_window_class_init (MooEditWindowClass *klass) "create-menu-func", create_lang_menu, NULL); +#ifndef MOO_USE_FILE_VIEW moo_ui_object_class_new_action (gobject_class, "id", "ShowFileSelector", "dead", TRUE, NULL); -// moo_ui_object_class_new_action (gobject_class, -// "action-type::", MOO_TYPE_TOGGLE_ACTION, -// "id", "ShowFileSelector", -// "name", "Show File Selector", -// "label", "Show File Selector", -// "tooltip", "Show File Selector", -// "toggled-callback", show_file_selector_toggled_cb, -// NULL); +#endif } static void moo_edit_window_init (MooEditWindow *window) { +#ifdef MOO_USE_FILE_VIEW + register_fileview (); +#endif + window->priv = g_new0 (MooEditWindowPrivate, 1); - + window->priv->panes = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_object_unref); window->priv->app_name = g_strdup ("medit"); - window->priv->lang_menu_items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); @@ -427,7 +440,7 @@ MooEditWindow *_moo_edit_window_new (MooEditor *editor) } -MooEditor *_moo_edit_window_get_editor (MooEditWindow *window) +MooEditor *moo_edit_window_get_editor (MooEditWindow *window) { g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL); return window->priv->editor; @@ -437,6 +450,9 @@ MooEditor *_moo_edit_window_get_editor (MooEditWindow *window) static void moo_edit_window_finalize (GObject *object) { MooEditWindow *window = MOO_EDIT_WINDOW (object); + /* XXX */ + g_hash_table_destroy (window->priv->panes); + g_hash_table_destroy (window->priv->lang_menu_items); g_free (window->priv->app_name); g_free (window->priv); G_OBJECT_CLASS (moo_edit_window_parent_class)->finalize (object); @@ -488,6 +504,13 @@ static void moo_edit_window_get_property(GObject *object, } +MooBigPaned *moo_edit_window_get_paned (MooEditWindow *window) +{ + g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL); + return window->priv->paned; +} + + void _moo_edit_window_set_app_name (MooEditWindow *window, const char *name) { @@ -538,7 +561,6 @@ GObject *moo_edit_window_constructor (GType type, gtk_widget_show (paned); gtk_box_pack_start (GTK_BOX (MOO_WINDOW(window)->vbox), paned, TRUE, TRUE, 0); window->priv->paned = MOO_BIG_PANED (paned); - setup_paned (window); notebook = g_object_new (MOO_TYPE_NOTEBOOK, "show-tabs", TRUE, @@ -552,10 +574,27 @@ GObject *moo_edit_window_constructor (GType type, g_signal_connect (window, "realize", G_CALLBACK (update_window_title), NULL); + window_instances = g_slist_append (window_instances, window); + moo_edit_window_add_panes (window); + return object; } +static void moo_edit_window_destroy (GtkObject *object) +{ + MooEditWindow *window = MOO_EDIT_WINDOW (object); + + if (g_slist_find (window_instances, window)) + { + moo_edit_window_remove_panes (window); + window_instances = g_slist_remove (window_instances, window); + } + + GTK_OBJECT_CLASS(moo_edit_window_parent_class)->destroy (object); +} + + /* XXX */ static void update_window_title (MooEditWindow *window) { @@ -1234,16 +1273,6 @@ static gboolean notebook_populate_popup (MooNotebook *notebook, } -/****************************************************************************/ -/* Panes and notebook - */ - -static void setup_paned (G_GNUC_UNUSED MooEditWindow *window) -{ - /* XXX */ -} - - /****************************************************************************/ /* Languages menu */ @@ -1466,3 +1495,442 @@ static void edit_cursor_moved (MooEditWindow *window, set_statusbar_numbers (window, line, column); } } + + +/****************************************************************************/ +/* Panes + */ + +typedef struct { + MooEditWindowPaneInfo info; + gpointer data; + gboolean initialized; +} PaneFullInfo; + +static PaneFullInfo *pane_full_info_new (MooEditWindowPaneInfo *pane_info, + gpointer data); +static void pane_full_info_free (PaneFullInfo *info); + +static PaneFullInfo *find_pane (const char *id); +static void moo_edit_window_add_pane (MooEditWindow *window, + const char *id); +static void moo_edit_window_remove_pane(MooEditWindow *window, + const char *id); + + +void +moo_edit_window_register_pane (MooEditWindowPaneInfo *info, + gpointer data) +{ + PaneFullInfo *full_info; + GSList *l; + + g_return_if_fail (info != NULL); + g_return_if_fail (info->id && info->id[0]); + g_return_if_fail (g_utf8_validate (info->id, -1, NULL)); + g_return_if_fail (!info->name || g_utf8_validate (info->name, -1, NULL)); + g_return_if_fail (!info->description || g_utf8_validate (info->description, -1, NULL)); + g_return_if_fail (info->create != NULL); + + full_info = pane_full_info_new (info, data); + g_return_if_fail (full_info != NULL); + + if (find_pane (full_info->info.id)) + { + g_warning ("pane with id '%s' already registered", info->id); + moo_edit_window_unregister_pane (full_info->info.id); + } + + g_return_if_fail (find_pane (full_info->info.id) == NULL); + + if (full_info->info.params->enabled) + { + if (full_info->info.init && !full_info->info.init (&full_info->info, full_info->data)) + { + pane_full_info_free (full_info); + return; + } + else + { + full_info->initialized = TRUE; + } + } + + registered_panes = g_slist_append (registered_panes, full_info); + + for (l = window_instances; l != NULL; l = l->next) + moo_edit_window_add_pane (l->data, full_info->info.id); +} + + +void +moo_edit_window_unregister_pane (const char *id) +{ + PaneFullInfo *full_info; + GSList *l; + + g_return_if_fail (id != NULL); + + full_info = find_pane (id); + g_return_if_fail (full_info != NULL); + + registered_panes = g_slist_remove (registered_panes, full_info); + + for (l = window_instances; l != NULL; l = l->next) + moo_edit_window_remove_pane (l->data, full_info->info.id); + + if (full_info->initialized && full_info->info.deinit) + full_info->info.deinit (&full_info->info, full_info->data); + full_info->initialized = FALSE; + + pane_full_info_free (full_info); +} + + +static void +moo_edit_window_add_panes (MooEditWindow *window) +{ + GSList *l; + + g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + + for (l = registered_panes; l != NULL; l = l->next) + { + PaneFullInfo *full_info = l->data; + moo_edit_window_add_pane (window, full_info->info.id); + } +} + + +static void +moo_edit_window_remove_panes (MooEditWindow *window) +{ + GSList *l, *reversed; + + g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + + reversed = g_slist_copy (registered_panes); + reversed = g_slist_reverse (reversed); + + for (l = reversed; l != NULL; l = l->next) + { + PaneFullInfo *full_info = l->data; + moo_edit_window_remove_pane (window, full_info->info.id); + } + + g_slist_free (reversed); +} + + +static PaneFullInfo* +find_pane (const char *id) +{ + GSList *l; + + g_return_val_if_fail (id != NULL, NULL); + + for (l = registered_panes; l != NULL; l = l->next) + { + PaneFullInfo *full_info = l->data; + if (!strcmp (full_info->info.id, id)) + return full_info; + } + + return NULL; +} + + +static void +moo_edit_window_add_pane (MooEditWindow *window, + const char *id) +{ + PaneFullInfo *full_info; + MooPaneLabel *label = NULL; + GtkWidget *widget = NULL; + + g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + + full_info = find_pane (id); + g_return_if_fail (full_info != NULL); + + if (!full_info->info.params->enabled) + return; + + if (!full_info->initialized) + { + if (full_info->info.init && !full_info->info.init (&full_info->info, full_info->data)) + return; + full_info->initialized = TRUE; + } + + if (!full_info->info.create (window, &full_info->info, &label, &widget, full_info->data)) + return; + + g_return_if_fail (GTK_IS_WIDGET (widget) && label != NULL); + + if (moo_big_paned_insert_pane (window->priv->paned, widget, label, + full_info->info.params->position, -1) >= 0) + g_hash_table_insert (window->priv->panes, + g_strdup (full_info->info.id), + g_object_ref (widget)); + + gtk_widget_unref (widget); + moo_pane_label_free (label); +} + + +static void +moo_edit_window_remove_pane (MooEditWindow *window, + const char *id) +{ + PaneFullInfo *full_info; + GtkWidget *widget; + + g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + + full_info = find_pane (id); + g_return_if_fail (full_info != NULL); + + widget = g_hash_table_lookup (window->priv->panes, id); + + if (widget) + { + if (full_info->info.destroy) + full_info->info.destroy (window, &full_info->info, full_info->data); + + g_hash_table_remove (window->priv->panes, full_info->info.id); + moo_big_paned_remove_pane (window->priv->paned, widget); + } +} + + +static PaneFullInfo* +pane_full_info_new (MooEditWindowPaneInfo *pane_info, + gpointer data) +{ + PaneFullInfo *full_info; + + g_return_val_if_fail (pane_info != NULL, NULL); + g_return_val_if_fail (pane_info->id != NULL, NULL); + g_return_val_if_fail (pane_info->create != NULL, NULL); + g_return_val_if_fail (pane_info->params != NULL, NULL); + + full_info = g_new0 (PaneFullInfo, 1); + + full_info->data = data; + full_info->initialized = FALSE; + + full_info->info.id = g_strdup (pane_info->id); + full_info->info.name = g_strdup (pane_info->name ? pane_info->name : pane_info->id); + full_info->info.description = g_strdup (pane_info->description ? + pane_info->description : + full_info->info.name); + + full_info->info.init = pane_info->init; + full_info->info.deinit = pane_info->deinit; + full_info->info.create = pane_info->create; + full_info->info.destroy = pane_info->destroy; + + full_info->info.params = g_new (MooEditWindowPaneParams, 1); + full_info->info.params->position = pane_info->params->position; + full_info->info.params->enabled = pane_info->params->enabled; + + return full_info; +} + + +static void pane_full_info_free (PaneFullInfo *full_info) +{ + if (full_info) + { + g_free (full_info->info.params); + g_free ((char*) full_info->info.id); + g_free ((char*) full_info->info.name); + g_free ((char*) full_info->info.description); + g_free (full_info); + } +} + + +GtkWidget *moo_edit_window_lookup_pane (MooEditWindow *window, + const char *id) +{ + g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL); + g_return_val_if_fail (id != NULL, NULL); + g_return_val_if_fail (window->priv->panes != NULL, NULL); + return g_hash_table_lookup (window->priv->panes, id); +} + + +/****************************************************************************/ +/* Fileview pane + */ + +#define FILEVIEW_PANE_ID "fileview" + +#define FILEVIEW_DIR_PREFS "panes/fileview/last_dir" + + +static void +show_fileview (MooEditWindow *window) +{ + GtkWidget *fileview = moo_edit_window_lookup_pane (window, FILEVIEW_PANE_ID); + MooBigPaned *paned = moo_edit_window_get_paned (window); + + if (MOO_IS_BIG_PANED (paned) && MOO_IS_FILE_VIEW (fileview)) + moo_big_paned_present_pane (paned, fileview); +} + + +static gboolean +fileview_factory_init_func (G_GNUC_UNUSED MooEditWindowPaneInfo *info) +{ + GObjectClass *klass = g_type_class_ref (MOO_TYPE_EDIT_WINDOW); + g_return_val_if_fail (klass != NULL, FALSE); + + moo_ui_object_class_new_action (klass, + "id", "ShowFileSelector", + "name", "Show File Selector", + "label", "Show File Selector", + "tooltip", "Show file selector", + "icon-stock-id", MOO_STOCK_FILE_SELECTOR, + "closure::callback", show_fileview, + NULL); + + moo_prefs_new_key_string (FILEVIEW_DIR_PREFS, NULL); + + g_type_class_unref (klass); + return TRUE; +} + + +static void +fileview_factory_deinit_func (G_GNUC_UNUSED MooEditWindowPaneInfo *info) +{ + /* XXX remove action */ +} + + +/* XXX */ +static gboolean +fileview_go_home (MooFileView *fileview) +{ + const char *dir; + char *real_dir = NULL; + + if (!MOO_IS_FILE_VIEW (fileview)) + return FALSE; + + dir = moo_prefs_get_string (FILEVIEW_DIR_PREFS); + + if (dir) + real_dir = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL); + + if (!real_dir || !moo_file_view_chdir (fileview, real_dir, NULL)) + g_signal_emit_by_name (fileview, "go-home"); + + g_free (real_dir); + return FALSE; +} + + +static void +fileview_chdir (MooFileView *fileview, + G_GNUC_UNUSED GParamSpec *whatever) +{ + char *dir = NULL; + char *utf8_dir = NULL; + + g_object_get (fileview, "current-directory", &dir, NULL); + + if (!dir) + { + moo_prefs_set (FILEVIEW_DIR_PREFS, NULL); + return; + } + + utf8_dir = g_filename_to_utf8 (dir, -1, NULL, NULL, NULL); + moo_prefs_set_string (FILEVIEW_DIR_PREFS, utf8_dir); + + g_free (utf8_dir); + g_free (dir); +} + + +static void +fileview_activate (G_GNUC_UNUSED MooFileView *fileview, + const char *path, + MooEditWindow *window) +{ + moo_editor_open_file (moo_edit_window_get_editor (window), + window, NULL, path, NULL); +} + + +static gboolean +fileview_create_func (MooEditWindow *window, + G_GNUC_UNUSED MooEditWindowPaneInfo *info, + MooPaneLabel **label, + GtkWidget **widget) +{ + GtkWidget *fileview; + + fileview = moo_file_view_new (); + + g_idle_add ((GSourceFunc) fileview_go_home, fileview); + g_signal_connect (fileview, "notify::current-directory", + G_CALLBACK (fileview_chdir), NULL); + g_signal_connect (fileview, "activate", + G_CALLBACK (fileview_activate), window); + + *widget = fileview; + gtk_object_sink (GTK_OBJECT (g_object_ref (*widget))); + *label = moo_pane_label_new (MOO_STOCK_FILE_SELECTOR, + NULL, NULL, "File Selector"); + + return TRUE; +} + + +static void +fileview_destroy_func (MooEditWindow *window, + G_GNUC_UNUSED MooEditWindowPaneInfo *info) +{ + GtkWidget *fileview = moo_edit_window_lookup_pane (window, FILEVIEW_PANE_ID); + g_return_if_fail (fileview != NULL); + g_signal_handlers_disconnect_by_func (fileview, + (gpointer) fileview_chdir, + NULL); + g_signal_handlers_disconnect_by_func (fileview, + (gpointer) fileview_activate, + window); +} + + +static void register_fileview (void) +{ + static gboolean done = FALSE; + + if (!done) + { + MooEditWindowPaneParams params = { + MOO_PANE_POS_LEFT, + TRUE + }; + + MooEditWindowPaneInfo info = { + FILEVIEW_PANE_ID, + "File Selector", + "File Selector", + (MooPaneFactoryInitFunc) fileview_factory_init_func, + (MooPaneFactoryDeinitFunc) fileview_factory_deinit_func, + (MooPaneCreateFunc) fileview_create_func, + (MooPaneDestroyFunc) fileview_destroy_func, + ¶ms + }; + + moo_edit_window_register_pane (&info, NULL); + } + + done = TRUE; +} diff --git a/moo/mooedit/mooeditwindow.h b/moo/mooedit/mooeditwindow.h index 40ce7198..7cf34831 100644 --- a/moo/mooedit/mooeditwindow.h +++ b/moo/mooedit/mooeditwindow.h @@ -44,14 +44,14 @@ struct _MooEditWindowClass }; -GType moo_edit_window_get_type (void) G_GNUC_CONST; +GType moo_edit_window_get_type (void) G_GNUC_CONST; -MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window); -void moo_edit_window_set_active_doc (MooEditWindow *window, - MooEdit *edit); +MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window); +void moo_edit_window_set_active_doc (MooEditWindow *window, + MooEdit *edit); -GSList *moo_edit_window_list_docs (MooEditWindow *window); -guint moo_edit_window_num_docs (MooEditWindow *window); +GSList *moo_edit_window_list_docs (MooEditWindow *window); +guint moo_edit_window_num_docs (MooEditWindow *window); G_END_DECLS diff --git a/moo/mooedit/mooeditwindowpane.h b/moo/mooedit/mooeditwindowpane.h new file mode 100644 index 00000000..762debcd --- /dev/null +++ b/moo/mooedit/mooeditwindowpane.h @@ -0,0 +1,73 @@ +/* + * mooeditwindowpane.h + * + * Copyright (C) 2004-2005 by Yevgen Muntyan + * + * 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. + */ + +#ifndef __MOO_EDIT_WINDOW_PANE_H__ +#define __MOO_EDIT_WINDOW_PANE_H__ + +#include "mooedit/mooeditwindow.h" +#include "mooedit/moobigpaned.h" + +G_BEGIN_DECLS + + +typedef struct _MooEditWindowPaneInfo MooEditWindowPaneInfo; +typedef struct _MooEditWindowPaneParams MooEditWindowPaneParams; + + +typedef gboolean (*MooPaneFactoryInitFunc) (MooEditWindowPaneInfo *info, + gpointer data); +typedef void (*MooPaneFactoryDeinitFunc)(MooEditWindowPaneInfo *info, + gpointer data); +typedef gboolean (*MooPaneCreateFunc) (MooEditWindow *window, + MooEditWindowPaneInfo *info, + MooPaneLabel **label, + GtkWidget **widget, + gpointer data); +typedef void (*MooPaneDestroyFunc) (MooEditWindow *window, + MooEditWindowPaneInfo *info, + gpointer data); + + +struct _MooEditWindowPaneInfo +{ + const char *id; + const char *name; + const char *description; + + MooPaneFactoryInitFunc init; + MooPaneFactoryDeinitFunc deinit; + MooPaneCreateFunc create; + MooPaneDestroyFunc destroy; + + MooEditWindowPaneParams *params; +}; + +struct _MooEditWindowPaneParams +{ + MooPanePosition position; + gboolean enabled; +}; + + +void moo_edit_window_register_pane (MooEditWindowPaneInfo *info, + gpointer data); +void moo_edit_window_unregister_pane(const char *id); + +GtkWidget *moo_edit_window_lookup_pane (MooEditWindow *window, + const char *id); +MooBigPaned *moo_edit_window_get_paned (MooEditWindow *window); + + +G_END_DECLS + +#endif /* __MOO_EDIT_WINDOW_PANE_H__ */ diff --git a/moo/mooedit/moofileview/glade/Makefile.am b/moo/mooedit/moofileview/glade/Makefile.am index b45670fa..64901ce9 100644 --- a/moo/mooedit/moofileview/glade/Makefile.am +++ b/moo/mooedit/moofileview/glade/Makefile.am @@ -1 +1 @@ -EXTRA_DIST = create_folder.glade fileprops.glade bookmark_editor.glade +EXTRA_DIST = bookmark_editor.glade diff --git a/moo/mooedit/moofileview/glade/create_folder.glade b/moo/mooedit/moofileview/glade/create_folder.glade deleted file mode 100644 index 7b6d2880..00000000 --- a/moo/mooedit/moofileview/glade/create_folder.glade +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - New Folder - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - True - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - 0.5 - 0.5 - 1 - 1 - 6 - 6 - 6 - 6 - - - - True - False - 6 - - - - True - Create new folder in: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - /home/muntyan - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - True - True - True - 0 - New Folder - True - * - True - - - 0 - False - False - - - - - - - 0 - True - True - - - - - - - diff --git a/moo/mooedit/moofileview/glade/fileprops.glade b/moo/mooedit/moofileview/glade/fileprops.glade deleted file mode 100644 index 9c18849e..00000000 --- a/moo/mooedit/moofileview/glade/fileprops.glade +++ /dev/null @@ -1,514 +0,0 @@ - - - - - - - True - File Properties - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_DIALOG - GDK_GRAVITY_NORTH_WEST - False - - - - True - False - 0 - - - - True - GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - False - -6 - - - - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - False - -5 - - - - - 0 - False - True - GTK_PACK_END - - - - - - True - True - True - True - GTK_POS_TOP - False - False - - - - True - 0.5 - 0.5 - 1 - 1 - 6 - 6 - 6 - 6 - - - - True - False - 6 - - - - True - False - 6 - - - - True - True - GTK_RELIEF_NONE - False - - - - True - gtk-directory - 6 - 0.5 - 0.5 - 0 - 0 - - - - - 0 - False - False - - - - - - True - True - True - True - True - 0 - File - True - * - True - - - 0 - True - True - - - - - 0 - False - False - - - - - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 0 - 0 - - - - True - 6 - 2 - False - 6 - 6 - - - - True - <b>Type:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - <b>Size:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - <b>Location:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - <b>MIME type:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - 15 GB - False - False - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 1 - 2 - fill - - - - - - - True - True - /home/muntyan/Desktop - False - False - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 2 - 3 - fill - - - - - - - True - True - text/x-uknown - False - False - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 3 - 4 - fill - - - - - - - True - True - Some file type - False - False - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 0 - 1 - fill - - - - - - - True - <b>Modified:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 4 - 5 - fill - - - - - - - True - True - /home/muntyan/Desktop/another_file - False - False - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 4 - 5 - fill - - - - - - - True - True - /home/muntyan/Desktop/another_file - False - False - GTK_JUSTIFY_LEFT - True - True - 0 - 0.5 - 0 - 0 - - - 1 - 2 - 5 - 6 - fill - - - - - - - True - <b>Points to:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 1 - 0.5 - 0 - 0 - - - 0 - 1 - 5 - 6 - fill - - - - - - - - 0 - True - True - - - - - - - False - True - - - - - - True - General - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - tab - - - - - 0 - True - True - - - - - - - diff --git a/moo/mooedit/moofileview/moofile.c b/moo/mooedit/moofileview/moofile.c index d357c86a..00871994 100644 --- a/moo/mooedit/moofileview/moofile.c +++ b/moo/mooedit/moofileview/moofile.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifndef __WIN32__ #include "xdgmime/xdgmime.h" @@ -81,7 +82,7 @@ struct _MooFolderPrivate { Stage wanted_bg; MooFileSystem *fs; GDir *dir; - GHashTable *files; + GHashTable *files; /* basename -> MooFile* */ GSList *files_copy; char *path; GSourceFunc populate_func; @@ -940,11 +941,60 @@ static gboolean moo_folder_reload (MooFolder *folder) } -void moo_folder_get_file_info (MooFolder *folder, +/* XXX */ +static char *moo_file_get_type_string (MooFile *file) +{ + g_return_val_if_fail (MOO_FILE_EXISTS (file), NULL); + + if (MOO_FILE_IS_DIR (file)) + return g_strdup ("folder"); + else if (file->mime_type) + return g_strdup (file->mime_type); + else + return g_strdup ("file"); +} + + +/* XXX */ +static char *moo_file_get_size_string (MooFile *file) +{ + return g_strdup_printf ("%" G_GINT64_FORMAT, (MooFileSize) file->statbuf.st_size); +} + + +/* XXX */ +static char *moo_file_get_mtime_string (MooFile *file) +{ + static char buf[1024]; + + if (!MOO_FILE_EXISTS (file)) + return NULL; + +#ifdef __WIN32__ + if (MOO_FILE_IS_DIR (file)) + return NULL; +#endif + + if (strftime (buf, 1024, "%x %X", localtime ((time_t*)&file->statbuf.st_mtime))) + return g_strdup (buf); + else + return NULL; +} + + +char **moo_folder_get_file_info (MooFolder *folder, MooFile *file) { - g_return_if_fail (MOO_IS_FOLDER (folder)); - g_return_if_fail (file != NULL); + GPtrArray *array; + GSList *list; + + g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL); + g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (!folder->priv->deleted, NULL); + g_return_val_if_fail (folder->priv->files != NULL, NULL); + g_return_val_if_fail (g_hash_table_lookup (folder->priv->files, + moo_file_name (file)) == file, NULL); + moo_file_stat (file, folder->priv->path); #ifndef __WIN32__ @@ -959,6 +1009,66 @@ void moo_folder_get_file_info (MooFolder *folder, g_free (path); } #endif + + array = g_ptr_array_new (); + + if (file->info & MOO_FILE_INFO_EXISTS) + { + char *type, *mtime, *location; + + g_ptr_array_add (array, g_strdup ("Type:")); + type = moo_file_get_type_string (file); + + if (file->info & MOO_FILE_INFO_IS_LINK) + { + g_ptr_array_add (array, g_strdup_printf ("link to %s", type)); + g_free (type); + } + else + { + g_ptr_array_add (array, type); + } + + location = g_filename_display_name (moo_folder_get_path (folder)); + g_ptr_array_add (array, g_strdup ("Location:")); + g_ptr_array_add (array, location); + + if (!(file->info & MOO_FILE_INFO_IS_DIR)) + { + g_ptr_array_add (array, g_strdup ("Size:")); + g_ptr_array_add (array, moo_file_get_size_string (file)); + } + + mtime = moo_file_get_mtime_string (file); + + if (mtime) + { + g_ptr_array_add (array, g_strdup ("Modified:")); + g_ptr_array_add (array, mtime); + } + } + else if (file->info & MOO_FILE_INFO_IS_LINK) + { + g_ptr_array_add (array, g_strdup ("Type:")); + g_ptr_array_add (array, g_strdup ("broken symbolic link")); + } + + if ((file->info & MOO_FILE_INFO_IS_LINK) && + moo_file_link_get_target (file)) + { + g_ptr_array_add (array, g_strdup ("Points to:")); + g_ptr_array_add (array, g_strdup (moo_file_link_get_target (file))); + } + + list = g_slist_append (NULL, moo_file_ref (file)); + g_object_ref (folder); + folder_emit_files (folder, FILES_CHANGED, list); + g_object_unref (folder); + moo_file_unref (file); + g_slist_free (list); + + g_ptr_array_add (array, NULL); + return (char**) g_ptr_array_free (array, FALSE); } @@ -1988,7 +2098,7 @@ static GdkPixbuf *_create_broken_icon (G_GNUC_UNUSED GtkIconTheme *ico static GdkPixbuf *_create_icon_with_flags (GdkPixbuf *original, MooIconFlags flags, - GtkIconTheme *icon_theme, + G_GNUC_UNUSED GtkIconTheme *icon_theme, G_GNUC_UNUSED GtkWidget *widget, GtkIconSize size) { diff --git a/moo/mooedit/moofileview/moofile.h b/moo/mooedit/moofileview/moofile.h index 96e250e4..6b28bce2 100644 --- a/moo/mooedit/moofileview/moofile.h +++ b/moo/mooedit/moofileview/moofile.h @@ -178,7 +178,7 @@ MooFolder *moo_folder_get_parent (MooFolder *folder, MooFileFlags wanted); char *moo_folder_get_parent_path (MooFolder *folder); -void moo_folder_get_file_info (MooFolder *folder, +char **moo_folder_get_file_info (MooFolder *folder, MooFile *file); diff --git a/moo/mooedit/moofileview/moofileview-dialogs.c b/moo/mooedit/moofileview/moofileview-dialogs.c index ff717ecb..0c4a34d9 100644 --- a/moo/mooedit/moofileview/moofileview-dialogs.c +++ b/moo/mooedit/moofileview/moofileview-dialogs.c @@ -11,15 +11,9 @@ * See COPYING file that comes with this distribution. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #define MOO_FILE_SYSTEM_COMPILATION #include "moofileview-dialogs.h" #include "moofilesystem.h" -#include "xdgmime/xdgmime.h" -#include #include #include @@ -32,15 +26,10 @@ static void dialog_response (GtkWidget *dialog, static void dialog_ok (GtkWidget *dialog); -#ifndef MOO_FILE_PROPS_GLADE_FILE -#define MOO_FILE_PROPS_GLADE_FILE "fileprops.glade" -#endif - - GtkWidget *moo_file_props_dialog_new (GtkWidget *parent) { - GtkWidget *dialog, *notebook, *entry; - GladeXML *xml; + GtkWidget *dialog, *notebook, *alignment, *vbox, *hbox, *label, *button; + GtkWidget *table, *icon, *entry; if (parent) parent = gtk_widget_get_toplevel (parent); @@ -54,25 +43,48 @@ GtkWidget *moo_file_props_dialog_new (GtkWidget *parent) GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - xml = glade_xml_new (MOO_FILE_PROPS_GLADE_FILE, "notebook", NULL); - - if (!xml) - g_error ("Yes, glade is great usually, but not always"); - - g_object_set_data_full (G_OBJECT (dialog), "dialog-glade-xml", - xml, g_object_unref); - - notebook = glade_xml_get_widget (xml, "notebook"); - g_assert (notebook != NULL); + notebook = gtk_notebook_new (); + gtk_widget_show (notebook); gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 0); - entry = glade_xml_get_widget (xml, "entry_name"); - gtk_widget_grab_focus (entry); + alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 6, 6); + gtk_widget_show (alignment); + label = gtk_label_new ("General"); + gtk_widget_show (alignment); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), alignment, label); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_widget_show (vbox); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + button = gtk_button_new (); + icon = gtk_image_new (); + gtk_container_add (GTK_CONTAINER (button), icon); + entry = gtk_entry_new (); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + gtk_widget_show_all (hbox); + + table = gtk_table_new (1, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 6); + gtk_table_set_col_spacings (GTK_TABLE (table), 6); + gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); g_object_set_data (G_OBJECT (dialog), MAGIC_STRING, MAGIC_NUMBER); g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL); + gtk_widget_grab_focus (entry); + + g_object_set_data (G_OBJECT (dialog), "moo-dialog-icon", icon); + g_object_set_data (G_OBJECT (dialog), "moo-dialog-entry", entry); + g_object_set_data (G_OBJECT (dialog), "moo-dialog-table", table); + g_object_set_data (G_OBJECT (dialog), "moo-dialog-notebook", notebook); + return dialog; } @@ -99,10 +111,6 @@ static void dialog_response (GtkWidget *dialog, } -#define get_widget(dialog,name) \ - (glade_xml_get_widget (g_object_get_data (G_OBJECT (dialog), "dialog-glade-xml"), name)) - - static void dialog_ok (GtkWidget *dialog) { GtkWidget *entry; @@ -118,7 +126,9 @@ static void dialog_ok (GtkWidget *dialog) if (!file) return; - entry = get_widget (dialog, "entry_name"); + entry = g_object_get_data (G_OBJECT (dialog), "moo-dialog-entry"); + g_return_if_fail (GTK_IS_ENTRY (entry)); + old_name = moo_file_display_name (file); new_name = gtk_entry_get_text (GTK_ENTRY (entry)); @@ -163,7 +173,8 @@ static void set_file (GtkWidget *dialog, MooFile *file, MooFolder *folder) { - GtkWidget *entry = get_widget (dialog, "entry_name"); + GtkWidget *entry = g_object_get_data (G_OBJECT (dialog), "moo-dialog-entry"); + g_return_if_fail (GTK_IS_ENTRY (entry)); if (file) { @@ -194,71 +205,45 @@ static void set_file (GtkWidget *dialog, } -static void set_label (GtkWidget *dialog, - const char *label_name, - const char *text) -{ - GtkWidget *label = get_widget (dialog, label_name); - gtk_label_set_text (GTK_LABEL (label), text ? text : ""); -} - - -static void set_points_to (GtkWidget *dialog, - const char *text) -{ - GtkWidget *label = get_widget (dialog, "points_to_label"); - GtkWidget *caption = get_widget (dialog, "points_to_caption"); - - if (text && text[0]) - { - gtk_widget_show (label); - gtk_widget_show (caption); - gtk_label_set_text (GTK_LABEL (label), text); - } - else - { - gtk_widget_hide (label); - gtk_widget_hide (caption); - } -} - - static void set_icon (GtkWidget *dialog, GdkPixbuf *icon) { - GtkWidget *image = get_widget (dialog, "image_icon"); - gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon); + GtkImage *image = g_object_get_data (G_OBJECT (dialog), "moo-dialog-icon"); + g_return_if_fail (GTK_IS_IMAGE (image)); + gtk_image_set_from_pixbuf (image, icon); } -#define MAX_DATE_LEN 1024 +static void erase_table (GtkWidget *table) +{ + gtk_container_foreach (GTK_CONTAINER (table), + (GtkCallback) gtk_widget_destroy, NULL); +} + void moo_file_props_dialog_set_file (GtkWidget *dialog, MooFile *file, MooFolder *folder) { - GdkPixbuf *icon; char *text; - GtkWidget *notebook; - MooFileTime mtime; - MooFileSize size; - char buf[MAX_DATE_LEN]; + GtkWidget *notebook, *table; + char **info, **p; + int i; g_return_if_fail (GTK_IS_DIALOG (dialog)); g_return_if_fail ((!file && !folder) || (file && MOO_IS_FOLDER (folder))); g_return_if_fail (g_object_get_data (G_OBJECT (dialog), MAGIC_STRING) == MAGIC_NUMBER); - notebook = get_widget (dialog, "notebook"); + notebook = g_object_get_data (G_OBJECT (dialog), "moo-dialog-notebook"); + table = g_object_get_data (G_OBJECT (dialog), "moo-dialog-table"); + g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); + g_return_if_fail (GTK_IS_TABLE (table)); if (!file) { gtk_widget_set_sensitive (notebook, FALSE); - + erase_table (table); set_file (dialog, NULL, NULL); - set_label (dialog, "location_label", NULL); - set_label (dialog, "mime_label", NULL); - set_points_to (dialog, NULL); - return; } else @@ -266,64 +251,49 @@ void moo_file_props_dialog_set_file (GtkWidget *dialog, gtk_widget_set_sensitive (notebook, TRUE); } - moo_folder_get_file_info (folder, file); - - icon = moo_file_get_icon (file, dialog, GTK_ICON_SIZE_DIALOG); - set_icon (dialog, icon); + info = moo_folder_get_file_info (folder, file); + g_return_if_fail (info != NULL); + set_icon (dialog, moo_file_get_icon (file, dialog, GTK_ICON_SIZE_DIALOG)); set_file (dialog, file, folder); - text = g_filename_display_name (moo_folder_get_path (folder)); - set_label (dialog, "location_label", text); - g_free (text); - - set_label (dialog, "mime_label", moo_file_get_mime_type (file)); - - if (MOO_FILE_IS_LINK (file)) + for (p = info, i = 0; *p != NULL; ++i) { -#ifndef __WIN32__ - char *display_target; - const char *target = moo_file_link_get_target (file); + GtkWidget *label; - if (target) - display_target = g_filename_display_name (target); - else - display_target = g_strdup (""); + if (!p[1]) + { + g_critical ("%s: oops", G_STRLOC); + break; + } - set_points_to (dialog, display_target); - g_free (display_target); -#endif /* !__WIN32__ */ - } - else - { - set_points_to (dialog, NULL); + label = gtk_label_new (NULL); + text = g_markup_printf_escaped ("%s", *(p++)); + gtk_label_set_markup (GTK_LABEL (label), text); + g_free (text); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, i, i+1, + GTK_EXPAND | GTK_FILL, 0, 0, 0); + + label = gtk_label_new (*(p++)); + gtk_label_set_selectable (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 1, 2, i, i+1, + GTK_EXPAND | GTK_FILL, 0, 0, 0); } - size = moo_file_get_size (file); - text = g_strdup_printf ("%" G_GINT64_FORMAT, size); - set_label (dialog, "size_label", text); - g_free (text); + gtk_widget_show_all (table); - mtime = moo_file_get_mtime (file); - if (strftime (buf, MAX_DATE_LEN, "%x %X", localtime ((time_t*)&mtime))) - set_label (dialog, "time_label", buf); - else - set_label (dialog, "time_label", NULL); + g_strfreev (info); } -#ifndef MOO_CREATE_FOLDER_GLADE_FILE -#define MOO_CREATE_FOLDER_GLADE_FILE "create_folder.glade" -#endif - - char *moo_create_folder_dialog (GtkWidget *parent, MooFolder *folder) { - GtkWidget *dialog, *entry, *label; - GladeXML *xml; - char *path, *new_folder_name = NULL; + GtkWidget *dialog, *entry, *label, *alignment, *vbox; + char *text, *path, *new_folder_name = NULL; g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL); @@ -332,31 +302,42 @@ char *moo_create_folder_dialog (GtkWidget *parent, if (!GTK_IS_WINDOW (parent)) parent = NULL; - xml = glade_xml_new (MOO_CREATE_FOLDER_GLADE_FILE, NULL, NULL); + dialog = gtk_dialog_new_with_buttons ("New Folder", + parent ? GTK_WINDOW (parent) : NULL, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); - if (!xml) - g_error ("Yes, glade is great usually, but not always"); + alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 6, 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), alignment, TRUE, TRUE, 0); + vbox = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (alignment), vbox); - dialog = glade_xml_get_widget (xml, "dialog"); - entry = glade_xml_get_widget (xml, "entry"); - label = glade_xml_get_widget (xml, "location_label"); - g_assert (dialog != NULL && entry != NULL && label != NULL); + label = gtk_label_new (NULL); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); path = g_filename_display_name (moo_folder_get_path (folder)); - gtk_label_set_text (GTK_LABEL (label), path); + text = g_strdup_printf ("Create new folder in %s", path); + gtk_label_set_text (GTK_LABEL (label), text); g_free (path); + g_free (text); - gtk_entry_set_text (GTK_ENTRY (entry), "New Folder"); - gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); - gtk_widget_grab_focus (entry); + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0); if (parent) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); + gtk_entry_set_text (GTK_ENTRY (entry), "New Folder"); + gtk_widget_show_all (dialog); + gtk_widget_grab_focus (entry); + gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) new_folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); gtk_widget_destroy (dialog); - g_object_unref (xml); return new_folder_name; } diff --git a/moo/mooedit/moofileview/moofileview.c b/moo/mooedit/moofileview/moofileview.c index f26f8809..454a0bb5 100644 --- a/moo/mooedit/moofileview/moofileview.c +++ b/moo/mooedit/moofileview/moofileview.c @@ -313,7 +313,6 @@ static void moo_file_view_class_init (MooFileViewClass *klass) g_get_home_dir (), #else #warning "Do something here" - NULL, #endif G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); diff --git a/moo/mooedit/moonotebook.c b/moo/mooedit/moonotebook.c index 520b011d..c92dcdba 100644 --- a/moo/mooedit/moonotebook.c +++ b/moo/mooedit/moonotebook.c @@ -735,7 +735,7 @@ static int labels_get_height_request (MooNotebook *nb) { int height = 0; GtkRequisition child_req; - gboolean has_visible; + gboolean has_visible = FALSE; g_assert (nb->priv->tabs_visible); @@ -1069,7 +1069,7 @@ static void moo_notebook_draw_child_border (MooNotebook *nb, GtkWidget *widget = GTK_WIDGET (nb); Page *page = nb->priv->current_page; int border_width = gtk_container_get_border_width (GTK_CONTAINER (nb)); - gboolean draw_gap; + gboolean draw_gap = TRUE; int gap_x, gap_width; if (!page) @@ -1536,7 +1536,10 @@ static void delete_page (MooNotebook *nb, if (page == nb->priv->current_page) nb->priv->current_page = NULL; - /* XXX disconnect focus_child */ + if (page->focus_child) + g_object_weak_unref (G_OBJECT (page->focus_child), + (GWeakNotify) g_nullify_pointer, + &page->focus_child); g_free (page->label->text); g_free (page->label); diff --git a/moo/mooedit/moopaned.c b/moo/mooedit/moopaned.c index 270a1111..2af960d2 100644 --- a/moo/mooedit/moopaned.c +++ b/moo/mooedit/moopaned.c @@ -145,6 +145,8 @@ static gboolean moo_paned_button_release(GtkWidget *widget, static int pane_index (MooPaned *paned, Pane *pane); +static Pane *get_nth_pane (MooPaned *paned, + guint index_); static void moo_paned_open_pane_real(MooPaned *paned, guint index); @@ -1744,12 +1746,29 @@ GtkWidget *moo_paned_get_nth_pane (MooPaned *paned, { Pane *pane; g_return_val_if_fail (MOO_IS_PANED (paned), NULL); - pane = g_slist_nth_data (paned->priv->panes, n); + pane = get_nth_pane (paned, n); g_return_val_if_fail (pane != NULL, NULL); return pane->child; } +int moo_paned_get_pane_num (MooPaned *paned, + GtkWidget *widget) +{ + Pane *pane; + + g_return_val_if_fail (MOO_IS_PANED (paned), -1); + g_return_val_if_fail (GTK_IS_WIDGET (widget), -1); + + pane = g_object_get_data (G_OBJECT (widget), "moo-pane"); + + if (pane) + return pane_index (paned, pane); + else + return -1; +} + + MooPaneLabel *moo_paned_get_label (MooPaned *paned, GtkWidget *pane_widget) { @@ -2132,21 +2151,24 @@ static GtkWidget *moo_pane_label_get_widget (MooPaneLabel *label, } -void moo_paned_add_pane (MooPaned *paned, +int moo_paned_add_pane (MooPaned *paned, GtkWidget *pane_widget, const char *button_label, const char *button_stock_id, int position) { MooPaneLabel *label; + int result; - g_return_if_fail (MOO_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (pane_widget)); - g_return_if_fail (pane_widget->parent == NULL); + g_return_val_if_fail (MOO_IS_PANED (paned), -1); + g_return_val_if_fail (GTK_IS_WIDGET (pane_widget), -1); + g_return_val_if_fail (pane_widget->parent == NULL, -1); label = moo_pane_label_new (button_stock_id, NULL, NULL, button_label); - moo_paned_insert_pane (paned, pane_widget, label, position); + result = moo_paned_insert_pane (paned, pane_widget, label, position); + moo_pane_label_free (label); + return result; } @@ -2342,7 +2364,7 @@ static GtkWidget *create_frame_widget (MooPaned *paned, } -void moo_paned_insert_pane (MooPaned *paned, +int moo_paned_insert_pane (MooPaned *paned, GtkWidget *pane_widget, MooPaneLabel *pane_label, int position) @@ -2350,10 +2372,10 @@ void moo_paned_insert_pane (MooPaned *paned, GtkWidget *button, *label_widget; Pane *pane; - g_return_if_fail (MOO_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (pane_widget)); - g_return_if_fail (pane_label != NULL); - g_return_if_fail (pane_widget->parent == NULL); + g_return_val_if_fail (MOO_IS_PANED (paned), -1); + g_return_val_if_fail (GTK_IS_WIDGET (pane_widget), -1); + g_return_val_if_fail (pane_label != NULL, -1); + g_return_val_if_fail (pane_widget->parent == NULL, -1); button = gtk_toggle_button_new (); gtk_widget_show (button); @@ -2428,22 +2450,24 @@ void moo_paned_insert_pane (MooPaned *paned, if (GTK_WIDGET_VISIBLE (paned)) gtk_widget_queue_resize (GTK_WIDGET (paned)); + + return position; } -void moo_paned_remove_pane (MooPaned *paned, +gboolean moo_paned_remove_pane (MooPaned *paned, GtkWidget *pane_widget) { Pane *pane; GtkWidget *label; - g_return_if_fail (MOO_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (pane_widget)); + g_return_val_if_fail (MOO_IS_PANED (paned), FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (pane_widget), FALSE); pane = g_object_get_data (G_OBJECT (pane_widget), "moo-pane"); - g_return_if_fail (pane != NULL); - g_return_if_fail (pane->child == pane_widget); - g_return_if_fail (g_slist_find (paned->priv->panes, pane) != NULL); + g_return_val_if_fail (pane != NULL, FALSE); + g_return_val_if_fail (pane->child == pane_widget, FALSE); + g_return_val_if_fail (g_slist_find (paned->priv->panes, pane) != NULL, FALSE); if (paned->priv->current_pane == pane) moo_paned_hide_pane (paned); @@ -2510,6 +2534,8 @@ void moo_paned_remove_pane (MooPaned *paned, if (GTK_WIDGET_VISIBLE (paned)) gtk_widget_queue_resize (GTK_WIDGET (paned)); + + return TRUE; } @@ -2933,6 +2959,47 @@ static void detach_button_clicked (G_GNUC_UNUSED GtkWidget *button, } +void moo_paned_present_pane (MooPaned *paned, + guint index_) +{ + Pane *pane; + + g_return_if_fail (MOO_IS_PANED (paned)); + g_return_if_fail (index_ < moo_paned_n_panes (paned)); + + pane = get_nth_pane (paned, index_); + g_return_if_fail (pane != NULL); + + if (paned->priv->current_pane == pane) + { + paned->priv->dont_move_focus = FALSE; + + if (!find_focus (pane->child)) + { + if (pane->focus_child) + { + gtk_widget_grab_focus (pane->focus_child); + } + else if (!gtk_widget_child_focus (pane->child, GTK_DIR_TAB_FORWARD)) + { + paned->priv->button_real_focus = FALSE; + gtk_widget_grab_focus (pane->button); + } + } + + return; + } + else if (pane->detached) + { + gtk_window_present (GTK_WINDOW (pane->window)); + } + else + { + moo_paned_open_pane (paned, index_); + } +} + + static void moo_paned_open_pane_real(MooPaned *paned, guint index) { @@ -2941,7 +3008,7 @@ static void moo_paned_open_pane_real(MooPaned *paned, g_return_if_fail (index < moo_paned_n_panes (paned)); - pane = g_slist_nth_data (paned->priv->panes, index); + pane = get_nth_pane (paned, index); g_return_if_fail (pane != NULL); if (paned->priv->current_pane == pane) @@ -3091,6 +3158,13 @@ static int pane_index (MooPaned *paned, } +static Pane *get_nth_pane (MooPaned *paned, + guint index_) +{ + return g_slist_nth_data (paned->priv->panes, index_); +} + + int moo_paned_get_open_pane (MooPaned *paned) { g_return_val_if_fail (MOO_IS_PANED (paned), -1); @@ -3214,17 +3288,19 @@ static gboolean handle_button_release (GtkWidget *widget, { Pane *pane; - paned->priv->handle_button_pressed = FALSE; + if (paned->priv->handle_button_pressed) + { +#if 1 + gdk_window_set_cursor (widget->window, NULL); +#endif + paned->priv->handle_button_pressed = FALSE; + } if (!paned->priv->handle_in_drag) return FALSE; paned->priv->handle_in_drag = FALSE; -#if 1 - gdk_window_set_cursor (widget->window, NULL); -#endif - pane = g_object_get_data (G_OBJECT (widget), "moo-pane"); g_return_val_if_fail (pane != NULL && pane->child != NULL, FALSE); @@ -3429,7 +3505,6 @@ static gboolean pane_window_delete_event (GtkWidget *window, } -/* XXX focus */ void moo_paned_detach_pane (MooPaned *paned, guint index_) { @@ -3439,7 +3514,7 @@ void moo_paned_detach_pane (MooPaned *paned, g_return_if_fail (MOO_IS_PANED (paned)); - pane = g_slist_nth_data (paned->priv->panes, index_); + pane = get_nth_pane (paned, index_); g_return_if_fail (pane != NULL); if (pane->detached) @@ -3535,7 +3610,7 @@ void moo_paned_attach_pane (MooPaned *paned, g_return_if_fail (MOO_IS_PANED (paned)); - pane = g_slist_nth_data (paned->priv->panes, index_); + pane = get_nth_pane (paned, index_); g_return_if_fail (pane != NULL); if (!pane->detached) diff --git a/moo/mooedit/moopaned.h b/moo/mooedit/moopaned.h index 29363f55..5c42c3ae 100644 --- a/moo/mooedit/moopaned.h +++ b/moo/mooedit/moopaned.h @@ -86,22 +86,25 @@ MooPaneLabel *moo_pane_label_new (const char *stock_id, MooPaneLabel *moo_pane_label_copy (MooPaneLabel *label); void moo_pane_label_free (MooPaneLabel *label); -void moo_paned_add_pane (MooPaned *paned, +int moo_paned_add_pane (MooPaned *paned, GtkWidget *pane_widget, const char *label, const char *icon_stock_id, int position); -void moo_paned_insert_pane (MooPaned *paned, +int moo_paned_insert_pane (MooPaned *paned, GtkWidget *pane_widget, MooPaneLabel *pane_label, int position); -void moo_paned_remove_pane (MooPaned *paned, +gboolean moo_paned_remove_pane (MooPaned *paned, GtkWidget *pane_widget); guint moo_paned_n_panes (MooPaned *paned); GSList *moo_paned_get_panes (MooPaned *paned); GtkWidget *moo_paned_get_nth_pane (MooPaned *paned, guint n); +int moo_paned_get_pane_num (MooPaned *paned, + GtkWidget *widget); + /* label should be freed with moo_pane_label_free() */ MooPaneLabel *moo_paned_get_label (MooPaned *paned, GtkWidget *pane_widget); @@ -119,6 +122,8 @@ gboolean moo_paned_is_open (MooPaned *paned); void moo_paned_open_pane (MooPaned *paned, guint index_); +void moo_paned_present_pane (MooPaned *paned, + guint index_); void moo_paned_hide_pane (MooPaned *paned); void moo_paned_detach_pane (MooPaned *paned, guint index_); diff --git a/moo/mooui/moouiobject.c b/moo/mooui/moouiobject.c index 98cea9e9..415bf11b 100644 --- a/moo/mooui/moouiobject.c +++ b/moo/mooui/moouiobject.c @@ -32,9 +32,9 @@ static void moo_ui_object_set_id (MooUIObject *object, const char *id); static void moo_ui_object_add_class_actions (MooUIObject *object); -static void xml_changed (MooUIObject *object); -static void unref_xml (GObject *xml, - gpointer object); +static void xml_changed (MooUIObject *object); +static void disconnect_xml_changed (MooUIXML *xml, + gpointer object); GType moo_ui_object_get_type (void) @@ -170,10 +170,11 @@ MooUIXML *_moo_ui_object_get_ui_xml_impl (MooUIObject *object) xml = moo_ui_xml_new (); g_signal_connect_swapped (xml, "changed", G_CALLBACK (xml_changed), object); - g_object_set_qdata_full (G_OBJECT (object), - MOO_UI_OBJECT_UI_XML_QUARK, - xml, - (GDestroyNotify) unref_xml); + g_object_weak_ref (G_OBJECT (object), + (GWeakNotify) disconnect_xml_changed, xml); + g_object_set_qdata (G_OBJECT (object), + MOO_UI_OBJECT_UI_XML_QUARK, + xml); g_object_notify (G_OBJECT (object), "ui-object-xml"); } @@ -187,19 +188,27 @@ void _moo_ui_object_set_ui_xml_impl (MooUIObject *object, MooUIXML *old; g_return_if_fail (MOO_IS_UI_OBJECT (object)); + g_return_if_fail (!xml || MOO_IS_UI_XML (xml)); old = g_object_get_qdata (G_OBJECT (object), MOO_UI_OBJECT_UI_XML_QUARK); if (old == xml) return; + if (old) + { + g_object_weak_unref (G_OBJECT (object), + (GWeakNotify) disconnect_xml_changed, old); + disconnect_xml_changed (old, object); + } + if (xml) { - g_object_ref (G_OBJECT (xml)); g_signal_connect_swapped (xml, "changed", G_CALLBACK (xml_changed), object); - g_object_set_qdata_full (G_OBJECT (object), - MOO_UI_OBJECT_UI_XML_QUARK, - xml, - (GDestroyNotify) unref_xml); + g_object_weak_ref (G_OBJECT (object), + (GWeakNotify) disconnect_xml_changed, xml); + g_object_set_qdata (G_OBJECT (object), + MOO_UI_OBJECT_UI_XML_QUARK, + g_object_ref (xml)); } else { @@ -218,11 +227,13 @@ static void xml_changed (MooUIObject *object) } -static void unref_xml (GObject *xml, - gpointer object) +static void disconnect_xml_changed (MooUIXML *xml, + gpointer object) { - g_signal_handlers_disconnect_by_func (xml, (gpointer)xml_changed, - object); + guint num; + g_assert (MOO_IS_UI_XML (xml)); + num = g_signal_handlers_disconnect_by_func (xml, (gpointer) xml_changed, object); + g_assert (num == 1); g_object_unref (xml); } @@ -307,6 +318,7 @@ const char *moo_ui_object_class_get_name (GObjectClass *klass) } +/* XXX check existing instances */ void moo_ui_object_class_install_action (GObjectClass *klass, MooObjectFactory *action, diff --git a/moo/mooui/moouixml.c b/moo/mooui/moouixml.c index a7bfcfd8..d27f7a25 100644 --- a/moo/mooui/moouixml.c +++ b/moo/mooui/moouixml.c @@ -104,8 +104,11 @@ static void moo_ui_xml_init (MooUIXML *xml) static void moo_ui_xml_finalize (GObject *object) { MooUIXML *xml = MOO_UI_XML (object); - if (xml->doc) moo_markup_doc_unref (xml->doc); + + if (xml->doc) + moo_markup_doc_unref (xml->doc); xml->doc = NULL; + G_OBJECT_CLASS (moo_ui_xml_parent_class)->finalize (object); } @@ -166,17 +169,21 @@ static void moo_ui_xml_set_ui (MooUIXML *xml, { if (!ui) { - if (xml->doc) moo_markup_doc_unref (xml->doc); + if (xml->doc) + moo_markup_doc_unref (xml->doc); xml->doc = NULL; } - else { + else + { if (!xml->doc) { GError *err = NULL; xml->doc = moo_markup_parse_memory (ui, -1, &err); - if (!xml->doc) { + if (!xml->doc) + { g_critical ("moo_ui_xml_set_ui: could not parse markup\n%s", ui); - if (err) { + if (err) + { g_critical ("%s", err->message); g_error_free (err); } @@ -193,18 +200,27 @@ static void moo_ui_xml_set_ui (MooUIXML *xml, static void moo_ui_xml_set_markup (MooUIXML *xml, MooMarkupDoc *doc) { - if (doc == xml->doc) return; - if (xml->doc) moo_markup_doc_unref (xml->doc); + if (doc == xml->doc) + return; + + if (xml->doc) + moo_markup_doc_unref (xml->doc); + xml->doc = doc; - if (xml->doc) moo_markup_doc_ref (xml->doc); + + if (xml->doc) + moo_markup_doc_ref (xml->doc); } char *moo_ui_xml_get_ui (MooUIXML *xml) { g_return_val_if_fail (MOO_IS_UI_XML (xml), NULL); - if (!xml->doc) return NULL; - return moo_markup_node_get_string (MOO_MARKUP_NODE (xml->doc)); + + if (!xml->doc) + return NULL; + else + return moo_markup_node_get_string (MOO_MARKUP_NODE (xml->doc)); } @@ -224,25 +240,27 @@ gboolean moo_ui_xml_add_ui_from_string (MooUIXML *xml, g_return_val_if_fail (MOO_IS_UI_XML (xml) && ui != NULL, FALSE); - if (xml->doc) { + if (xml->doc) + { g_critical ("%s: implement me", G_STRLOC); return FALSE; } xml->doc = moo_markup_parse_memory (ui, len, &err); + if (xml->doc) { - if (error) *error = NULL; + g_clear_error (error); g_signal_emit (xml, signals[CHANGED], 0); return TRUE; } - - if (err) + else { - if (error) *error = err; - else g_error_free (err); + if (err) + g_propagate_error (error, err); + + return FALSE; } - return FALSE; } @@ -252,25 +270,20 @@ gboolean moo_ui_xml_add_ui_from_file (MooUIXML *xml, { g_return_val_if_fail (MOO_IS_UI_XML (xml) && file != NULL, FALSE); - if (xml->doc) { + if (xml->doc) + { g_critical ("%s: implement me", G_STRLOC); return FALSE; } - GError *err = NULL; - xml->doc = moo_markup_parse_file (file, &err); + xml->doc = moo_markup_parse_file (file, error); + if (xml->doc) { - if (error) *error = NULL; g_signal_emit (xml, signals[CHANGED], 0); return TRUE; } - if (err) - { - if (error) *error = err; - else g_error_free (err); - } return FALSE; } diff --git a/moo/mooui/moowindow.c b/moo/mooui/moowindow.c index 5a809010..006f4e16 100644 --- a/moo/mooui/moowindow.c +++ b/moo/mooui/moowindow.c @@ -343,7 +343,6 @@ static void moo_window_finalize (GObject *object) g_free (window->priv->menubar_ui_name); g_free (window->priv->toolbar_ui_name); - g_free (window->priv); if (window->accel_group) g_object_unref (window->accel_group); @@ -354,6 +353,8 @@ static void moo_window_finalize (GObject *object) g_source_remove (window->priv->save_size_id); window->priv->save_size_id = 0; + g_free (window->priv); + G_OBJECT_CLASS (moo_window_parent_class)->finalize (object); } diff --git a/moo/mooutils/moomarkup.c b/moo/mooutils/moomarkup.c index 60e39ddb..417bffa2 100644 --- a/moo/mooutils/moomarkup.c +++ b/moo/mooutils/moomarkup.c @@ -184,6 +184,7 @@ static void start_element (G_GNUC_UNUSED GMarkupParseContext *ctx, element_name, attribute_names, attribute_values); + g_assert (elm->parent == state->current); state->current = elm; } @@ -313,6 +314,8 @@ static void add_node (MooMarkupDoc *doc, } else { + g_assert (parent->children == NULL); + g_assert (parent->last == NULL); parent->children = node; parent->last = node; } @@ -323,11 +326,12 @@ static void moo_markup_text_node_add_text (MooMarkupText *node, const char *text, gsize text_len) { - char *tmp = (char*)g_memdup (node->text, sizeof(char) * (node->size + text_len)); - g_memmove (tmp + node->size, text, sizeof(char) * text_len); + char *tmp = (char*)g_memdup (node->text, node->size + text_len + 1); + g_memmove (tmp + node->size, text, text_len); tmp[node->size + text_len] = 0; g_free (node->text); node->text = tmp; + node->size += text_len; } @@ -366,13 +370,17 @@ static void collect_text_content (MooMarkupElement *node) static void moo_markup_node_free (MooMarkupNode *node) { MooMarkupNode *child; + GSList *children = NULL, *l; g_return_if_fail (node != NULL); - g_free (node->name); - for (child = node->children; child != NULL; child = child->next) - moo_markup_node_free (child); + children = g_slist_prepend (children, child); + + for (l = children; l != NULL; l = l->next) + moo_markup_node_free (l->data); + + g_free (node->name); switch (node->type) { @@ -389,6 +397,9 @@ static void moo_markup_node_free (MooMarkupNode *node) default: g_assert_not_reached (); } + + g_slist_free (children); + g_free (node); } @@ -609,32 +620,23 @@ void moo_markup_delete_node (MooMarkupNode *node) prev = node->prev; if (parent->children == node) + { + g_assert (node->prev == NULL); parent->children = next; + } + if (parent->last == node) + { + g_assert (node->next == NULL); parent->last = prev; + } if (prev) prev->next = next; if (next) next->prev = prev; - g_free (node->name); - - for (child = node->children; child != NULL; child = child->next) - moo_markup_node_free (child); - - switch (node->type) - { - case MOO_MARKUP_ELEMENT_NODE: - moo_markup_element_free (MOO_MARKUP_ELEMENT (node)); - break; - case MOO_MARKUP_TEXT_NODE: - case MOO_MARKUP_COMMENT_NODE: - moo_markup_text_node_free (node); - break; - default: - g_return_if_reached (); - } + moo_markup_node_free (node); } diff --git a/moo/mooutils/moostock.h b/moo/mooutils/moostock.h index 00609784..d9cd6d18 100644 --- a/moo/mooutils/moostock.h +++ b/moo/mooutils/moostock.h @@ -34,6 +34,8 @@ G_BEGIN_DECLS #define MOO_STOCK_DOC_MODIFIED_ON_DISK GTK_STOCK_DIALOG_WARNING #define MOO_STOCK_DOC_MODIFIED GTK_STOCK_SAVE +#define MOO_STOCK_FILE_SELECTOR GTK_STOCK_DIRECTORY + #define MOO_STOCK_SAVE_NONE "moo-save-none" #define MOO_STOCK_SAVE_SELECTED "moo-save-selected"