diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index c84a4c39..e76b09f1 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -28,6 +28,7 @@ struct _MooEditWindowPrivate { MooPaned *paned; GtkNotebook *notebook; + MooFileView *fileview; gboolean use_fullname; char *app_name; MooEditor *editor; @@ -90,7 +91,7 @@ static void file_saved (MooEditWindow *window, static void fileview_activate (MooEditWindow *window, MooFileViewFile *file); - +static void current_doc_dir_clicked (MooEditWindow *window); /* actions */ @@ -423,7 +424,7 @@ GObject *moo_edit_window_constructor (GType type, guint n_props, GObjectConstructParam *props) { - GtkWidget *notebook, *paned, *fileview; + GtkWidget *notebook, *paned, *fileview, *button, *icon; MooEdit *edit; MooEditFileMgr *mgr = NULL; MooEditWindow *window; @@ -450,10 +451,29 @@ GObject *moo_edit_window_constructor (GType type, mgr = moo_editor_get_file_mgr (window->priv->editor); fileview = GTK_WIDGET (g_object_new (MOO_TYPE_FILE_VIEW, - "file-mgr", mgr, NULL)); + "file-mgr", mgr, + "current-directory", g_get_home_dir (), + NULL)); g_signal_connect_swapped (fileview, "activate", G_CALLBACK (fileview_activate), window); + window->priv->fileview = MOO_FILE_VIEW (fileview); + + icon = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_MENU); + gtk_widget_show (GTK_WIDGET (icon)); + button = gtk_button_new (); + gtk_container_add (GTK_CONTAINER (button), icon); + gtk_widget_show (button); + gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_tooltips_set_tip (MOO_WINDOW(window)->tooltips, button, + "Current Document Directory", + "Current Document Directory"); + gtk_box_pack_end (GTK_BOX (MOO_FILE_VIEW (fileview)->toolbar), + button, FALSE, FALSE, 0); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (current_doc_dir_clicked), + window); moo_paned_add_pane (MOO_PANED (paned), fileview, "File Selector", @@ -1170,3 +1190,17 @@ static void fileview_activate (MooEditWindow *window, gtk_widget_grab_focus (GTK_WIDGET (edit)); } } + + +static void current_doc_dir_clicked (MooEditWindow *window) +{ + MooEdit *edit = moo_edit_window_get_active_doc (window); + const char *filename = moo_edit_get_filename (edit); + + if (filename) + { + char *dirname = g_path_get_dirname (filename); + moo_file_view_chdir (window->priv->fileview, dirname, NULL); + g_free (dirname); + } +} diff --git a/moo/mooedit/moofileview.c b/moo/mooedit/moofileview.c index 8ba13775..2f0d46ef 100644 --- a/moo/mooedit/moofileview.c +++ b/moo/mooedit/moofileview.c @@ -130,7 +130,7 @@ static int tree_compare_func (GtkTreeModel *model, static void init_gui (MooFileView *fileview); static void focus_to_file_view (MooFileView *fileview); static GtkWidget *create_toolbar (MooFileView *fileview); -static void toolbar_button_clicked (GtkToolButton *button, +static void toolbar_button_clicked (GtkButton *button, MooFileView *fileview); static GtkWidget *create_notebook (MooFileView *fileview); @@ -466,87 +466,54 @@ static void focus_to_file_view (MooFileView *fileview) } +static void create_button (MooFileView *fileview, + GtkWidget *box, + GtkTooltips *tooltips, + const char *stock_id, + const char *tip, + const char *signal) +{ + GtkWidget *icon, *button; + + icon = gtk_image_new_from_stock (stock_id, + GTK_ICON_SIZE_MENU); + gtk_widget_show (GTK_WIDGET (icon)); + button = gtk_button_new (); + gtk_container_add (GTK_CONTAINER (button), icon); + gtk_widget_show (button); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE); + gtk_tooltips_set_tip (tooltips, button, tip, tip); + gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); + g_object_set_data (G_OBJECT (button), "moo-file-view-signal", + (gpointer) signal); + g_signal_connect (button, "clicked", + G_CALLBACK (toolbar_button_clicked), + fileview); +} + static GtkWidget *create_toolbar (MooFileView *fileview) { - GtkWidget *toolbar, *icon; - GtkToolItem *item; + GtkWidget *toolbar; GtkTooltips *tooltips; tooltips = gtk_tooltips_new (); + toolbar = gtk_hbox_new (FALSE, 0); - /*********************************************************/ - /* Navigation toolbar */ - - toolbar = gtk_toolbar_new (); - gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE); - - gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), - GTK_ICON_SIZE_MENU); - - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), - GTK_TOOLBAR_ICONS); - - /* Up */ - icon = gtk_image_new_from_stock (GTK_STOCK_GO_UP, - GTK_ICON_SIZE_MENU); - gtk_widget_show (GTK_WIDGET (icon)); - item = gtk_tool_button_new (icon, NULL); - gtk_widget_show (GTK_WIDGET (item)); - gtk_tool_item_set_tooltip (item, tooltips, "Up", "Up"); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - g_object_set_data (G_OBJECT (item), "moo-file-view-signal", - (gpointer) "go-up"); - g_signal_connect (item, "clicked", - G_CALLBACK (toolbar_button_clicked), - fileview); - - /* Back */ - icon = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, - GTK_ICON_SIZE_MENU); - gtk_widget_show (GTK_WIDGET (icon)); - item = gtk_tool_button_new (icon, NULL); - gtk_widget_show (GTK_WIDGET (item)); - gtk_tool_item_set_tooltip (item, tooltips, "Back", "Back"); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - g_object_set_data (G_OBJECT (item), "moo-file-view-signal", - (gpointer) "go-back"); - g_signal_connect (item, "clicked", - G_CALLBACK (toolbar_button_clicked), - fileview); - - /* Forward */ - icon = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, - GTK_ICON_SIZE_MENU); - gtk_widget_show (GTK_WIDGET (icon)); - item = gtk_tool_button_new (icon, NULL); - gtk_widget_show (GTK_WIDGET (item)); - gtk_tool_item_set_tooltip (item, tooltips, "Forward", "Forward"); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - g_object_set_data (G_OBJECT (item), "moo-file-view-signal", - (gpointer) "go-forward"); - g_signal_connect (item, "clicked", - G_CALLBACK (toolbar_button_clicked), - fileview); - - /* Home */ - icon = gtk_image_new_from_stock (GTK_STOCK_HOME, - GTK_ICON_SIZE_MENU); - gtk_widget_show (GTK_WIDGET (icon)); - item = gtk_tool_button_new (icon, NULL); - gtk_widget_show (GTK_WIDGET (item)); - gtk_tool_item_set_tooltip (item, tooltips, "Home", "Home"); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - g_object_set_data (G_OBJECT (item), "moo-file-view-signal", - (gpointer) "go-home"); - g_signal_connect (item, "clicked", - G_CALLBACK (toolbar_button_clicked), - fileview); + create_button (fileview, toolbar, tooltips, + GTK_STOCK_GO_UP, "Up", "go-up"); + create_button (fileview, toolbar, tooltips, + GTK_STOCK_GO_BACK, "Back", "go-back"); + create_button (fileview, toolbar, tooltips, + GTK_STOCK_GO_FORWARD, "Forward", "go-forward"); + create_button (fileview, toolbar, tooltips, + GTK_STOCK_HOME, "Home", "go-home"); return toolbar; } -static void toolbar_button_clicked (GtkToolButton *button, +static void toolbar_button_clicked (GtkButton *button, MooFileView *fileview) { const char *signal = g_object_get_data (G_OBJECT (button),