2005-09-06 18:46:36 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
|
|
|
|
* fileselector.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.
|
|
|
|
*/
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2005-09-06 18:46:36 -07:00
|
|
|
#include <gmodule.h>
|
2005-09-08 00:46:48 -07:00
|
|
|
#include "mooedit/mooplugin.h"
|
2005-09-06 18:46:36 -07:00
|
|
|
#include "mooedit/moofileview/moofileview.h"
|
|
|
|
#include "mooedit/moofileview/moobookmarkmgr.h"
|
2005-09-08 00:46:48 -07:00
|
|
|
#include "mooedit/plugins/mooeditplugins.h"
|
2005-09-06 18:46:36 -07:00
|
|
|
#include "mooui/moouiobject.h"
|
|
|
|
#include "mooutils/moostock.h"
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
#ifndef MOO_VERSION
|
|
|
|
#define MOO_VERSION NULL
|
|
|
|
#endif
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
#define PLUGIN_ID "FileSelector"
|
|
|
|
#define DIR_PREFS MOO_PLUGIN_PREFS_ROOT "/" PLUGIN_ID "/last_dir"
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MooBookmarkMgr *bookmark_mgr;
|
2005-09-08 00:46:48 -07:00
|
|
|
} Plugin;
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_file_selector (MooEditWindow *window)
|
|
|
|
{
|
2005-09-08 00:46:48 -07:00
|
|
|
GtkWidget *fileview;
|
|
|
|
fileview = moo_edit_window_get_pane (window, PLUGIN_ID);
|
|
|
|
moo_big_paned_present_pane (window->paned, fileview);
|
2005-09-06 18:46:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2005-09-07 04:19:26 -07:00
|
|
|
file_selector_plugin_init (void)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
|
|
|
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_file_selector,
|
|
|
|
NULL);
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
moo_prefs_new_key_string (DIR_PREFS, NULL);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
g_type_class_unref (klass);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-09-08 00:46:48 -07:00
|
|
|
file_selector_plugin_deinit (Plugin *plugin)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
|
|
|
/* XXX remove action */
|
2005-09-08 00:46:48 -07:00
|
|
|
if (plugin->bookmark_mgr)
|
|
|
|
g_object_unref (plugin->bookmark_mgr);
|
|
|
|
plugin->bookmark_mgr = NULL;
|
2005-09-06 18:46:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
static gboolean
|
|
|
|
file_selector_go_home (MooFileView *fileview)
|
|
|
|
{
|
|
|
|
const char *dir;
|
|
|
|
char *real_dir = NULL;
|
|
|
|
|
|
|
|
if (!MOO_IS_FILE_VIEW (fileview))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
dir = moo_prefs_get_string (DIR_PREFS);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
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
|
2005-09-07 04:19:26 -07:00
|
|
|
fileview_chdir (MooFileView *fileview)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
|
|
|
char *dir = NULL;
|
|
|
|
char *utf8_dir = NULL;
|
|
|
|
|
|
|
|
g_object_get (fileview, "current-directory", &dir, NULL);
|
|
|
|
|
|
|
|
if (!dir)
|
|
|
|
{
|
2005-09-08 00:46:48 -07:00
|
|
|
moo_prefs_set (DIR_PREFS, NULL);
|
2005-09-06 18:46:36 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8_dir = g_filename_to_utf8 (dir, -1, NULL, NULL, NULL);
|
2005-09-08 00:46:48 -07:00
|
|
|
moo_prefs_set_string (DIR_PREFS, utf8_dir);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
g_free (utf8_dir);
|
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-09-07 04:19:26 -07:00
|
|
|
fileview_activate (MooEditWindow *window,
|
|
|
|
const char *path)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
|
|
|
moo_editor_open_file (moo_edit_window_get_editor (window),
|
|
|
|
window, NULL, path, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
static void
|
|
|
|
file_selector_plugin_attach (MooEditWindow *window,
|
|
|
|
Plugin *plugin)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
|
|
|
GtkWidget *fileview;
|
|
|
|
MooEditor *editor;
|
2005-09-08 00:46:48 -07:00
|
|
|
MooPaneLabel *label;
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
editor = moo_edit_window_get_editor (window);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
if (!plugin->bookmark_mgr)
|
|
|
|
plugin->bookmark_mgr = moo_bookmark_mgr_new ();
|
2005-09-06 18:46:36 -07:00
|
|
|
|
|
|
|
fileview = g_object_new (MOO_TYPE_FILE_VIEW,
|
|
|
|
"filter-mgr", moo_editor_get_filter_mgr (editor),
|
2005-09-08 00:46:48 -07:00
|
|
|
"bookmark-mgr", plugin->bookmark_mgr,
|
2005-09-06 18:46:36 -07:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_idle_add ((GSourceFunc) file_selector_go_home, fileview);
|
|
|
|
g_signal_connect (fileview, "notify::current-directory",
|
|
|
|
G_CALLBACK (fileview_chdir), NULL);
|
2005-09-07 04:19:26 -07:00
|
|
|
g_signal_connect_swapped (fileview, "activate",
|
|
|
|
G_CALLBACK (fileview_activate),
|
2005-09-08 00:46:48 -07:00
|
|
|
window);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
label = moo_pane_label_new (MOO_STOCK_FILE_SELECTOR,
|
|
|
|
NULL, NULL, "File Selector");
|
|
|
|
moo_edit_window_add_pane (window, PLUGIN_ID, fileview,
|
|
|
|
label, MOO_PANE_POS_LEFT);
|
2005-09-06 18:46:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-09-08 00:46:48 -07:00
|
|
|
file_selector_plugin_detach (MooEditWindow *window)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
2005-09-08 00:46:48 -07:00
|
|
|
GtkWidget *fileview = moo_edit_window_get_pane (window, PLUGIN_ID);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
g_return_if_fail (fileview != NULL);
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
g_signal_handlers_disconnect_by_func (fileview,
|
2005-09-06 18:46:36 -07:00
|
|
|
(gpointer) fileview_chdir,
|
|
|
|
NULL);
|
2005-09-08 00:46:48 -07:00
|
|
|
g_signal_handlers_disconnect_by_func (fileview,
|
2005-09-06 18:46:36 -07:00
|
|
|
(gpointer) fileview_activate,
|
2005-09-08 00:46:48 -07:00
|
|
|
window);
|
|
|
|
|
|
|
|
moo_edit_window_remove_pane (window, PLUGIN_ID);
|
2005-09-06 18:46:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
gboolean
|
|
|
|
moo_file_selector_init (void)
|
2005-09-06 18:46:36 -07:00
|
|
|
{
|
2005-09-08 00:46:48 -07:00
|
|
|
MooPluginParams params = { TRUE };
|
|
|
|
MooPluginPrefsParams prefs_params;
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
MooPluginInfo info = {
|
|
|
|
MOO_PLUGIN_CURRENT_VERSION,
|
2005-09-07 04:19:26 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
PLUGIN_ID,
|
2005-09-06 18:46:36 -07:00
|
|
|
"File Selector",
|
|
|
|
"File Selector",
|
2005-09-07 04:19:26 -07:00
|
|
|
"Yevgen Muntyan <muntyan@tamu.edu>",
|
|
|
|
MOO_VERSION,
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
(MooPluginInitFunc) file_selector_plugin_init,
|
|
|
|
(MooPluginDeinitFunc) file_selector_plugin_deinit,
|
|
|
|
(MooPluginWindowAttachFunc) file_selector_plugin_attach,
|
|
|
|
(MooPluginWindowDetachFunc) file_selector_plugin_detach,
|
2005-09-07 04:19:26 -07:00
|
|
|
|
2005-09-06 18:46:36 -07:00
|
|
|
¶ms,
|
|
|
|
&prefs_params
|
|
|
|
};
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
static Plugin plugin;
|
2005-09-06 18:46:36 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
return moo_plugin_register (&info, &plugin);
|
2005-09-06 18:46:36 -07:00
|
|
|
}
|