Added MooFileChooser

master
Yevgen Muntyan 2006-04-04 21:48:12 -05:00
parent 632ec59da6
commit bcefef042c
7 changed files with 277 additions and 61 deletions

View File

@ -24,7 +24,7 @@
</ignoreparts>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description/>
<description></description>
<secondaryLanguages>
<language>C</language>
</secondaryLanguages>
@ -36,10 +36,10 @@
<useconfiguration>debug</useconfiguration>
</general>
<run>
<mainprogram>medit</mainprogram>
<mainprogram>./medit</mainprogram>
<directoryradio>executable</directoryradio>
<customdirectory>/</customdirectory>
<programargs/>
<programargs></programargs>
<terminal>false</terminal>
<autocompile>false</autocompile>
<envvars/>
@ -216,11 +216,15 @@
</kdevautoproject>
<kdevdebugger>
<general>
<dbgshell/>
<dbgshell></dbgshell>
<programargs>--g-fatal-warnings</programargs>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>true</floatingtoolbar>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
</general>
<display>
<staticmembers>true</staticmembers>
@ -282,16 +286,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" name="GAP source" create="template" >
<type icon="source" ext="g" create="template" name="GAP source" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" name="C Source" create="template" >
<type icon="source_c" ext="c" create="template" name="C Source" >
<descr>A new empty C file.</descr>
</type>
</filetypes>
@ -318,7 +322,7 @@
</codecompletion>
<references/>
<creategettersetter>
<prefixGet/>
<prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>

View File

@ -39,6 +39,9 @@ if GTK_2_6
mooedit_plugins_sources += \
$(mooedit_plugins)/moofileselector-glade.h\
$(mooedit_plugins)/moofilechooser-glade.h \
$(mooedit_plugins)/moofileselector.h \
$(mooedit_plugins)/moofilechooser.c \
$(mooedit_plugins)/moofilechooser.h \
$(mooedit_plugins)/fileselector.c
endif

View File

@ -15,12 +15,12 @@
#include "config.h"
#endif
#include "mooedit/plugins/moofileselector.h"
#include "mooedit/mooplugin-macro.h"
#include "mooutils/moofileview/moofileview.h"
#include "mooutils/moofileview/moobookmarkmgr.h"
#include "mooedit/plugins/mooeditplugins.h"
#include "mooedit/plugins/moofileselector-glade.h"
#include "mooedit/plugins/moofilechooser-glade.h"
#include "mooedit/plugins/moofilechooser.h"
#include "mooutils/moostock.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-misc.h"
@ -49,28 +49,6 @@ typedef struct {
#define Plugin FileSelectorPlugin
#define MOO_TYPE_FILE_SELECTOR (moo_file_selector_get_type ())
#define MOO_FILE_SELECTOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_FILE_SELECTOR, MooFileSelector))
#define MOO_FILE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_FILE_SELECTOR, MooFileSelectorClass))
#define MOO_IS_FILE_SELECTOR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_FILE_SELECTOR))
#define MOO_IS_FILE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_FILE_SELECTOR))
#define MOO_FILE_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_FILE_SELECTOR, MooFileSelectorClass))
typedef struct {
MooFileView base;
MooEditWindow *window;
GtkWidget *button;
guint open_pane_timeout;
gboolean button_highlight;
GtkTargetList *targets;
gboolean waiting_for_tab;
} MooFileSelector;
typedef struct {
MooFileViewClass base_class;
} MooFileSelectorClass;
enum {
TARGET_MOO_EDIT_TAB = 1,
TARGET_URI_LIST = 2
@ -85,7 +63,6 @@ static GtkTargetEntry targets[] = {
#define OPEN_PANE_TIMEOUT 300
GType moo_file_selector_get_type (void) G_GNUC_CONST;
G_DEFINE_TYPE (MooFileSelector, moo_file_selector, MOO_TYPE_FILE_VIEW)
@ -1067,32 +1044,46 @@ show_file_selector (MooEditWindow *window)
}
// static void
// show_file_chooser (MooEditWindow *window)
// {
// GtkWidget *dialog;
// int response;
//
// dialog = g_object_get_data (G_OBJECT (window), "moo-file-chooser");
//
// if (!dialog)
// {
// MooGladeXML *xml;
//
// xml = moo_glade_xml_new_empty ();
// moo_glade_xml_map_id (xml, "fielview", MOO_TYPE_FILE_SELECTOR);
// moo_glade_xml_parse_memory (*xml, MOO_FILE_CHOOSER_GLADE_XML, -1, NULL);
//
// dialog = moo_glade_xml_get_widget (xml, "dialog");
// g_return_val_if_fail (dialog != NULL, NULL);
//
// gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
// g_object_set_data_full (G_OBJECT (window), "moo-file-chooser",
// dialog, gtk_widget_destroy);
// }
//
// response = gtk_dialog_run ();
// }
static void
show_file_chooser (MooEditWindow *window)
{
GtkWidget *dialog;
int response;
dialog = g_object_get_data (G_OBJECT (window), "moo-file-chooser");
if (!dialog)
{
dialog = moo_file_chooser_new ();
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
g_object_set_data_full (G_OBJECT (window), "moo-file-chooser",
dialog, (GDestroyNotify) gtk_widget_destroy);
}
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide (dialog);
if (response == GTK_RESPONSE_OK)
{
GSList *files = NULL;
GList *filenames;
filenames = moo_file_view_get_filenames (MOO_FILE_CHOOSER (dialog)->fileview);
while (filenames)
{
MooEditFileInfo *info = moo_edit_file_info_new (filenames->data, NULL);
files = g_slist_prepend (files, info);
g_free (filenames->data);
filenames = g_list_delete_link (filenames, filenames);
}
moo_editor_open (moo_edit_window_get_editor (window), window, NULL, files);
g_slist_foreach (files, (GFunc) moo_edit_file_info_free, NULL);
g_slist_free (files);
}
}
static gboolean
@ -1112,6 +1103,13 @@ file_selector_plugin_init (Plugin *plugin)
"icon-stock-id", MOO_STOCK_FILE_SELECTOR,
"closure-callback", show_file_selector,
NULL);
moo_window_class_new_action (klass, "ShowFileChooser",
"name", "Show File Chooser",
"label", "Show File Chooser",
"tooltip", "Show file chooser",
"icon-stock-id", MOO_STOCK_FILE_SELECTOR,
"closure-callback", show_file_chooser,
NULL);
plugin->ui_merge_id = moo_ui_xml_new_merge_id (xml);
@ -1119,6 +1117,10 @@ file_selector_plugin_init (Plugin *plugin)
"Editor/Menubar/View",
"ShowFileSelector",
"ShowFileSelector", -1);
moo_ui_xml_add_item (xml, plugin->ui_merge_id,
"Editor/Menubar/View",
"ShowFileChooser",
"ShowFileChooser", -1);
moo_prefs_new_key_string (DIR_PREFS, NULL);

View File

@ -0,0 +1,81 @@
/*
* moofilechooser.c
*
* Copyright (C) 2004-2006 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 "mooedit/plugins/moofilechooser.h"
#include "mooedit/plugins/moofilechooser-glade.h"
#include "mooutils/mooglade.h"
#include <gtk/gtk.h>
G_DEFINE_TYPE(MooFileChooser, moo_file_chooser, GTK_TYPE_DIALOG)
static void
fileview_activate (GtkDialog *dialog)
{
gtk_dialog_response (dialog, GTK_RESPONSE_OK);
}
static void
moo_file_chooser_destroy (GtkObject *object)
{
MooFileChooser *chooser = MOO_FILE_CHOOSER (object);
if (chooser->fileview)
{
g_signal_handlers_disconnect_by_func (chooser->fileview,
(gpointer) fileview_activate,
chooser);
chooser->fileview = NULL;
}
GTK_OBJECT_CLASS(moo_file_chooser_parent_class)->destroy (object);
}
static void
moo_file_chooser_class_init (MooFileChooserClass *klass)
{
GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
gtkobject_class->destroy = moo_file_chooser_destroy;
}
static void
moo_file_chooser_init (MooFileChooser *chooser)
{
MooGladeXML *xml;
GtkDialog *dialog = GTK_DIALOG (chooser);
xml = moo_glade_xml_new_empty ();
moo_glade_xml_map_id (xml, "fileview", MOO_TYPE_FILE_VIEW);
moo_glade_xml_fill_widget (xml, GTK_WIDGET (dialog),
MOO_FILE_CHOOSER_GLADE_XML, -1, "dialog");
gtk_dialog_set_alternative_button_order (dialog, GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL);
chooser->fileview = moo_glade_xml_get_widget (xml, "fileview");
g_signal_connect_swapped (chooser->fileview, "activate",
G_CALLBACK (fileview_activate),
chooser);
g_signal_emit_by_name (chooser->fileview, "go-home");
}
GtkWidget *
moo_file_chooser_new (void)
{
return g_object_new (MOO_TYPE_FILE_CHOOSER, NULL);
}

View File

@ -8,6 +8,8 @@
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="modal">True</property>
<property name="default_width">400</property>
<property name="default_height">300</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
@ -64,8 +66,21 @@
</child>
<child>
<widget class="GtkDrawingArea" id="fileview">
<widget class="GtkVBox" id="vbox">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkDrawingArea" id="fileview">
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -0,0 +1,52 @@
/*
* moofilechooser.h
*
* Copyright (C) 2004-2006 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_FILE_CHOOSER_H__
#define __MOO_FILE_CHOOSER_H__
#include "mooutils/moofileview/moofileview.h"
#include <gtk/gtkdialog.h>
G_BEGIN_DECLS
#define MOO_TYPE_FILE_CHOOSER (moo_file_chooser_get_type ())
#define MOO_FILE_CHOOSER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_FILE_CHOOSER, MooFileChooser))
#define MOO_FILE_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_FILE_CHOOSER, MooFileChooserClass))
#define MOO_IS_FILE_CHOOSER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_FILE_CHOOSER))
#define MOO_IS_FILE_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_FILE_CHOOSER))
#define MOO_FILE_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_FILE_CHOOSER, MooFileChooserClass))
typedef struct _MooFileChooser MooFileChooser;
typedef struct _MooFileChooserClass MooFileChooserClass;
struct _MooFileChooser
{
GtkDialog parent;
MooFileView *fileview;
};
struct _MooFileChooserClass
{
GtkDialogClass parent_class;
};
GType moo_file_chooser_get_type (void) G_GNUC_CONST;
GtkWidget *moo_file_chooser_new (void);
G_END_DECLS
#endif /* __MOO_FILE_CHOOSER_H__ */

View File

@ -0,0 +1,59 @@
/*
* moofileselector.h
*
* Copyright (C) 2004-2006 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_FILE_SELECTOR_H__
#define __MOO_FILE_SELECTOR_H__
#include "mooedit/mooeditwindow.h"
#include "mooutils/moofileview/moofileview.h"
G_BEGIN_DECLS
#define MOO_TYPE_FILE_SELECTOR (moo_file_selector_get_type ())
#define MOO_FILE_SELECTOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_FILE_SELECTOR, MooFileSelector))
#define MOO_FILE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_FILE_SELECTOR, MooFileSelectorClass))
#define MOO_IS_FILE_SELECTOR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_FILE_SELECTOR))
#define MOO_IS_FILE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_FILE_SELECTOR))
#define MOO_FILE_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_FILE_SELECTOR, MooFileSelectorClass))
typedef struct _MooFileSelector MooFileSelector;
typedef struct _MooFileSelectorClass MooFileSelectorClass;
struct _MooFileSelector
{
MooFileView parent;
MooEditWindow *window;
GtkWidget *button;
guint open_pane_timeout;
gboolean button_highlight;
GtkTargetList *targets;
gboolean waiting_for_tab;
};
struct _MooFileSelectorClass
{
MooFileViewClass parent_class;
};
GType moo_file_selector_get_type (void) G_GNUC_CONST;
GtkWidget *moo_file_selector_new (void);
G_END_DECLS
#endif /* __MOO_FILE_SELECTOR_H__ */