1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
plugin.c
Copyright (C) 2000 Naba Kumar
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
#include <libanjuta/interfaces/ianjuta-project-manager.h>
#include <libanjuta/interfaces/ianjuta-wizard.h>
#include "file.h"
#include "plugin.h"
#define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-file-wizard.ui"
#define ICON_FILE "anjuta-file-wizard-plugin-48.png"
static gpointer parent_class;
static void
project_root_added (AnjutaPlugin *plugin, const gchar *name,
const GValue *value, gpointer user_data)
{
AnjutaFileWizardPlugin *w_plugin;
const gchar *root_uri;
w_plugin = ANJUTA_PLUGIN_FILE_WIZARD (plugin);
root_uri = g_value_get_string (value);
if (root_uri)
{
gchar *root_dir = anjuta_util_get_local_path_from_uri (root_uri);
if (root_dir)
w_plugin->top_dir = g_strdup(root_dir);
else
w_plugin->top_dir = NULL;
g_free (root_dir);
}
else
w_plugin->top_dir = NULL;
}
static void
project_root_removed (AnjutaPlugin *plugin, const gchar *name,
gpointer user_data)
{
AnjutaFileWizardPlugin *w_plugin;
w_plugin = ANJUTA_PLUGIN_FILE_WIZARD (plugin);
g_free (w_plugin->top_dir);
w_plugin->top_dir = NULL;
}
static gboolean
activate_plugin (AnjutaPlugin *plugin)
{
AnjutaFileWizardPlugin *w_plugin;
DEBUG_PRINT ("%s", "AnjutaFileWizardPlugin: Activating File wizard plugin ...");
w_plugin = ANJUTA_PLUGIN_FILE_WIZARD (plugin);
w_plugin->prefs = anjuta_shell_get_preferences (plugin->shell, NULL);
/* set up project directory watch */
w_plugin->root_watch_id = anjuta_plugin_add_watch (plugin,
IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI,
project_root_added,
project_root_removed,
NULL);
return TRUE;
}
static gboolean
deactivate_plugin (AnjutaPlugin *plugin)
{
AnjutaFileWizardPlugin *w_plugin;
w_plugin = ANJUTA_PLUGIN_FILE_WIZARD (plugin);
anjuta_plugin_remove_watch (plugin, w_plugin->root_watch_id, TRUE);
return TRUE;
}
static void
dispose (GObject *obj)
{
G_OBJECT_CLASS (parent_class)->dispose (obj);
}
static void
finalize (GObject *obj)
{
/* Finalization codes here */
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void
file_wizard_plugin_instance_init (GObject *obj)
{
AnjutaFileWizardPlugin *plugin = ANJUTA_PLUGIN_FILE_WIZARD (obj);
plugin->top_dir = NULL;
}
static void
file_wizard_plugin_class_init (GObjectClass *klass)
{
AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
plugin_class->activate = activate_plugin;
plugin_class->deactivate = deactivate_plugin;
klass->dispose = dispose;
klass->finalize = finalize;
}
static void
iwizard_activate (IAnjutaWizard *wiz, GError **err)
{
AnjutaFileWizardPlugin *plugin;
IAnjutaDocumentManager *docman;
plugin = ANJUTA_PLUGIN_FILE_WIZARD (wiz);
docman = anjuta_shell_get_interface (ANJUTA_PLUGIN (wiz)->shell,
IAnjutaDocumentManager, NULL);
display_new_file(plugin, docman);
}
static void
iwizard_iface_init (IAnjutaWizardIface *iface)
{
iface->activate = iwizard_activate;
}
ANJUTA_PLUGIN_BEGIN (AnjutaFileWizardPlugin, file_wizard_plugin);
ANJUTA_PLUGIN_ADD_INTERFACE(iwizard, IANJUTA_TYPE_WIZARD);
ANJUTA_PLUGIN_END;
ANJUTA_SIMPLE_PLUGIN (AnjutaFileWizardPlugin, file_wizard_plugin);
|