Added goto-current-dir button

master
Yevgen Muntyan 2005-11-07 14:50:24 +00:00
parent ac11192d65
commit e32166482a
8 changed files with 355 additions and 88 deletions

View File

@ -268,16 +268,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" create="template" name="GAP source" >
<type icon="source" ext="g" name="GAP source" create="template" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" create="template" name="C Source" >
<type icon="source_c" ext="c" name="C Source" create="template" >
<descr>A new empty C file.</descr>
</type>
</filetypes>

View File

@ -16,6 +16,7 @@
#endif
#include <gmodule.h>
#include <gtk/gtkbutton.h>
#include "mooedit/mooplugin-macro.h"
#include "mooutils/moofileview/moofileview.h"
#include "mooutils/moofileview/moobookmarkmgr.h"
@ -157,11 +158,31 @@ fileview_activate (MooEditWindow *window,
}
static void
goto_current_doc_dir (MooEditWindow *window)
{
GtkWidget *fileview;
MooEdit *doc;
const char *filename;
fileview = moo_edit_window_get_pane (window, PLUGIN_ID);
doc = moo_edit_window_get_active_doc (window);
filename = doc ? moo_edit_get_filename (doc) : NULL;
if (filename)
{
char *dirname = g_path_get_dirname (filename);
moo_file_view_chdir (MOO_FILE_VIEW (fileview), dirname, NULL);
g_free (dirname);
}
}
static void
file_selector_plugin_attach (Plugin *plugin,
MooEditWindow *window)
{
GtkWidget *fileview;
GtkWidget *fileview, *button;
MooEditor *editor;
MooPaneLabel *label;
@ -182,6 +203,12 @@ file_selector_plugin_attach (Plugin *plugin,
G_CALLBACK (fileview_activate),
window);
button = moo_file_view_add_button (MOO_FILE_VIEW (fileview),
GTK_TYPE_BUTTON, GTK_STOCK_JUMP_TO,
"Go to current document directory");
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (goto_current_doc_dir), window);
label = moo_pane_label_new (MOO_STOCK_FILE_SELECTOR,
NULL, NULL, "File Selector",
"File Selector");

View File

@ -18,7 +18,7 @@ class Plugin(object):
def init(self):
editor = moo.edit.editor_instance()
xml = editor.get_ui_xml()
moo.utils.window_class_add_action (moo.utils.Window, "ShowConsole",
moo.utils.window_class_add_action (moo.edit.EditWindow, "ShowConsole",
name="Show Console",
label="Show Console",
icon_stock_id=moo.utils.STOCK_TERMINAL,
@ -32,7 +32,7 @@ class Plugin(object):
editor = moo.edit.editor_instance()
xml = editor.get_ui_xml()
moo.utils.window_class_remove_action(moo.utils.Window, "ShowConsole");
moo.utils.window_class_remove_action(moo.edit.EditWindow, "ShowConsole");
if self.ui_merge_id:
xml.remove_ui(self.ui_merge_id)

View File

@ -173,7 +173,10 @@ mooutils_srcdir = $(srcdir)/$(mooutils)
mooutils_include_headers = \
$(mooutils)/eggregex.h \
$(mooutils)/mooaccel.h \
$(mooutils)/mooaccelbutton.h \
$(mooutils)/mooaction.h \
$(mooutils)/mooactiongroup.h \
$(mooutils)/moobigpaned.h \
$(mooutils)/moocellrenderercolor.h \
$(mooutils)/mooclosure.h \
@ -184,29 +187,33 @@ mooutils_include_headers = \
$(mooutils)/moohistoryentry.h \
$(mooutils)/moohistorylist.h \
$(mooutils)/moomarkup.h \
$(mooutils)/moomenuaction.h \
$(mooutils)/moomenumgr.h \
$(mooutils)/moomenutoolbutton.h \
$(mooutils)/moonotebook.h \
$(mooutils)/moopaned.h \
$(mooutils)/mooprefs.h \
$(mooutils)/mooprefsdialog.h \
$(mooutils)/mooprefsdialogpage.h \
$(mooutils)/moostock.h \
$(mooutils)/mooutils-gobject.h \
$(mooutils)/mooaccel.h \
$(mooutils)/mooaction.h \
$(mooutils)/mooactiongroup.h \
$(mooutils)/moomenuaction.h \
$(mooutils)/mootoggleaction.h \
$(mooutils)/moouixml.h \
$(mooutils)/mooutils-gobject.h \
$(mooutils)/mooutils-misc.h \
$(mooutils)/moowindow.h \
$(mooutils)/mooutils-python.h
$(mooutils)/mooutils-python.h \
$(mooutils)/moowindow.h
mooutils_sources = \
$(mooutils_include_headers) \
$(mooutils)/eggregex.c \
$(mooutils)/mooaccelbutton.c \
$(mooutils)/gtksourceundomanager.c \
$(mooutils)/gtksourceundomanager.h \
$(mooutils)/mooaccel.c \
$(mooutils)/mooaccelbutton-glade.h \
$(mooutils)/mooaccelbutton.c \
$(mooutils)/mooaccelprefs-glade.h \
$(mooutils)/mooaction.c \
$(mooutils)/mooactiongroup.c \
$(mooutils)/moobigpaned.c \
$(mooutils)/moocellrenderercolor.c \
$(mooutils)/mooclosure.c \
@ -223,30 +230,25 @@ mooutils_sources = \
$(mooutils)/moohistoryentry.c \
$(mooutils)/moohistorylist.c \
$(mooutils)/moomarkup.c \
$(mooutils)/moomenuaction.c \
$(mooutils)/moomenumgr.c \
$(mooutils)/moomenutoolbutton.c \
$(mooutils)/moonotebook.c \
$(mooutils)/moopaned.c \
$(mooutils)/mooprefs.c \
$(mooutils)/mooprefsdialog.c \
$(mooutils)/mooprefsdialogpage.c \
$(mooutils)/moostock.c \
$(mooutils)/mooutils-gobject.c \
$(mooutils)/mooutils-misc.c \
$(mooutils)/mooaccel.c \
$(mooutils)/mooaccelprefs-glade.h \
$(mooutils)/mooaction.c \
$(mooutils)/mooactiongroup.c \
$(mooutils)/moomenuaction.c \
$(mooutils)/mootoggleaction.c \
$(mooutils)/moouixml.c \
$(mooutils)/mooutils-gobject.c \
$(mooutils)/mooutils-misc.c \
$(mooutils)/moowindow.c \
$(mooutils)/gtksourceundomanager.c \
$(mooutils)/gtksourceundomanager.h \
$(mooutils)/stock-about-16.h \
$(mooutils)/stock-about-24.h \
$(mooutils)/stock-moo.h \
$(mooutils)/stock-edit-16.h \
$(mooutils)/stock-edit-24.h \
$(mooutils)/stock-moo.h \
$(mooutils)/stock-select-all-16.h \
$(mooutils)/stock-select-all-24.h \
$(mooutils)/stock-terminal-24.h

View File

@ -731,7 +731,6 @@ static void init_gui (MooFileView *fileview)
toolbar = create_toolbar (fileview);
gtk_widget_show (toolbar);
gtk_box_pack_start (box, toolbar, FALSE, FALSE, 0);
fileview->toolbar = toolbar;
entry = moo_file_entry_new ();
g_object_set_data (G_OBJECT (entry), "moo-file-view", fileview);
@ -821,61 +820,20 @@ void moo_file_view_set_view_type (MooFileView *fileview,
}
static void create_bookmarks_button (MooFileView *fileview,
GtkWidget *box,
GtkTooltips *tooltips)
GtkWidget*
moo_file_view_add_button (MooFileView *fileview,
GType type,
const char *stock_id,
const char *tip)
{
GtkWidget *icon, *button;
icon = gtk_image_new_from_stock (GTK_STOCK_ABOUT,
GTK_ICON_SIZE_MENU);
gtk_widget_show (GTK_WIDGET (icon));
button = gtk_toggle_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, "Bookmarks", "Bookmarks");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
g_signal_connect (button, "toggled",
G_CALLBACK (boomarks_button_toggled),
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 (goto_item_activated),
fileview);
}
static GtkWidget *create_toolbar (MooFileView *fileview)
{
GtkWidget *toolbar;
GtkTooltips *tooltips;
tooltips = g_object_get_data (G_OBJECT (fileview),
"moo-file-view-tooltips");
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), NULL);
g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_BUTTON), NULL);
tooltips = g_object_get_data (G_OBJECT (fileview), "moo-file-view-tooltips");
if (!tooltips)
{
tooltips = gtk_tooltips_new ();
@ -885,20 +843,66 @@ static GtkWidget *create_toolbar (MooFileView *fileview)
tooltips, g_object_unref);
}
toolbar = gtk_hbox_new (FALSE, 0);
button = g_object_new (type, NULL);
gtk_widget_show (button);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
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");
if (tip)
gtk_tooltips_set_tip (tooltips, button, tip, tip);
create_bookmarks_button (fileview, toolbar, tooltips);
gtk_box_pack_start (GTK_BOX (fileview->toolbar), button,
FALSE, FALSE, 0);
return toolbar;
if (stock_id)
{
icon = gtk_image_new_from_stock (stock_id,
GTK_ICON_SIZE_MENU);
gtk_widget_show (icon);
gtk_container_add (GTK_CONTAINER (button), icon);
}
return button;
}
static void
create_bookmarks_button (MooFileView *fileview)
{
GtkWidget *button;
button = moo_file_view_add_button (fileview, GTK_TYPE_TOGGLE_BUTTON,
GTK_STOCK_ABOUT, "Bookmarks");
g_signal_connect (button, "toggled",
G_CALLBACK (boomarks_button_toggled),
fileview);
}
static void
create_button (MooFileView *fileview,
const char *stock_id,
const char *tip,
const char *signal)
{
GtkWidget *button = moo_file_view_add_button (fileview, GTK_TYPE_BUTTON, stock_id, tip);
g_object_set_data (G_OBJECT (button), "moo-file-view-signal", (gpointer) signal);
g_signal_connect (button, "clicked", G_CALLBACK (goto_item_activated), fileview);
}
static GtkWidget*
create_toolbar (MooFileView *fileview)
{
fileview->toolbar = gtk_hbox_new (FALSE, 0);
create_button (fileview, GTK_STOCK_GO_UP, "Up", "go-up");
create_button (fileview, GTK_STOCK_GO_BACK, "Back", "go-back");
create_button (fileview, GTK_STOCK_GO_FORWARD, "Forward", "go-forward");
create_button (fileview, GTK_STOCK_HOME, "Home", "go-home");
create_bookmarks_button (fileview);
return fileview->toolbar;
}

View File

@ -84,6 +84,11 @@ void moo_file_view_set_sort_case_sensitive (MooFileView *filevie
void moo_file_view_set_typeahead_case_sensitive (MooFileView *fileview,
gboolean case_sensitive);
GtkWidget *moo_file_view_add_button (MooFileView *fileview,
GType type,
const char *stock_id,
const char *tip);
G_END_DECLS

View File

@ -0,0 +1,176 @@
/*
* moomenutoolbutton.c
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#include "mooutils/moomenutoolbutton.h"
#include <gtk/gtk.h>
enum {
PROP_0,
PROP_MENU
};
// enum {
// ACCEL_SET,
// LAST_SIGNAL
// };
// static guint signals[LAST_SIGNAL] = {0};
static void moo_menu_tool_button_class_init (MooMenuToolButtonClass *klass);
static void moo_menu_tool_button_init (MooMenuToolButton *button);
static void moo_menu_tool_button_destroy (GtkObject *object);
static void moo_menu_tool_button_toggled (GtkToggleToolButton *button);
G_DEFINE_TYPE(MooMenuToolButton, moo_menu_tool_button, GTK_TYPE_TOGGLE_TOOL_BUTTON)
static void
moo_menu_tool_button_class_init (MooMenuToolButtonClass *klass)
{
// GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
GtkToggleToolButtonClass *toggle_class = GTK_TOGGLE_TOOL_BUTTON_CLASS (klass);
// GtkToolButtonClass *button_class = GTK_TOOL_BUTTON_CLASS (klass);
// GtkToolItemClass *item_class = GTK_TOOL_ITEM_CLASS (klass);
gtkobject_class->destroy = moo_menu_tool_button_destroy;
toggle_class->toggled = moo_menu_tool_button_toggled;
}
static void
moo_menu_tool_button_init (G_GNUC_UNUSED MooMenuToolButton *button)
{
}
static void
moo_menu_tool_button_destroy (GtkObject *object)
{
MooMenuToolButton *button = MOO_MENU_TOOL_BUTTON (object);
if (button->menu)
gtk_widget_destroy (button->menu);
GTK_OBJECT_CLASS (moo_menu_tool_button_parent_class)->destroy (object);
}
GtkWidget*
moo_menu_tool_button_new (void)
{
return g_object_new (MOO_TYPE_MENU_TOOL_BUTTON, NULL);
}
static void
menu_position_func (G_GNUC_UNUSED GtkMenu *menu,
int *x,
int *y,
gboolean *push_in,
GtkWidget *button)
{
GtkRequisition req;
gdk_window_get_origin (button->window, x, y);
gtk_widget_size_request (button, &req);
*x += GTK_WIDGET(button)->allocation.width - req.width;
*y += GTK_WIDGET(button)->allocation.height;
*push_in = TRUE;
}
static void
moo_menu_tool_button_toggled (GtkToggleToolButton *button)
{
MooMenuToolButton *menu_button = MOO_MENU_TOOL_BUTTON (button);
if (!gtk_toggle_tool_button_get_active (button))
return;
if (!menu_button->menu)
return;
gtk_menu_popup (GTK_MENU (menu_button->menu), NULL, NULL,
(GtkMenuPositionFunc) menu_position_func,
button, 0, gtk_get_current_event_time ());
}
static void
menu_deactivated (GtkToggleToolButton *button)
{
gtk_toggle_tool_button_set_active (button, FALSE);
}
static void
menu_destroyed (MooMenuToolButton *button)
{
if (button->menu)
{
GtkWidget *menu = button->menu;
button->menu = NULL;
g_object_unref (menu);
}
}
void
moo_menu_tool_button_set_menu (MooMenuToolButton *button,
GtkWidget *menu)
{
g_return_if_fail (MOO_IS_MENU_TOOL_BUTTON (button));
g_return_if_fail (!menu || GTK_IS_MENU (menu));
if (button->menu == menu)
return;
if (button->menu)
{
g_signal_handlers_disconnect_by_func (button->menu,
(gpointer) menu_deactivated,
button);
g_signal_handlers_disconnect_by_func (button->menu,
(gpointer) menu_destroyed,
button);
g_object_unref (button->menu);
}
if (menu)
{
gtk_object_sink (g_object_ref (menu));
g_signal_connect_swapped (menu, "deactivate",
G_CALLBACK (menu_deactivated),
button);
g_signal_connect_swapped (menu, "destroy",
G_CALLBACK (menu_destroyed),
button);
}
button->menu = menu;
}
GtkWidget*
moo_menu_tool_button_get_menu (MooMenuToolButton *button)
{
g_return_val_if_fail (MOO_IS_MENU_TOOL_BUTTON (button), NULL);
return button->menu;
}

View File

@ -0,0 +1,53 @@
/*
* moomenutoolbutton.h
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#ifndef __MOO_MENU_TOOL_BUTTON_H__
#define __MOO_MENU_TOOL_BUTTON_H__
#include <gtk/gtktoggletoolbutton.h>
G_BEGIN_DECLS
#define MOO_TYPE_MENU_TOOL_BUTTON (moo_menu_tool_button_get_type ())
#define MOO_MENU_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOO_TYPE_MENU_TOOL_BUTTON, MooMenuToolButton))
#define MOO_MENU_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_MENU_TOOL_BUTTON, MooMenuToolButtonClass))
#define MOO_IS_MENU_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOO_TYPE_MENU_TOOL_BUTTON))
#define MOO_IS_MENU_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_MENU_TOOL_BUTTON))
#define MOO_MENU_TOOL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_MENU_TOOL_BUTTON, MooMenuToolButtonClass))
typedef struct _MooMenuToolButton MooMenuToolButton;
typedef struct _MooMenuToolButtonClass MooMenuToolButtonClass;
struct _MooMenuToolButton {
GtkToggleToolButton parent;
GtkWidget *menu;
};
struct _MooMenuToolButtonClass {
GtkToggleToolButtonClass parent_class;
};
GType moo_menu_tool_button_get_type (void) G_GNUC_CONST;
GtkWidget *moo_menu_tool_button_new (void);
void moo_menu_tool_button_set_menu (MooMenuToolButton *button,
GtkWidget *menu);
GtkWidget *moo_menu_tool_button_get_menu (MooMenuToolButton *button);
G_END_DECLS
#endif /* __MOO_MENU_TOOL_BUTTON_H__ */