* plugins/project-wizard/templates/terminal.wiz,
[anjuta-git-plugin.git] / src / start-with.c
blob2dceeefa30f5418230a0cfddfc3f722e5816064b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * start-with.c
4 * Copyright (C) 2003 Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc., 59
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <gtk/gtkdialog.h>
22 #include <glade/glade.h>
23 #include "anjuta.h"
24 #include "start-with.h"
26 #define GLADE_FILE PACKAGE_DATA_DIR"/glade/anjuta.glade"
28 static void
29 on_application_wizard_clicked (GtkButton *button, gpointer data)
31 GtkWidget *dialog = GTK_WIDGET (data);
32 gtk_signal_emit_by_name (GTK_OBJECT (app->menubar.file.new_project),
33 "activate", NULL);
34 gtk_widget_destroy (dialog);
37 static void
38 on_import_wizard_clicked (GtkButton *button, gpointer data)
40 GtkWidget *dialog = GTK_WIDGET (data);
41 gtk_signal_emit_by_name (GTK_OBJECT (app->menubar.file.import_project),
42 "activate", NULL);
43 gtk_widget_destroy (dialog);
46 static void
47 on_open_project_clicked (GtkButton *button, gpointer data)
49 GtkWidget *dialog = GTK_WIDGET (data);
50 gtk_signal_emit_by_name (GTK_OBJECT (app->menubar.file.open_project),
51 "activate", NULL);
52 gtk_widget_destroy (dialog);
55 static void
56 on_open_last_project_clicked (GtkButton *button, gpointer data)
58 GtkWidget *dialog;
59 /* Do not allow a second click */
60 gchar *prj_filename;
62 dialog = GTK_WIDGET (data);
63 gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
64 prj_filename = anjuta_preferences_get (app->preferences,
65 "anjuta.last.open.project");
66 project_dbase_load_project (app->project_dbase, prj_filename, TRUE);
67 g_free (prj_filename);
68 gtk_widget_destroy (dialog);
71 static void
72 on_open_file_clicked (GtkButton *button, gpointer data)
74 GtkWidget *dialog = GTK_WIDGET (data);
75 gtk_signal_emit_by_name (GTK_OBJECT (app->menubar.file.open_file),
76 "activate", NULL);
77 gtk_widget_destroy (dialog);
80 static void
81 on_new_file_clicked (GtkButton *button, gpointer data)
83 GtkWidget *dialog = GTK_WIDGET (data);
84 gtk_signal_emit_by_name (GTK_OBJECT (app->menubar.file.new_file),
85 "activate", NULL);
86 gtk_widget_destroy (dialog);
89 static void
90 on_do_not_show_again_toggled (GtkToggleButton *button, AnjutaPreferences *p)
92 gboolean state;
93 state = gtk_toggle_button_get_active (button);
94 anjuta_preferences_set_int (p, "donotshow.start.with.dialog", state);
97 static void
98 on_dialog_response (GtkWidget *dialog, gint response, gpointer data)
100 gtk_widget_destroy (dialog);
103 void
104 start_with_dialog_show (GtkWindow *parent, AnjutaPreferences *pref,
105 gboolean force)
107 GladeXML *gxml;
108 GtkWidget *dialog;
109 GtkWidget *button;
110 gboolean do_not_show;
111 gboolean reload_last_project;
112 gchar *last_project;
114 do_not_show = anjuta_preferences_get_int (pref, "donotshow.start.with.dialog");
115 reload_last_project = anjuta_preferences_get_int (pref, "reload.last.project");
116 last_project = anjuta_preferences_get (pref, "anjuta.last.open.project");
118 /* Return if the dialog is not to be shown */
119 if (!force && do_not_show) {
120 g_free (last_project)
121 return;
124 /* Return if preference for loading last project is set */
125 if (!force && reload_last_project &&
126 last_project && file_is_readable (last_project)) {
127 g_free (last_project);
128 return;
131 gxml = glade_xml_new (GLADE_FILE, "start_with_dialog", NULL);
132 g_return_if_fail (gxml != NULL);
134 dialog = glade_xml_get_widget (gxml, "start_with_dialog");
135 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
136 g_signal_connect (G_OBJECT (dialog), "response",
137 G_CALLBACK (on_dialog_response), pref);
139 button = glade_xml_get_widget (gxml, "application_wizard_button");
140 g_signal_connect (G_OBJECT (button), "clicked",
141 G_CALLBACK (on_application_wizard_clicked), dialog);
143 button = glade_xml_get_widget (gxml, "import_wizard_button");
144 g_signal_connect (G_OBJECT (button), "clicked",
145 G_CALLBACK (on_import_wizard_clicked), dialog);
147 button = glade_xml_get_widget (gxml, "open_project_button");
148 g_signal_connect (G_OBJECT (button), "clicked",
149 G_CALLBACK (on_open_project_clicked), dialog);
151 button = glade_xml_get_widget (gxml, "open_last_project_button");
152 g_signal_connect (G_OBJECT (button), "clicked",
153 G_CALLBACK (on_open_last_project_clicked), dialog);
155 if (last_project && file_is_readable (last_project))
156 gtk_widget_set_sensitive (button, TRUE);
157 else
158 gtk_widget_set_sensitive (button, FALSE);
160 button = glade_xml_get_widget (gxml, "open_file_button");
161 g_signal_connect (G_OBJECT (button), "clicked",
162 G_CALLBACK (on_open_file_clicked), dialog);
164 button = glade_xml_get_widget (gxml, "new_file_button");
165 g_signal_connect (G_OBJECT (button), "clicked",
166 G_CALLBACK (on_new_file_clicked), dialog);
168 button = glade_xml_get_widget (gxml, "do_not_show_button");
169 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), do_not_show);
170 g_signal_connect (G_OBJECT (button), "toggled",
171 G_CALLBACK (on_do_not_show_again_toggled), pref);
173 g_object_unref (gxml);
174 g_free (last_project);
175 gtk_widget_show (dialog);
178 void
179 start_with_dialog_save_yourself (AnjutaPreferences *pref, FILE *fp)
181 gint state = anjuta_preferences_get_int (pref, "donotshow.start.with.dialog");
182 fprintf (fp, "donotshow.start.with.dialog=%d\n", state);