2007-01-15 18:12:32 +00:00
|
|
|
/*
|
|
|
|
* project.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
|
|
|
* Copyright 2007 Enrico Tröger <enrico.troeger@uvena.de>
|
|
|
|
* Copyright 2007 Nick Treleaven <nick.treleaven@btinternet.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Project Management.
|
|
|
|
*/
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
#include "geany.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
#include "project.h"
|
|
|
|
#include "dialogs.h"
|
|
|
|
#include "support.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "ui_utils.h"
|
2007-01-21 17:43:52 +00:00
|
|
|
#include "msgwindow.h"
|
2007-04-21 12:25:17 +00:00
|
|
|
#include "main.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
# include "win32.h"
|
|
|
|
#endif
|
2007-05-01 12:27:56 +00:00
|
|
|
#include "build.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
|
2007-04-21 12:25:17 +00:00
|
|
|
ProjectPrefs project_prefs = {NULL};
|
|
|
|
|
2007-04-29 16:36:42 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
gchar *project_file_path;
|
|
|
|
} local_prefs = {NULL};
|
|
|
|
|
2007-04-21 12:25:17 +00:00
|
|
|
|
2007-01-18 18:48:43 +00:00
|
|
|
static gboolean entries_modified;
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
// simple struct to keep references to the elements of the properties dialog
|
2007-01-21 17:43:52 +00:00
|
|
|
typedef struct _PropertyDialogElements
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *name;
|
|
|
|
GtkWidget *description;
|
|
|
|
GtkWidget *file_name;
|
|
|
|
GtkWidget *base_path;
|
2007-03-05 12:13:09 +00:00
|
|
|
GtkWidget *run_cmd;
|
2007-01-17 23:44:08 +00:00
|
|
|
GtkWidget *patterns;
|
|
|
|
} PropertyDialogElements;
|
|
|
|
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
static gboolean update_config(const PropertyDialogElements *e);
|
2007-03-05 12:13:09 +00:00
|
|
|
static void on_file_save_button_clicked(GtkButton *button, GtkWidget *entry);
|
|
|
|
static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry);
|
2007-01-15 18:12:32 +00:00
|
|
|
static gboolean close_open_project();
|
2007-01-18 22:13:50 +00:00
|
|
|
static gboolean load_config(const gchar *filename);
|
2007-01-21 17:43:52 +00:00
|
|
|
static gboolean write_config();
|
2007-01-17 23:44:08 +00:00
|
|
|
static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
|
2007-01-18 18:48:43 +00:00
|
|
|
static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e);
|
2007-01-15 18:12:32 +00:00
|
|
|
|
|
|
|
|
2007-03-01 12:38:31 +00:00
|
|
|
// avoid using __VA_ARGS__ because older gcc 2.x versions probably don't support C99
|
|
|
|
#define SHOW_ERR(args...) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args)
|
2007-01-18 22:13:50 +00:00
|
|
|
#define MAX_NAME_LEN 50
|
2007-04-29 16:36:42 +00:00
|
|
|
// "projects" is part of the default project base path so be careful when translating
|
2007-01-21 17:43:52 +00:00
|
|
|
// please avoid special characters and spaces, look at the source for details or ask Frank
|
|
|
|
#define PROJECT_DIR _("projects")
|
2007-01-18 22:13:50 +00:00
|
|
|
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
void project_new()
|
|
|
|
{
|
2007-03-10 12:27:55 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *label;
|
2007-03-14 12:47:32 +00:00
|
|
|
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
2007-03-10 12:27:55 +00:00
|
|
|
PropertyDialogElements *e;
|
2007-03-21 11:54:35 +00:00
|
|
|
gint response;
|
2007-03-10 12:27:55 +00:00
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
if (! close_open_project()) return;
|
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
g_return_if_fail(app->project == NULL);
|
|
|
|
|
|
|
|
e = g_new0(PropertyDialogElements, 1);
|
|
|
|
e->dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(app->window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
|
|
|
|
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(e->dialog, "GeanyDialogProject");
|
2007-03-10 12:27:55 +00:00
|
|
|
bbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
button = gtk_button_new();
|
|
|
|
image = gtk_image_new_from_stock("gtk-new", GTK_ICON_SIZE_BUTTON);
|
|
|
|
label = gtk_label_new_with_mnemonic(_("C_reate"));
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 3);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(button), bbox);
|
|
|
|
gtk_dialog_add_action_widget(GTK_DIALOG(e->dialog), button, GTK_RESPONSE_OK);
|
|
|
|
|
|
|
|
vbox = ui_dialog_vbox_new(GTK_DIALOG(e->dialog));
|
|
|
|
|
|
|
|
entries_modified = FALSE;
|
|
|
|
|
|
|
|
table = gtk_table_new(3, 2, FALSE);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
|
|
|
|
|
|
|
|
label = gtk_label_new(_("Name:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->name = gtk_entry_new();
|
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
|
2007-07-13 15:54:16 +00:00
|
|
|
|
|
|
|
ui_table_add_row(GTK_TABLE(table), 0, label, e->name, NULL);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
label = gtk_label_new(_("Filename:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->file_name = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(e->file_name), 30);
|
|
|
|
button = gtk_button_new();
|
|
|
|
g_signal_connect((gpointer) button, "clicked",
|
|
|
|
G_CALLBACK(on_file_save_button_clicked), e->file_name);
|
|
|
|
image = gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_container_add(GTK_CONTAINER(button), image);
|
|
|
|
bbox = gtk_hbox_new(FALSE, 6);
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(bbox), e->file_name);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
2007-07-13 15:54:16 +00:00
|
|
|
|
|
|
|
ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
label = gtk_label_new(_("Base path:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->base_path = gtk_entry_new();
|
2007-03-14 12:47:32 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, e->base_path,
|
|
|
|
_("Base directory of all files that make up the project. "
|
|
|
|
"This can be a new path, or an existing directory tree."), NULL);
|
2007-05-11 16:34:18 +00:00
|
|
|
bbox = ui_path_box_new(_("Choose Project Base Path"),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
|
2007-07-13 15:54:16 +00:00
|
|
|
|
|
|
|
ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), table);
|
|
|
|
|
|
|
|
// signals
|
|
|
|
g_signal_connect((gpointer) e->name, "changed", G_CALLBACK(on_name_entry_changed), e);
|
|
|
|
// run the callback manually to initialise the base_path and file_name fields
|
|
|
|
on_name_entry_changed(GTK_EDITABLE(e->name), e);
|
|
|
|
|
|
|
|
g_signal_connect((gpointer) e->file_name, "changed", G_CALLBACK(on_entries_changed), e);
|
|
|
|
g_signal_connect((gpointer) e->base_path, "changed", G_CALLBACK(on_entries_changed), e);
|
|
|
|
|
|
|
|
gtk_widget_show_all(e->dialog);
|
2007-04-21 16:27:38 +00:00
|
|
|
|
|
|
|
retry:
|
2007-03-21 11:54:35 +00:00
|
|
|
response = gtk_dialog_run(GTK_DIALOG(e->dialog));
|
2007-04-21 16:27:38 +00:00
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
if (! update_config(e))
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
gtk_widget_destroy(e->dialog);
|
|
|
|
g_free(e);
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
static void run_open_dialog(GtkDialog *dialog)
|
|
|
|
{
|
|
|
|
gint response;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
response = gtk_dialog_run(dialog);
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
|
|
|
|
|
|
// try to load the config
|
|
|
|
if (! project_load_file(filename))
|
|
|
|
{
|
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(filename);
|
|
|
|
|
|
|
|
SHOW_ERR(_("Project file \"%s\" could not be loaded."), utf8_filename);
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(dialog));
|
|
|
|
g_free(utf8_filename);
|
|
|
|
g_free(filename);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
g_free(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
void project_open()
|
|
|
|
{
|
2007-04-29 16:36:42 +00:00
|
|
|
const gchar *dir = local_prefs.project_file_path;
|
2007-02-19 18:58:32 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gchar *file;
|
|
|
|
#else
|
2007-01-18 22:13:50 +00:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
#endif
|
2007-01-15 18:12:32 +00:00
|
|
|
if (! close_open_project()) return;
|
|
|
|
|
2007-01-18 22:13:50 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2007-03-10 12:27:55 +00:00
|
|
|
file = win32_show_project_open_dialog(_("Open Project"), dir, FALSE);
|
2007-02-19 18:58:32 +00:00
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
load_config(file);
|
|
|
|
g_free(file);
|
|
|
|
}
|
2007-01-18 22:13:50 +00:00
|
|
|
#else
|
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(app->window),
|
2007-01-18 22:13:50 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialogProject");
|
2007-01-15 18:12:32 +00:00
|
|
|
|
2007-01-18 22:13:50 +00:00
|
|
|
// set default Open, so pressing enter can open multiple files
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(app->window));
|
|
|
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
|
|
|
|
|
|
|
|
// add FileFilters
|
|
|
|
filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter, _("All files"));
|
|
|
|
gtk_file_filter_add_pattern(filter, "*");
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter, _("Project files"));
|
|
|
|
gtk_file_filter_add_pattern(filter, "*." GEANY_PROJECT_EXT);
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
|
2007-01-21 17:43:52 +00:00
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
|
|
|
|
|
2007-01-18 22:13:50 +00:00
|
|
|
gtk_widget_show_all(dialog);
|
2007-04-21 16:27:38 +00:00
|
|
|
run_open_dialog(GTK_DIALOG(dialog));
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
2007-01-18 22:13:50 +00:00
|
|
|
#endif
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-28 15:24:21 +00:00
|
|
|
// Called when opening, closing and updating projects.
|
|
|
|
static void update_ui()
|
|
|
|
{
|
|
|
|
ui_set_window_title(-1);
|
|
|
|
build_menu_update(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
void project_close()
|
|
|
|
{
|
|
|
|
g_return_if_fail(app->project != NULL);
|
|
|
|
|
2007-01-21 17:43:52 +00:00
|
|
|
/// TODO handle open project files
|
|
|
|
|
|
|
|
write_config();
|
|
|
|
msgwin_status_add(_("Project \"%s\" closed."), app->project->name);
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
g_free(app->project->name);
|
|
|
|
g_free(app->project->description);
|
|
|
|
g_free(app->project->file_name);
|
|
|
|
g_free(app->project->base_path);
|
2007-03-05 12:13:09 +00:00
|
|
|
g_free(app->project->run_cmd);
|
2007-01-15 18:12:32 +00:00
|
|
|
|
|
|
|
g_free(app->project);
|
|
|
|
app->project = NULL;
|
2007-05-01 12:27:56 +00:00
|
|
|
|
2007-05-28 15:24:21 +00:00
|
|
|
update_ui();
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void project_properties()
|
|
|
|
{
|
2007-01-17 23:44:08 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *swin;
|
2007-03-05 12:13:09 +00:00
|
|
|
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
2007-01-17 23:44:08 +00:00
|
|
|
PropertyDialogElements *e = g_new(PropertyDialogElements, 1);
|
2007-03-10 12:27:55 +00:00
|
|
|
GeanyProject *p = app->project;
|
2007-03-21 11:54:35 +00:00
|
|
|
gint response;
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail(app->project != NULL);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
e->dialog = gtk_dialog_new_with_buttons(_("Project Properties"), GTK_WINDOW(app->window),
|
2007-01-21 19:10:40 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_dialog_add_buttons(GTK_DIALOG(e->dialog), GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(e->dialog, "GeanyDialogProject");
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
vbox = ui_dialog_vbox_new(GTK_DIALOG(e->dialog));
|
|
|
|
|
2007-01-18 18:48:43 +00:00
|
|
|
entries_modified = FALSE;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
table = gtk_table_new(6, 2, FALSE);
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
|
|
|
|
|
|
|
|
label = gtk_label_new(_("Name:"));
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
|
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->name = gtk_entry_new();
|
2007-01-21 17:43:52 +00:00
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), e->name, 1, 2, 0, 1,
|
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
label = gtk_label_new(_("Filename:"));
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
|
2007-03-10 12:27:55 +00:00
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->file_name = gtk_entry_new();
|
|
|
|
gtk_editable_set_editable(GTK_EDITABLE(e->file_name), FALSE); // read-only
|
|
|
|
gtk_table_attach(GTK_TABLE(table), e->file_name, 1, 2, 1, 2,
|
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
|
|
|
|
label = gtk_label_new(_("Description:"));
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
|
2007-01-17 23:44:08 +00:00
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (GTK_FILL), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->description = gtk_text_view_new();
|
2007-01-21 17:43:52 +00:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(e->description), GTK_WRAP_WORD);
|
2007-01-17 23:44:08 +00:00
|
|
|
swin = gtk_scrolled_window_new(NULL, NULL);
|
2007-01-21 17:43:52 +00:00
|
|
|
gtk_widget_set_size_request(swin, 250, 80);
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), GTK_WIDGET(e->description));
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), swin, 1, 2, 2, 3,
|
2007-01-17 23:44:08 +00:00
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
|
|
|
|
label = gtk_label_new(_("Base path:"));
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4,
|
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->base_path = gtk_entry_new();
|
2007-05-01 15:48:53 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, e->base_path,
|
|
|
|
_("Directory to run Make All from. "
|
|
|
|
"Leave blank to use the default command."), NULL);
|
2007-05-11 16:34:18 +00:00
|
|
|
bbox = ui_path_box_new(_("Choose Project Base Path"),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 3, 4,
|
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
label = gtk_label_new(_("Run command:"));
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5,
|
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->run_cmd = gtk_entry_new();
|
|
|
|
gtk_tooltips_set_tip(tooltips, e->run_cmd,
|
|
|
|
_("Command-line to run in the project base directory. "
|
|
|
|
"Options can be appended to the command. "
|
|
|
|
"Leave blank to use the default run command."), NULL);
|
|
|
|
button = gtk_button_new();
|
|
|
|
g_signal_connect((gpointer) button, "clicked",
|
|
|
|
G_CALLBACK(on_file_open_button_clicked), e->run_cmd);
|
|
|
|
image = gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_container_add(GTK_CONTAINER(button), image);
|
|
|
|
bbox = gtk_hbox_new(FALSE, 6);
|
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(bbox), e->run_cmd);
|
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 4, 5,
|
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
|
|
|
|
2007-05-01 11:47:06 +00:00
|
|
|
#if 0
|
2007-01-17 23:44:08 +00:00
|
|
|
label = gtk_label_new(_("File patterns:"));
|
|
|
|
// <small>Separate multiple patterns by a new line</small>
|
2007-03-05 12:13:09 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6,
|
2007-01-17 23:44:08 +00:00
|
|
|
(GtkAttachOptions) (GTK_FILL),
|
|
|
|
(GtkAttachOptions) (GTK_FILL), 0, 0);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
|
|
|
|
|
|
|
|
e->patterns = gtk_text_view_new();
|
|
|
|
swin = gtk_scrolled_window_new(NULL, NULL);
|
2007-01-21 17:43:52 +00:00
|
|
|
gtk_widget_set_size_request(swin, -1, 80);
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), GTK_WIDGET(e->patterns));
|
2007-03-05 12:13:09 +00:00
|
|
|
gtk_table_attach(GTK_TABLE(table), swin, 1, 2, 5, 6,
|
2007-01-17 23:44:08 +00:00
|
|
|
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
|
(GtkAttachOptions) (0), 0, 0);
|
2007-05-01 11:47:06 +00:00
|
|
|
#endif
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), table);
|
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
// fill the elements with the appropriate data
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->name), p->name);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
if (p->description != NULL)
|
|
|
|
{ // set text
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
|
|
|
|
gtk_text_buffer_set_text(buffer, p->description, -1);
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-05-01 11:47:06 +00:00
|
|
|
#if 0
|
2007-03-10 12:27:55 +00:00
|
|
|
if (p->file_patterns != NULL)
|
|
|
|
{ // set the file patterns
|
|
|
|
gint i;
|
|
|
|
gint len = g_strv_length(p->file_patterns);
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->patterns));
|
|
|
|
GString *str = g_string_sized_new(len * 4);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (p->file_patterns[i] != NULL)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-03-10 12:27:55 +00:00
|
|
|
g_string_append(str, p->file_patterns[i]);
|
|
|
|
g_string_append_c(str, '\n');
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_text_buffer_set_text(buffer, str->str, -1);
|
|
|
|
g_string_free(str, TRUE);
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
2007-05-01 11:47:06 +00:00
|
|
|
#endif
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->file_name), p->file_name);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->base_path), p->base_path);
|
|
|
|
if (p->run_cmd != NULL)
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->run_cmd), p->run_cmd);
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_widget_show_all(e->dialog);
|
2007-04-21 16:27:38 +00:00
|
|
|
|
|
|
|
retry:
|
2007-03-21 11:54:35 +00:00
|
|
|
response = gtk_dialog_run(GTK_DIALOG(e->dialog));
|
2007-04-21 16:27:38 +00:00
|
|
|
if (response == GTK_RESPONSE_OK)
|
2007-05-01 12:27:56 +00:00
|
|
|
{
|
2007-04-21 16:27:38 +00:00
|
|
|
if (! update_config(e))
|
|
|
|
goto retry;
|
2007-05-01 12:27:56 +00:00
|
|
|
// successfully updated properties
|
2007-05-28 15:24:21 +00:00
|
|
|
update_ui();
|
2007-05-01 12:27:56 +00:00
|
|
|
}
|
2007-04-21 16:27:38 +00:00
|
|
|
|
|
|
|
gtk_widget_destroy(e->dialog);
|
|
|
|
g_free(e);
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
/* checks whether there is an already open project and asks the user if he wants to close it or
|
2007-01-15 18:12:32 +00:00
|
|
|
* abort the current action. Returns FALSE when the current action(the caller) should be cancelled
|
|
|
|
* and TRUE if we can go ahead */
|
|
|
|
static gboolean close_open_project()
|
|
|
|
{
|
|
|
|
if (app->project != NULL)
|
|
|
|
{
|
2007-07-04 17:08:53 +00:00
|
|
|
if (dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
|
2007-05-01 15:48:53 +00:00
|
|
|
_("Do you want to close it before proceeding?"),
|
|
|
|
_("The '%s' project is already open. "), app->project->name))
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
|
|
|
project_close();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
/* Verifies data for New & Properties dialogs.
|
|
|
|
* Returns: FALSE if the user needs to change any data. */
|
|
|
|
static gboolean update_config(const PropertyDialogElements *e)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-04-21 16:27:38 +00:00
|
|
|
const gchar *name, *file_name, *base_path;
|
|
|
|
gint name_len;
|
|
|
|
gboolean new_project = FALSE;
|
|
|
|
GeanyProject *p;
|
|
|
|
|
|
|
|
g_return_val_if_fail(e != NULL, TRUE);
|
|
|
|
|
|
|
|
name = gtk_entry_get_text(GTK_ENTRY(e->name));
|
|
|
|
name_len = strlen(name);
|
|
|
|
if (name_len == 0)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-04-21 16:27:38 +00:00
|
|
|
SHOW_ERR(_("The specified project name is too short."));
|
|
|
|
gtk_widget_grab_focus(e->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (name_len > MAX_NAME_LEN)
|
|
|
|
{
|
|
|
|
SHOW_ERR(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
|
|
|
|
gtk_widget_grab_focus(e->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
|
|
|
|
if (strlen(file_name) == 0)
|
|
|
|
{
|
|
|
|
SHOW_ERR(_("You have specified an invalid project filename."));
|
|
|
|
gtk_widget_grab_focus(e->file_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
|
2007-05-01 15:48:53 +00:00
|
|
|
if (NZV(base_path))
|
2007-04-21 16:27:38 +00:00
|
|
|
{ // check whether the given directory actually exists
|
|
|
|
gchar *locale_path = utils_get_locale_from_utf8(base_path);
|
|
|
|
if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-07-04 17:08:53 +00:00
|
|
|
if (dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
|
2007-05-01 15:48:53 +00:00
|
|
|
_("Create the project's base path directory?"),
|
|
|
|
_("The path \"%s\" does not exist."),
|
|
|
|
base_path))
|
2007-04-21 16:27:38 +00:00
|
|
|
{
|
|
|
|
utils_mkdir(locale_path, TRUE);
|
|
|
|
}
|
|
|
|
else
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-04-21 16:27:38 +00:00
|
|
|
g_free(locale_path);
|
|
|
|
gtk_widget_grab_focus(e->base_path);
|
|
|
|
return FALSE;
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-21 16:27:38 +00:00
|
|
|
g_free(locale_path);
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
// finally test whether the given project file can be written
|
|
|
|
if (utils_write_file(file_name, "") != 0)
|
|
|
|
{
|
|
|
|
SHOW_ERR(_("Project file could not be written."));
|
|
|
|
gtk_widget_grab_focus(e->file_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (app->project == NULL)
|
|
|
|
{
|
|
|
|
app->project = g_new0(GeanyProject, 1);
|
|
|
|
new_project = TRUE;
|
|
|
|
}
|
|
|
|
p = app->project;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (p->name != NULL) g_free(p->name);
|
|
|
|
p->name = g_strdup(name);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (p->file_name != NULL) g_free(p->file_name);
|
|
|
|
p->file_name = g_strdup(file_name);
|
2007-01-21 17:43:52 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (p->base_path != NULL) g_free(p->base_path);
|
|
|
|
p->base_path = g_strdup(base_path);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (! new_project) // save properties specific fields
|
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
2007-05-01 11:47:06 +00:00
|
|
|
//gchar *tmp;
|
2007-04-21 16:27:38 +00:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
|
|
|
if (p->run_cmd != NULL) g_free(p->run_cmd);
|
|
|
|
p->run_cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->run_cmd)));
|
|
|
|
|
|
|
|
// get and set the project description
|
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description));
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
g_free(p->description);
|
|
|
|
p->description = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
|
|
|
|
|
2007-05-01 11:47:06 +00:00
|
|
|
#if 0
|
2007-04-21 16:27:38 +00:00
|
|
|
// get and set the project file patterns
|
|
|
|
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->patterns));
|
|
|
|
gtk_text_buffer_get_start_iter(buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter(buffer, &end);
|
|
|
|
tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
|
|
|
|
g_strfreev(p->file_patterns);
|
|
|
|
p->file_patterns = g_strsplit(tmp, "\n", -1);
|
|
|
|
g_free(tmp);
|
2007-05-01 11:47:06 +00:00
|
|
|
#endif
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
2007-04-21 16:27:38 +00:00
|
|
|
write_config();
|
|
|
|
if (new_project)
|
|
|
|
msgwin_status_add(_("Project \"%s\" created."), p->name);
|
|
|
|
else
|
|
|
|
msgwin_status_add(_("Project \"%s\" saved."), p->name);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
return TRUE;
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-19 18:58:32 +00:00
|
|
|
#ifndef G_OS_WIN32
|
2007-01-18 22:13:50 +00:00
|
|
|
static void run_dialog(GtkWidget *dialog, GtkWidget *entry)
|
|
|
|
{
|
2007-02-19 18:58:32 +00:00
|
|
|
// set filename in the file chooser dialog
|
2007-03-05 12:13:09 +00:00
|
|
|
const gchar *utf8_filename = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
|
|
gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
|
2007-01-18 22:13:50 +00:00
|
|
|
|
|
|
|
if (g_path_is_absolute(locale_filename))
|
2007-03-10 17:26:03 +00:00
|
|
|
{
|
|
|
|
if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
|
|
|
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
|
|
|
|
}
|
2007-01-18 22:13:50 +00:00
|
|
|
else
|
2007-03-05 12:13:09 +00:00
|
|
|
if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
|
2007-03-10 17:26:03 +00:00
|
|
|
{
|
2007-03-05 12:13:09 +00:00
|
|
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), utf8_filename);
|
2007-03-10 17:26:03 +00:00
|
|
|
}
|
2007-01-18 22:13:50 +00:00
|
|
|
g_free(locale_filename);
|
|
|
|
|
|
|
|
// run it
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
2007-03-09 13:52:26 +00:00
|
|
|
gchar *tmp_utf8_filename = utils_get_utf8_from_locale(filename);
|
2007-01-18 22:13:50 +00:00
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), tmp_utf8_filename);
|
2007-01-18 22:13:50 +00:00
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
g_free(tmp_utf8_filename);
|
2007-01-18 22:13:50 +00:00
|
|
|
g_free(filename);
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
2007-02-19 18:58:32 +00:00
|
|
|
#endif
|
2007-01-18 22:13:50 +00:00
|
|
|
|
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
static void on_file_save_button_clicked(GtkButton *button, GtkWidget *entry)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2007-03-10 12:27:55 +00:00
|
|
|
gchar *path = win32_show_project_open_dialog(_("Choose Project Filename"),
|
2007-02-19 18:58:32 +00:00
|
|
|
gtk_entry_get_text(GTK_ENTRY(entry)), TRUE);
|
|
|
|
if (path != NULL)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
#else
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
// initialise the dialog
|
2007-03-10 12:27:55 +00:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Choose Project Filename"), NULL,
|
2007-01-17 23:44:08 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2007-03-05 12:13:09 +00:00
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialogProject");
|
2007-01-17 23:44:08 +00:00
|
|
|
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
2007-01-18 22:13:50 +00:00
|
|
|
run_dialog(dialog, entry);
|
2007-01-17 23:44:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
static void on_file_open_button_clicked(GtkButton *button, GtkWidget *entry)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2007-03-10 12:27:55 +00:00
|
|
|
gchar *path = win32_show_project_open_dialog(_("Choose Project Run Command"),
|
2007-03-05 12:13:09 +00:00
|
|
|
gtk_entry_get_text(GTK_ENTRY(entry)), FALSE);
|
|
|
|
if (path != NULL)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), path);
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
// initialise the dialog
|
2007-03-10 12:27:55 +00:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Choose Project Run Command"), NULL,
|
2007-03-05 12:13:09 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialog");
|
2007-03-05 12:13:09 +00:00
|
|
|
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
|
|
|
|
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
run_dialog(dialog, entry);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
/* sets the project base path and the project file name according to the project name */
|
|
|
|
static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
|
|
|
|
{
|
|
|
|
gchar *base_path;
|
|
|
|
gchar *file_name;
|
|
|
|
gchar *name;
|
2007-04-29 16:36:42 +00:00
|
|
|
const gchar *project_dir = local_prefs.project_file_path;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-01-18 18:48:43 +00:00
|
|
|
if (entries_modified)
|
|
|
|
return;
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
name = gtk_editable_get_chars(editable, 0, -1);
|
|
|
|
if (name != NULL && strlen(name) > 0)
|
|
|
|
{
|
2007-04-29 16:36:42 +00:00
|
|
|
base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
|
2007-01-17 23:44:08 +00:00
|
|
|
name, G_DIR_SEPARATOR_S, NULL);
|
2007-04-29 16:36:42 +00:00
|
|
|
file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
|
2007-03-14 12:36:59 +00:00
|
|
|
name, "." GEANY_PROJECT_EXT, NULL);
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-29 16:36:42 +00:00
|
|
|
base_path = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
|
|
|
|
file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, NULL);
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
2007-04-29 16:36:42 +00:00
|
|
|
g_free(name);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->base_path), base_path);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->file_name), file_name);
|
|
|
|
|
2007-01-18 18:48:43 +00:00
|
|
|
entries_modified = FALSE;
|
|
|
|
|
2007-01-17 23:44:08 +00:00
|
|
|
g_free(base_path);
|
|
|
|
g_free(file_name);
|
|
|
|
}
|
2007-01-18 18:48:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e)
|
|
|
|
{
|
|
|
|
entries_modified = TRUE;
|
|
|
|
}
|
2007-01-18 22:13:50 +00:00
|
|
|
|
|
|
|
|
2007-04-21 12:25:17 +00:00
|
|
|
gboolean project_load_file(const gchar *locale_file_name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(locale_file_name != NULL, FALSE);
|
|
|
|
|
|
|
|
if (load_config(locale_file_name))
|
|
|
|
{
|
|
|
|
msgwin_status_add(_("Project \"%s\" opened."), app->project->name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
|
|
|
|
|
|
|
|
msgwin_status_add(_("Project file \"%s\" could not be loaded."), utf8_filename);
|
|
|
|
g_free(utf8_filename);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-21 17:43:52 +00:00
|
|
|
/* Reads the given filename and creates a new project with the data found in the file.
|
|
|
|
* At this point there should not be an already opened project in Geany otherwise it will just
|
|
|
|
* return.
|
|
|
|
* The filename is expected in the locale encoding. */
|
2007-01-18 22:13:50 +00:00
|
|
|
static gboolean load_config(const gchar *filename)
|
|
|
|
{
|
2007-01-21 17:43:52 +00:00
|
|
|
GKeyFile *config;
|
|
|
|
GeanyProject *p;
|
|
|
|
|
|
|
|
// there should not be an open project
|
|
|
|
g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
|
|
|
|
|
|
|
|
config = g_key_file_new();
|
|
|
|
if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_KEEP_COMMENTS, NULL))
|
|
|
|
{
|
|
|
|
g_key_file_free(config);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-21 12:25:17 +00:00
|
|
|
p = app->project = g_new0(GeanyProject, 1);
|
|
|
|
|
2007-01-21 17:43:52 +00:00
|
|
|
p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
|
|
|
|
p->description = utils_get_setting_string(config, "project", "description", "");
|
|
|
|
p->file_name = utils_get_utf8_from_locale(filename);
|
|
|
|
p->base_path = utils_get_setting_string(config, "project", "base_path", "");
|
2007-03-05 12:13:09 +00:00
|
|
|
p->run_cmd = utils_get_setting_string(config, "project", "run_cmd", "");
|
2007-01-21 17:43:52 +00:00
|
|
|
p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
|
|
|
|
|
|
|
|
g_key_file_free(config);
|
|
|
|
|
2007-05-28 15:24:21 +00:00
|
|
|
update_ui();
|
2007-01-21 17:43:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
// Returns: TRUE if project file was written successfully.
|
2007-01-21 17:43:52 +00:00
|
|
|
static gboolean write_config()
|
|
|
|
{
|
|
|
|
GeanyProject *p;
|
|
|
|
GKeyFile *config;
|
|
|
|
gchar *filename;
|
|
|
|
gchar *data;
|
2007-03-05 12:13:09 +00:00
|
|
|
gboolean ret = FALSE;
|
2007-01-21 17:43:52 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(app->project != NULL, FALSE);
|
|
|
|
|
|
|
|
p = app->project;
|
|
|
|
|
|
|
|
config = g_key_file_new();
|
|
|
|
// try to load an existing config to keep manually added comments
|
|
|
|
filename = utils_get_locale_from_utf8(p->file_name);
|
|
|
|
g_key_file_load_from_file(config, filename, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
|
|
|
|
|
|
|
g_key_file_set_string(config, "project", "name", p->name);
|
|
|
|
g_key_file_set_string(config, "project", "base_path", p->base_path);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
if (p->description)
|
|
|
|
g_key_file_set_string(config, "project", "description", p->description);
|
|
|
|
if (p->run_cmd)
|
|
|
|
g_key_file_set_string(config, "project", "run_cmd", p->run_cmd);
|
|
|
|
if (p->file_patterns)
|
|
|
|
g_key_file_set_string_list(config, "project", "file_patterns",
|
|
|
|
(const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
|
2007-01-21 17:43:52 +00:00
|
|
|
|
|
|
|
// write the file
|
|
|
|
data = g_key_file_to_data(config, NULL, NULL);
|
2007-03-05 12:13:09 +00:00
|
|
|
ret = (utils_write_file(filename, data) == 0);
|
2007-01-21 17:43:52 +00:00
|
|
|
|
|
|
|
g_free(data);
|
|
|
|
g_free(filename);
|
|
|
|
g_key_file_free(config);
|
|
|
|
|
2007-03-05 12:13:09 +00:00
|
|
|
return ret;
|
2007-01-18 22:13:50 +00:00
|
|
|
}
|
2007-03-01 11:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
const gchar *project_get_make_dir()
|
|
|
|
{
|
2007-05-01 15:48:53 +00:00
|
|
|
if (app->project != NULL && NZV(app->project->base_path))
|
2007-03-01 11:38:14 +00:00
|
|
|
return app->project->base_path;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
|
2007-04-21 12:25:17 +00:00
|
|
|
void project_save_prefs(GKeyFile *config)
|
|
|
|
{
|
|
|
|
GeanyProject *project = app->project;
|
|
|
|
|
|
|
|
if (cl_options.load_session)
|
|
|
|
{
|
|
|
|
gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
|
|
|
|
|
|
|
|
g_key_file_set_string(config, "project", "session_file", utf8_filename);
|
|
|
|
}
|
2007-04-29 16:36:42 +00:00
|
|
|
g_key_file_set_string(config, "project", "project_file_path",
|
|
|
|
NVL(local_prefs.project_file_path, ""));
|
2007-04-21 12:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void project_load_prefs(GKeyFile *config)
|
|
|
|
{
|
|
|
|
if (cl_options.load_session)
|
|
|
|
{
|
|
|
|
g_return_if_fail(project_prefs.session_file == NULL);
|
|
|
|
project_prefs.session_file = utils_get_setting_string(config, "project",
|
|
|
|
"session_file", "");
|
|
|
|
}
|
2007-04-29 16:36:42 +00:00
|
|
|
local_prefs.project_file_path = utils_get_setting_string(config, "project",
|
|
|
|
"project_file_path", NULL);
|
|
|
|
if (local_prefs.project_file_path == NULL)
|
|
|
|
{
|
|
|
|
local_prefs.project_file_path = g_strconcat(GEANY_HOME_DIR,
|
|
|
|
G_DIR_SEPARATOR_S, PROJECT_DIR, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize project-related preferences in the Preferences dialog. */
|
|
|
|
void project_setup_prefs()
|
|
|
|
{
|
|
|
|
GtkWidget *path_entry = lookup_widget(app->prefs_dialog, "project_file_path_entry");
|
|
|
|
GtkWidget *path_btn = lookup_widget(app->prefs_dialog, "project_file_path_button");
|
|
|
|
|
|
|
|
g_return_if_fail(local_prefs.project_file_path != NULL);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
|
2007-05-11 16:34:18 +00:00
|
|
|
ui_setup_open_button_callback(path_btn, NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(path_entry));
|
2007-04-29 16:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Update project-related preferences after using the Preferences dialog. */
|
|
|
|
void project_apply_prefs()
|
|
|
|
{
|
|
|
|
GtkWidget *path_entry = lookup_widget(app->prefs_dialog, "project_file_path_entry");
|
|
|
|
const gchar *str;
|
|
|
|
|
|
|
|
str = gtk_entry_get_text(GTK_ENTRY(path_entry));
|
|
|
|
g_free(local_prefs.project_file_path);
|
|
|
|
local_prefs.project_file_path = g_strdup(str);
|
2007-04-21 12:25:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 16:36:42 +00:00
|
|
|
|