2007-01-15 18:12:32 +00:00
|
|
|
/*
|
|
|
|
* project.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2012-06-18 01:13:05 +02:00
|
|
|
* Copyright 2007-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2007-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2007-01-15 18:12:32 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2012-08-24 19:25:57 +02:00
|
|
|
* 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.
|
2007-01-15 18:12:32 +00:00
|
|
|
*/
|
|
|
|
|
2008-07-24 14:37:36 +00:00
|
|
|
/** @file project.h
|
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-10-28 17:02:36 +00:00
|
|
|
#include <unistd.h>
|
2011-02-06 16:32:49 +00:00
|
|
|
#include <errno.h>
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
#include "project.h"
|
2008-12-27 12:55:04 +00:00
|
|
|
#include "projectprivate.h"
|
|
|
|
|
2007-01-15 18:12:32 +00:00
|
|
|
#include "dialogs.h"
|
|
|
|
#include "support.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "ui_utils.h"
|
2008-06-12 20:09:57 +00:00
|
|
|
#include "document.h"
|
2007-01-21 17:43:52 +00:00
|
|
|
#include "msgwindow.h"
|
2007-04-21 12:25:17 +00:00
|
|
|
#include "main.h"
|
2007-11-11 19:06:41 +00:00
|
|
|
#include "keyfile.h"
|
2010-05-16 17:42:58 +00:00
|
|
|
#include "win32.h"
|
2007-05-01 12:27:56 +00:00
|
|
|
#include "build.h"
|
2008-12-27 12:55:04 +00:00
|
|
|
#include "editor.h"
|
|
|
|
#include "stash.h"
|
2009-09-28 11:16:59 +00:00
|
|
|
#include "sidebar.h"
|
2014-05-18 15:49:22 -07:00
|
|
|
#include "filetypesprivate.h"
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
|
2008-10-02 15:09:33 +00:00
|
|
|
ProjectPrefs project_prefs = { NULL, FALSE, FALSE };
|
2007-04-21 12:25:17 +00:00
|
|
|
|
2008-12-27 12:55:04 +00:00
|
|
|
|
|
|
|
static GeanyProjectPrivate priv;
|
|
|
|
static GeanyIndentPrefs indentation;
|
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
static GSList *stash_groups = NULL;
|
2008-12-27 12:55:04 +00:00
|
|
|
|
2007-04-29 16:36:42 +00:00
|
|
|
static struct
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
gchar *project_file_path; /* in UTF-8 */
|
2009-09-06 16:50:20 +00:00
|
|
|
} local_prefs = { NULL };
|
2007-04-29 16:36:42 +00:00
|
|
|
|
2007-01-18 18:48:43 +00:00
|
|
|
static gboolean entries_modified;
|
|
|
|
|
2008-02-27 13:17:29 +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;
|
2010-07-07 12:04:28 +00:00
|
|
|
GtkWidget *notebook;
|
2007-01-17 23:44:08 +00:00
|
|
|
GtkWidget *name;
|
|
|
|
GtkWidget *description;
|
|
|
|
GtkWidget *file_name;
|
|
|
|
GtkWidget *base_path;
|
|
|
|
GtkWidget *patterns;
|
2010-07-07 12:04:28 +00:00
|
|
|
BuildTableData build_properties;
|
2011-12-27 23:12:10 -08:00
|
|
|
gint build_page_num;
|
2007-01-17 23:44:08 +00:00
|
|
|
} PropertyDialogElements;
|
|
|
|
|
|
|
|
|
2011-02-06 16:32:49 +00:00
|
|
|
static gboolean update_config(const PropertyDialogElements *e, gboolean new_project);
|
2007-12-07 16:31:38 +00:00
|
|
|
static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
|
2007-01-18 22:13:50 +00:00
|
|
|
static gboolean load_config(const gchar *filename);
|
2008-01-25 13:09:14 +00:00
|
|
|
static gboolean write_config(gboolean emit_signal);
|
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);
|
2010-03-10 16:20:34 +00:00
|
|
|
static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line);
|
2010-04-25 17:43:39 +00:00
|
|
|
static void apply_editor_prefs(void);
|
2012-01-19 18:09:29 +00:00
|
|
|
static void init_stash_prefs(void);
|
2007-01-15 18:12:32 +00:00
|
|
|
|
|
|
|
|
2007-10-19 14:48:19 +00:00
|
|
|
#define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args)
|
2009-09-16 14:13:38 +00:00
|
|
|
#define SHOW_ERR1(args, more) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args, more)
|
2007-01-18 22:13:50 +00:00
|
|
|
#define MAX_NAME_LEN 50
|
2008-02-27 13:17:29 +00:00
|
|
|
/* "projects" is part of the default project base path so be careful when translating
|
|
|
|
* please avoid special characters and spaces, look at the source for details or ask Frank */
|
2007-01-21 17:43:52 +00:00
|
|
|
#define PROJECT_DIR _("projects")
|
2007-01-18 22:13:50 +00:00
|
|
|
|
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
/* TODO: this should be ported to Glade like the project preferences dialog,
|
|
|
|
* then we can get rid of the PropertyDialogElements struct altogether as
|
|
|
|
* widgets pointers can be accessed through ui_lookup_widget(). */
|
2009-04-16 17:55:26 +00:00
|
|
|
void project_new(void)
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
2007-03-10 12:27:55 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
PropertyDialogElements *e;
|
|
|
|
|
2009-09-06 16:50:20 +00:00
|
|
|
if (! project_ask_close())
|
|
|
|
return;
|
2007-01-15 18:12:32 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
g_return_if_fail(app->project == NULL);
|
|
|
|
|
|
|
|
e = g_new0(PropertyDialogElements, 1);
|
2008-05-22 14:41:28 +00:00
|
|
|
e->dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window),
|
2007-03-10 12:27:55 +00:00
|
|
|
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();
|
2013-04-26 14:55:48 -07:00
|
|
|
gtk_widget_set_can_default(button, TRUE);
|
|
|
|
gtk_window_set_default(GTK_WINDOW(e->dialog), button);
|
2011-10-30 22:01:49 +01:00
|
|
|
image = gtk_image_new_from_stock(GTK_STOCK_NEW, GTK_ICON_SIZE_BUTTON);
|
2007-03-10 12:27:55 +00:00
|
|
|
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();
|
2013-04-26 14:55:48 -07:00
|
|
|
gtk_entry_set_activates_default(GTK_ENTRY(e->name), TRUE);
|
2009-09-21 16:46:16 +00:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->name));
|
2007-03-10 12:27:55 +00:00
|
|
|
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();
|
2013-04-26 14:55:48 -07:00
|
|
|
gtk_entry_set_activates_default(GTK_ENTRY(e->file_name), TRUE);
|
2009-09-21 16:46:16 +00:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->file_name));
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(e->file_name), 30);
|
|
|
|
button = gtk_button_new();
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), e);
|
2011-10-30 22:01:49 +01:00
|
|
|
image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(button), image);
|
|
|
|
bbox = gtk_hbox_new(FALSE, 6);
|
2012-09-11 16:37:01 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(bbox), e->file_name, TRUE, TRUE, 0);
|
2007-03-10 12:27:55 +00:00
|
|
|
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();
|
2013-04-26 14:55:48 -07:00
|
|
|
gtk_entry_set_activates_default(GTK_ENTRY(e->base_path), TRUE);
|
2009-09-21 16:46:16 +00:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
|
2011-06-13 18:41:50 +00:00
|
|
|
gtk_widget_set_tooltip_text(e->base_path,
|
2007-03-14 12:47:32 +00:00
|
|
|
_("Base directory of all files that make up the project. "
|
2008-01-09 18:05:09 +00:00
|
|
|
"This can be a new path, or an existing directory tree. "
|
2008-11-18 20:14:42 +00:00
|
|
|
"You can use paths relative to the project filename."));
|
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
|
|
|
|
2012-09-28 03:27:35 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* signals */
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(e->name, "changed", G_CALLBACK(on_name_entry_changed), e);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* run the callback manually to initialise the base_path and file_name fields */
|
2007-03-10 12:27:55 +00:00
|
|
|
on_name_entry_changed(GTK_EDITABLE(e->name), e);
|
|
|
|
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(e->file_name, "changed", G_CALLBACK(on_entries_changed), e);
|
|
|
|
g_signal_connect(e->base_path, "changed", G_CALLBACK(on_entries_changed), e);
|
2007-03-10 12:27:55 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all(e->dialog);
|
2007-04-21 16:27:38 +00:00
|
|
|
|
2010-03-31 13:39:33 +00:00
|
|
|
while (gtk_dialog_run(GTK_DIALOG(e->dialog)) == GTK_RESPONSE_OK)
|
2009-04-27 19:31:06 +00:00
|
|
|
{
|
2011-02-06 16:32:49 +00:00
|
|
|
if (update_config(e, TRUE))
|
2010-03-31 13:39:33 +00:00
|
|
|
{
|
2011-02-06 16:32:49 +00:00
|
|
|
if (!write_config(TRUE))
|
|
|
|
SHOW_ERR(_("Project file could not be written"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name);
|
2010-09-16 15:14:09 +00:00
|
|
|
|
2011-02-06 16:32:49 +00:00
|
|
|
ui_add_recent_project_file(app->project->file_name);
|
|
|
|
break;
|
|
|
|
}
|
2010-03-31 13:39:33 +00:00
|
|
|
}
|
2009-04-27 19:31:06 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
gboolean project_load_file_with_session(const gchar *locale_file_name)
|
|
|
|
{
|
|
|
|
if (project_load_file(locale_file_name))
|
|
|
|
{
|
|
|
|
if (project_prefs.project_session)
|
|
|
|
{
|
|
|
|
configuration_open_files();
|
|
|
|
/* open a new file if no other file was opened */
|
|
|
|
document_new_file_if_non_open();
|
2011-06-02 21:16:43 +00:00
|
|
|
ui_focus_current_document();
|
2009-04-05 14:14:29 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
static void run_open_dialog(GtkDialog *dialog)
|
|
|
|
{
|
2010-03-31 13:39:33 +00:00
|
|
|
while (gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT)
|
2007-04-21 16:27:38 +00:00
|
|
|
{
|
|
|
|
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try to load the config */
|
2009-04-05 14:14:29 +00:00
|
|
|
if (! project_load_file_with_session(filename))
|
2007-04-21 16:27:38 +00:00
|
|
|
{
|
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(filename);
|
|
|
|
|
2007-10-19 14:48:19 +00:00
|
|
|
SHOW_ERR1(_("Project file \"%s\" could not be loaded."), utf8_filename);
|
2007-04-21 16:27:38 +00:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(dialog));
|
|
|
|
g_free(utf8_filename);
|
|
|
|
g_free(filename);
|
2010-03-31 13:39:33 +00:00
|
|
|
continue;
|
2007-04-21 16:27:38 +00:00
|
|
|
}
|
|
|
|
g_free(filename);
|
2010-03-31 13:39:33 +00:00
|
|
|
break;
|
2007-04-21 16:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-04-16 17:55:26 +00:00
|
|
|
void project_open(void)
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
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;
|
2007-10-28 17:02:36 +00:00
|
|
|
gchar *locale_path;
|
2007-01-18 22:13:50 +00:00
|
|
|
#endif
|
2009-04-05 14:14:29 +00:00
|
|
|
if (! project_ask_close()) return;
|
2007-01-15 18:12:32 +00:00
|
|
|
|
2007-01-18 22:13:50 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2008-05-22 14:41:28 +00:00
|
|
|
file = win32_show_project_open_dialog(main_widgets.window, _("Open Project"), dir, FALSE, TRUE);
|
2007-02-19 18:58:32 +00:00
|
|
|
if (file != NULL)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try to load the config */
|
2009-04-06 13:39:33 +00:00
|
|
|
if (! project_load_file_with_session(file))
|
2007-11-11 19:06:41 +00:00
|
|
|
{
|
|
|
|
SHOW_ERR1(_("Project file \"%s\" could not be loaded."), file);
|
|
|
|
}
|
2007-02-19 18:58:32 +00:00
|
|
|
g_free(file);
|
|
|
|
}
|
2007-01-18 22:13:50 +00:00
|
|
|
#else
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Open Project"), GTK_WINDOW(main_widgets.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
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* set default Open, so pressing enter can open multiple files */
|
2007-01-18 22:13:50 +00:00
|
|
|
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);
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
|
2007-01-18 22:13:50 +00:00
|
|
|
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* add FileFilters */
|
2007-01-18 22:13:50 +00:00
|
|
|
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-10-28 17:02:36 +00:00
|
|
|
locale_path = utils_get_locale_from_utf8(dir);
|
|
|
|
if (g_file_test(locale_path, G_FILE_TEST_EXISTS) &&
|
|
|
|
g_file_test(locale_path, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
|
|
|
|
}
|
|
|
|
g_free(locale_path);
|
2007-01-21 17:43:52 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 20:29:27 +00:00
|
|
|
/* Called when creating, opening, closing and updating projects. */
|
2008-02-20 11:24:23 +00:00
|
|
|
static void update_ui(void)
|
2007-05-28 15:24:21 +00:00
|
|
|
{
|
2010-05-16 17:43:24 +00:00
|
|
|
if (main_status.quitting)
|
|
|
|
return;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
ui_set_window_title(NULL);
|
|
|
|
build_menu_update(NULL);
|
2009-09-28 11:16:59 +00:00
|
|
|
sidebar_openfiles_update_all();
|
2007-05-28 15:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-16 14:13:38 +00:00
|
|
|
static void remove_foreach_project_filetype(gpointer data, gpointer user_data)
|
2009-07-09 06:49:42 +00:00
|
|
|
{
|
2010-11-18 16:25:11 +00:00
|
|
|
GeanyFiletype *ft = data;
|
2009-09-06 16:50:20 +00:00
|
|
|
if (ft != NULL)
|
2009-07-09 06:49:42 +00:00
|
|
|
{
|
2014-05-18 15:49:22 -07:00
|
|
|
SETPTR(ft->priv->projfilecmds, NULL);
|
|
|
|
SETPTR(ft->priv->projexeccmds, NULL);
|
|
|
|
SETPTR(ft->priv->projerror_regex_string, NULL);
|
|
|
|
ft->priv->project_list_entry = -1;
|
2009-07-09 06:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-06 16:50:20 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* open_default will make function reload default session files on close */
|
2007-11-18 18:24:23 +00:00
|
|
|
void project_close(gboolean open_default)
|
2007-11-11 19:06:41 +00:00
|
|
|
{
|
2012-01-19 18:09:29 +00:00
|
|
|
GSList *node;
|
|
|
|
|
2007-11-11 19:06:41 +00:00
|
|
|
g_return_if_fail(app->project != NULL);
|
|
|
|
|
2012-11-21 13:07:37 +00:00
|
|
|
/* save project session files, etc */
|
2011-02-06 16:36:04 +00:00
|
|
|
if (!write_config(FALSE))
|
|
|
|
g_warning("Project file \"%s\" could not be written", app->project->file_name);
|
2008-01-13 17:50:04 +00:00
|
|
|
|
2012-11-21 13:07:37 +00:00
|
|
|
if (project_prefs.project_session)
|
|
|
|
{
|
|
|
|
/* close all existing tabs first */
|
|
|
|
if (!document_close_all())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
|
|
|
|
|
2009-07-09 06:49:42 +00:00
|
|
|
/* remove project filetypes build entries */
|
2014-05-18 15:49:22 -07:00
|
|
|
if (app->project->priv->build_filetypes_list != NULL)
|
2009-07-25 05:24:48 +00:00
|
|
|
{
|
2014-05-18 15:49:22 -07:00
|
|
|
g_ptr_array_foreach(app->project->priv->build_filetypes_list, remove_foreach_project_filetype, NULL);
|
|
|
|
g_ptr_array_free(app->project->priv->build_filetypes_list, FALSE);
|
2009-07-25 05:24:48 +00:00
|
|
|
}
|
2009-07-27 16:37:23 +00:00
|
|
|
|
2009-07-09 06:49:42 +00:00
|
|
|
/* remove project non filetype build menu items */
|
2009-09-06 16:50:20 +00:00
|
|
|
build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1);
|
|
|
|
build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1);
|
2009-07-27 16:37:23 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_free(app->project);
|
|
|
|
app->project = NULL;
|
2007-05-01 12:27:56 +00:00
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
foreach_slist(node, stash_groups)
|
|
|
|
stash_group_free(node->data);
|
|
|
|
|
|
|
|
g_slist_free(stash_groups);
|
|
|
|
stash_groups = NULL;
|
|
|
|
|
2010-03-10 16:20:34 +00:00
|
|
|
apply_editor_prefs(); /* ensure that global settings are restored */
|
|
|
|
|
2008-01-16 16:30:34 +00:00
|
|
|
if (project_prefs.project_session)
|
2007-11-11 19:06:41 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* after closing all tabs let's open the tabs found in the default config */
|
2009-04-15 22:46:13 +00:00
|
|
|
if (open_default && cl_options.load_session)
|
2008-01-16 16:30:34 +00:00
|
|
|
{
|
|
|
|
configuration_reload_default_session();
|
|
|
|
configuration_open_files();
|
2008-02-27 13:17:29 +00:00
|
|
|
/* open a new file if no other file was opened */
|
2008-04-08 14:07:17 +00:00
|
|
|
document_new_file_if_non_open();
|
2011-06-02 21:16:43 +00:00
|
|
|
ui_focus_current_document();
|
2008-01-16 16:30:34 +00:00
|
|
|
}
|
2007-11-18 18:24:23 +00:00
|
|
|
}
|
2008-11-21 17:33:35 +00:00
|
|
|
g_signal_emit_by_name(geany_object, "project-close");
|
2007-11-18 18:24:23 +00:00
|
|
|
|
2007-05-28 15:24:21 +00:00
|
|
|
update_ui();
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
2009-08-26 17:25:28 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
/* Shows the file chooser dialog when base path button is clicked
|
|
|
|
* FIXME: this should be connected in Glade but 3.8.1 has a bug
|
|
|
|
* where it won't pass any objects as user data (#588824). */
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
on_project_properties_base_path_button_clicked(GtkWidget *button,
|
|
|
|
GtkWidget *base_path_entry)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2010-07-07 12:04:28 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
g_return_if_fail(base_path_entry != NULL);
|
|
|
|
g_return_if_fail(GTK_IS_WIDGET(base_path_entry));
|
2010-08-24 12:07:28 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Choose Project Base Path"),
|
|
|
|
NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(base_path_entry),
|
|
|
|
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void insert_build_page(PropertyDialogElements *e)
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
2012-01-19 18:09:29 +00:00
|
|
|
GtkWidget *build_table, *label;
|
2009-07-09 06:49:42 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2010-03-10 00:55:21 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
if (doc != NULL)
|
|
|
|
ft = doc->file_type;
|
2009-02-10 21:10:50 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
build_table = build_commands_table(doc, GEANY_BCS_PROJ, &(e->build_properties), ft);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(build_table), 6);
|
|
|
|
label = gtk_label_new(_("Build"));
|
2012-01-19 18:09:29 +00:00
|
|
|
e->build_page_num = gtk_notebook_append_page(GTK_NOTEBOOK(e->notebook),
|
|
|
|
build_table, label);
|
2011-12-27 23:12:10 -08:00
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
static void create_properties_dialog(PropertyDialogElements *e)
|
|
|
|
{
|
|
|
|
GtkWidget *base_path_button;
|
|
|
|
static guint base_path_button_handler_id = 0;
|
|
|
|
static guint radio_long_line_handler_id = 0;
|
2007-03-10 12:27:55 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
e->dialog = create_project_dialog();
|
|
|
|
e->notebook = ui_lookup_widget(e->dialog, "project_notebook");
|
|
|
|
e->file_name = ui_lookup_widget(e->dialog, "label_project_dialog_filename");
|
|
|
|
e->name = ui_lookup_widget(e->dialog, "entry_project_dialog_name");
|
|
|
|
e->description = ui_lookup_widget(e->dialog, "textview_project_dialog_description");
|
|
|
|
e->base_path = ui_lookup_widget(e->dialog, "entry_project_dialog_base_path");
|
|
|
|
e->patterns = ui_lookup_widget(e->dialog, "entry_project_dialog_file_patterns");
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->name));
|
2009-09-21 16:46:16 +00:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->base_path));
|
2011-12-27 23:12:10 -08:00
|
|
|
ui_entry_add_clear_icon(GTK_ENTRY(e->patterns));
|
2009-07-27 16:37:23 +00:00
|
|
|
|
2011-12-27 23:12:10 -08:00
|
|
|
/* Workaround for bug in Glade 3.8.1, see comment above signal handler */
|
|
|
|
if (base_path_button_handler_id == 0)
|
|
|
|
{
|
|
|
|
base_path_button = ui_lookup_widget(e->dialog, "button_project_dialog_base_path");
|
|
|
|
base_path_button_handler_id =
|
|
|
|
g_signal_connect(base_path_button, "clicked",
|
|
|
|
G_CALLBACK(on_project_properties_base_path_button_clicked),
|
|
|
|
e->base_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same as above, should be in Glade but can't due to bug in 3.8.1 */
|
|
|
|
if (radio_long_line_handler_id == 0)
|
|
|
|
{
|
|
|
|
radio_long_line_handler_id =
|
|
|
|
g_signal_connect(ui_lookup_widget(e->dialog,
|
|
|
|
"radio_long_line_custom_project"), "toggled",
|
|
|
|
G_CALLBACK(on_radio_long_line_custom_toggled),
|
|
|
|
ui_lookup_widget(e->dialog, "spin_long_line_project"));
|
|
|
|
}
|
2008-01-11 16:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-07 12:04:28 +00:00
|
|
|
static void show_project_properties(gboolean show_build)
|
2008-01-11 16:53:25 +00:00
|
|
|
{
|
|
|
|
GeanyProject *p = app->project;
|
2010-03-10 16:20:34 +00:00
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
GtkWidget *radio_long_line_custom;
|
2012-01-09 15:56:59 +00:00
|
|
|
static PropertyDialogElements e;
|
2012-01-19 18:09:29 +00:00
|
|
|
GSList *node;
|
2012-01-09 15:56:59 +00:00
|
|
|
|
2008-01-11 16:53:25 +00:00
|
|
|
g_return_if_fail(app->project != NULL);
|
|
|
|
|
|
|
|
entries_modified = FALSE;
|
|
|
|
|
2012-01-08 11:48:54 -08:00
|
|
|
if (e.dialog == NULL)
|
|
|
|
create_properties_dialog(&e);
|
|
|
|
|
|
|
|
insert_build_page(&e);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
foreach_slist(node, stash_groups)
|
|
|
|
stash_group_display(node->data, e.dialog);
|
2008-12-27 12:55:04 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* fill the elements with the appropriate data */
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(e.name), p->name);
|
|
|
|
gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path);
|
2010-03-10 16:20:34 +00:00
|
|
|
|
2012-01-08 11:48:54 -08:00
|
|
|
radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project");
|
2014-05-18 15:49:22 -07:00
|
|
|
switch (p->priv->long_line_behaviour)
|
2010-03-10 16:20:34 +00:00
|
|
|
{
|
2012-01-08 11:48:54 -08:00
|
|
|
case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break;
|
|
|
|
case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break;
|
2010-03-10 16:20:34 +00:00
|
|
|
case 2: widget = radio_long_line_custom; break;
|
|
|
|
}
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
|
|
|
|
|
2012-01-08 11:48:54 -08:00
|
|
|
widget = ui_lookup_widget(e.dialog, "spin_long_line_project");
|
2014-05-18 15:49:22 -07:00
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->priv->long_line_column);
|
2010-03-10 16:20:34 +00:00
|
|
|
on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
if (p->description != NULL)
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* set text */
|
2012-01-08 11:48:54 -08:00
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description));
|
2007-03-10 12:27:55 +00:00
|
|
|
gtk_text_buffer_set_text(buffer, p->description, -1);
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-03-10 12:27:55 +00:00
|
|
|
if (p->file_patterns != NULL)
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* set the file patterns */
|
2011-04-30 21:50:22 +00:00
|
|
|
gchar *str;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2011-04-30 21:50:22 +00:00
|
|
|
str = g_strjoinv(" ", p->file_patterns);
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(e.patterns), str);
|
2011-04-30 21:50:22 +00:00
|
|
|
g_free(str);
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 23:55:25 +01:00
|
|
|
g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook);
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_widget_show_all(e.dialog);
|
2007-04-21 16:27:38 +00:00
|
|
|
|
2010-07-07 12:04:28 +00:00
|
|
|
/* note: notebook page must be shown before setting current page */
|
|
|
|
if (show_build)
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
|
2010-07-07 12:04:28 +00:00
|
|
|
else
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0);
|
2010-07-07 12:04:28 +00:00
|
|
|
|
2012-01-08 11:48:54 -08:00
|
|
|
while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK)
|
2007-05-01 12:27:56 +00:00
|
|
|
{
|
2012-01-08 11:48:54 -08:00
|
|
|
if (update_config(&e, FALSE))
|
2010-03-31 13:39:33 +00:00
|
|
|
{
|
2012-01-08 11:48:54 -08:00
|
|
|
g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook);
|
2011-02-06 16:32:49 +00:00
|
|
|
if (!write_config(TRUE))
|
|
|
|
SHOW_ERR(_("Project file could not be written"));
|
|
|
|
else
|
2012-01-08 11:34:27 -08:00
|
|
|
{
|
2011-02-06 16:32:49 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name);
|
2012-01-08 11:34:27 -08:00
|
|
|
break;
|
|
|
|
}
|
2010-03-31 13:39:33 +00:00
|
|
|
}
|
2007-05-01 12:27:56 +00:00
|
|
|
}
|
2011-12-27 23:12:10 -08:00
|
|
|
|
2012-01-08 11:48:54 -08:00
|
|
|
build_free_fields(e.build_properties);
|
2012-02-19 23:55:25 +01:00
|
|
|
g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook);
|
2012-01-08 11:48:54 -08:00
|
|
|
gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num);
|
|
|
|
gtk_widget_hide(e.dialog);
|
2007-01-15 18:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-07 12:04:28 +00:00
|
|
|
void project_properties(void)
|
|
|
|
{
|
|
|
|
show_project_properties(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void project_build_properties(void)
|
|
|
|
{
|
|
|
|
show_project_properties(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|
2009-04-05 14:14:29 +00:00
|
|
|
gboolean project_ask_close(void)
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
|
|
|
if (app->project != NULL)
|
|
|
|
{
|
2008-01-09 18:05:09 +00:00
|
|
|
if (dialogs_show_question_full(NULL, GTK_STOCK_CLOSE, GTK_STOCK_CANCEL,
|
2007-05-01 15:48:53 +00:00
|
|
|
_("Do you want to close it before proceeding?"),
|
2012-02-20 00:06:24 +01:00
|
|
|
_("The '%s' project is open."), app->project->name))
|
2007-01-15 18:12:32 +00:00
|
|
|
{
|
2007-11-18 18:24:23 +00:00
|
|
|
project_close(FALSE);
|
2007-01-15 18:12:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
|
|
|
|
2008-12-27 12:55:04 +00:00
|
|
|
static GeanyProject *create_project(void)
|
|
|
|
{
|
|
|
|
GeanyProject *project = g_new0(GeanyProject, 1);
|
|
|
|
|
|
|
|
memset(&priv, 0, sizeof priv);
|
|
|
|
priv.indentation = &indentation;
|
|
|
|
project->priv = &priv;
|
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
init_stash_prefs();
|
|
|
|
|
2011-04-30 21:50:22 +00:00
|
|
|
project->file_patterns = NULL;
|
|
|
|
|
2014-05-18 15:49:22 -07:00
|
|
|
project->priv->long_line_behaviour = 1 /* use global settings */;
|
|
|
|
project->priv->long_line_column = editor_prefs.long_line_column;
|
2010-03-10 16:20:34 +00:00
|
|
|
|
2008-12-27 12:55:04 +00:00
|
|
|
app->project = project;
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
/* Verifies data for New & Properties dialogs.
|
|
|
|
* Returns: FALSE if the user needs to change any data. */
|
2011-02-06 16:32:49 +00:00
|
|
|
static gboolean update_config(const PropertyDialogElements *e, gboolean new_project)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2007-04-21 16:27:38 +00:00
|
|
|
const gchar *name, *file_name, *base_path;
|
2007-10-28 17:02:36 +00:00
|
|
|
gchar *locale_filename;
|
2011-12-17 23:10:03 +01:00
|
|
|
gsize name_len;
|
2008-10-02 15:09:33 +00:00
|
|
|
gint err_code = 0;
|
2007-04-21 16:27:38 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-10-19 14:48:19 +00:00
|
|
|
SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN);
|
2007-04-21 16:27:38 +00:00
|
|
|
gtk_widget_grab_focus(e->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2011-02-06 16:32:49 +00:00
|
|
|
if (new_project)
|
2010-08-24 11:41:56 +00:00
|
|
|
file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name));
|
|
|
|
else
|
|
|
|
file_name = gtk_label_get_text(GTK_LABEL(e->file_name));
|
|
|
|
|
2013-08-11 14:10:57 +01:00
|
|
|
if (G_UNLIKELY(EMPTY(file_name)))
|
2007-04-21 16:27:38 +00:00
|
|
|
{
|
|
|
|
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-10-28 17:02:36 +00:00
|
|
|
locale_filename = utils_get_locale_from_utf8(file_name);
|
2007-04-21 16:27:38 +00:00
|
|
|
base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
|
2013-08-11 14:10:57 +01:00
|
|
|
if (!EMPTY(base_path))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* check whether the given directory actually exists */
|
2007-04-21 16:27:38 +00:00
|
|
|
gchar *locale_path = utils_get_locale_from_utf8(base_path);
|
2007-10-28 17:02:36 +00:00
|
|
|
|
|
|
|
if (! g_path_is_absolute(locale_path))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* relative base path, so add base dir of project file name */
|
2007-10-28 17:02:36 +00:00
|
|
|
gchar *dir = g_path_get_dirname(locale_filename);
|
2012-08-09 18:15:47 -07:00
|
|
|
SETPTR(locale_path, g_strconcat(dir, locale_path, NULL));
|
2007-10-28 17:02:36 +00:00
|
|
|
g_free(dir);
|
|
|
|
}
|
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2008-09-30 20:28:18 +00:00
|
|
|
gboolean create_dir;
|
|
|
|
|
|
|
|
create_dir = 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."),
|
2008-09-30 20:28:18 +00:00
|
|
|
base_path);
|
|
|
|
|
|
|
|
if (create_dir)
|
|
|
|
err_code = utils_mkdir(locale_path, TRUE);
|
|
|
|
|
|
|
|
if (! create_dir || err_code != 0)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
2008-09-30 20:28:18 +00:00
|
|
|
if (err_code != 0)
|
2008-10-02 15:09:33 +00:00
|
|
|
SHOW_ERR1(_("Project base directory could not be created (%s)."),
|
2008-09-30 20:28:18 +00:00
|
|
|
g_strerror(err_code));
|
2007-04-21 16:27:38 +00:00
|
|
|
gtk_widget_grab_focus(e->base_path);
|
2009-10-15 16:15:28 +00:00
|
|
|
utils_free_pointers(2, locale_path, locale_filename, NULL);
|
2007-04-21 16:27:38 +00:00
|
|
|
return FALSE;
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-21 16:27:38 +00:00
|
|
|
g_free(locale_path);
|
|
|
|
}
|
2008-10-02 15:09:33 +00:00
|
|
|
/* finally test whether the given project file can be written */
|
2011-02-06 16:47:18 +00:00
|
|
|
if ((err_code = utils_is_file_writable(locale_filename)) != 0 ||
|
2011-02-06 16:32:49 +00:00
|
|
|
(err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0)
|
2008-10-02 15:09:33 +00:00
|
|
|
{
|
|
|
|
SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code));
|
|
|
|
gtk_widget_grab_focus(e->file_name);
|
|
|
|
g_free(locale_filename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-10-28 17:02:36 +00:00
|
|
|
g_free(locale_filename);
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2007-04-21 16:27:38 +00:00
|
|
|
if (app->project == NULL)
|
|
|
|
{
|
2008-12-27 12:55:04 +00:00
|
|
|
create_project();
|
2007-04-21 16:27:38 +00:00
|
|
|
new_project = TRUE;
|
|
|
|
}
|
|
|
|
p = app->project;
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2012-01-25 16:26:16 +00:00
|
|
|
SETPTR(p->name, g_strdup(name));
|
|
|
|
SETPTR(p->file_name, g_strdup(file_name));
|
2008-09-30 20:28:18 +00:00
|
|
|
/* use "." if base_path is empty */
|
2013-08-11 14:10:57 +01:00
|
|
|
SETPTR(p->base_path, g_strdup(!EMPTY(base_path) ? base_path : "./"));
|
2007-01-17 23:44:08 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
if (! new_project) /* save properties specific fields */
|
2007-04-21 16:27:38 +00:00
|
|
|
{
|
2010-05-11 14:38:42 +00:00
|
|
|
GtkTextIter start, end;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GeanyDocument *doc = document_get_current();
|
|
|
|
GeanyBuildCommand *oldvalue;
|
|
|
|
GeanyFiletype *ft = doc ? doc->file_type : NULL;
|
|
|
|
GtkWidget *widget;
|
2011-04-30 21:50:22 +00:00
|
|
|
gchar *tmp;
|
|
|
|
GString *str;
|
2012-01-19 18:09:29 +00:00
|
|
|
GSList *node;
|
2007-04-21 16:27:38 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get and set the project description */
|
2007-04-21 16:27:38 +00:00
|
|
|
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);
|
2012-01-25 16:26:16 +00:00
|
|
|
SETPTR(p->description, g_strdup(gtk_text_buffer_get_text(buffer, &start, &end, FALSE)));
|
2009-07-27 16:37:23 +00:00
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
foreach_slist(node, stash_groups)
|
|
|
|
stash_group_update(node->data, e->dialog);
|
2010-10-18 14:16:08 +00:00
|
|
|
|
2009-07-09 06:49:42 +00:00
|
|
|
/* read the project build menu */
|
2014-05-18 15:49:22 -07:00
|
|
|
oldvalue = ft ? ft->priv->projfilecmds : NULL;
|
2010-05-11 14:38:42 +00:00
|
|
|
build_read_project(ft, e->build_properties);
|
|
|
|
|
2014-05-18 15:49:22 -07:00
|
|
|
if (ft != NULL && ft->priv->projfilecmds != oldvalue && ft->priv->project_list_entry < 0)
|
2009-07-09 06:49:42 +00:00
|
|
|
{
|
2014-05-18 15:49:22 -07:00
|
|
|
if (p->priv->build_filetypes_list == NULL)
|
|
|
|
p->priv->build_filetypes_list = g_ptr_array_new();
|
|
|
|
ft->priv->project_list_entry = p->priv->build_filetypes_list->len;
|
|
|
|
g_ptr_array_add(p->priv->build_filetypes_list, ft);
|
2009-07-09 06:49:42 +00:00
|
|
|
}
|
|
|
|
build_menu_update(doc);
|
2007-04-21 16:27:38 +00:00
|
|
|
|
2011-10-22 11:58:09 -07:00
|
|
|
widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project");
|
2010-03-10 16:20:34 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_behaviour = 0;
|
2010-03-10 16:20:34 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-22 11:58:09 -07:00
|
|
|
widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project");
|
2010-03-10 16:20:34 +00:00
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_behaviour = 1;
|
2010-03-10 16:20:34 +00:00
|
|
|
else
|
|
|
|
/* "Custom" radio button must be checked */
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_behaviour = 2;
|
2010-03-10 16:20:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 11:58:09 -07:00
|
|
|
widget = ui_lookup_widget(e->dialog, "spin_long_line_project");
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
|
2010-03-10 16:20:34 +00:00
|
|
|
apply_editor_prefs();
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get and set the project file patterns */
|
2011-04-30 21:50:22 +00:00
|
|
|
tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns)));
|
2007-04-21 16:27:38 +00:00
|
|
|
g_strfreev(p->file_patterns);
|
2011-04-30 21:50:22 +00:00
|
|
|
g_strstrip(tmp);
|
|
|
|
str = g_string_new(tmp);
|
|
|
|
do {} while (utils_string_replace_all(str, " ", " "));
|
|
|
|
p->file_patterns = g_strsplit(str->str, " ", -1);
|
|
|
|
g_string_free(str, TRUE);
|
2007-04-21 16:27:38 +00:00
|
|
|
g_free(tmp);
|
2007-01-17 23:44:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:29:27 +00:00
|
|
|
update_ui();
|
|
|
|
|
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)
|
|
|
|
{
|
2008-02-27 13:17:29 +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))
|
2008-03-15 11:06:55 +00:00
|
|
|
{
|
|
|
|
/* if the current filename is a directory, we must use
|
|
|
|
* gtk_file_chooser_set_current_folder(which expects a locale filename) otherwise
|
|
|
|
* we end up in the parent directory */
|
|
|
|
if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR))
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_filename);
|
|
|
|
else
|
|
|
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else /* if the file doesn't yet exist, use at least the current directory */
|
2007-10-28 17:02:36 +00:00
|
|
|
{
|
|
|
|
gchar *locale_dir = g_path_get_dirname(locale_filename);
|
|
|
|
gchar *name = g_path_get_basename(utf8_filename);
|
|
|
|
|
|
|
|
if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dir);
|
|
|
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), name);
|
|
|
|
|
|
|
|
g_free(name);
|
|
|
|
g_free(locale_dir);
|
|
|
|
}
|
2007-03-10 17:26:03 +00:00
|
|
|
}
|
2009-09-06 16:50:20 +00:00
|
|
|
else 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);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* run it */
|
2007-01-18 22:13:50 +00:00
|
|
|
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-12-07 16:31:38 +00:00
|
|
|
static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e)
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2007-12-07 16:31:38 +00:00
|
|
|
gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Filename"),
|
|
|
|
gtk_entry_get_text(GTK_ENTRY(e->file_name)), TRUE, TRUE);
|
2007-02-19 18:58:32 +00:00
|
|
|
if (path != NULL)
|
|
|
|
{
|
2007-12-07 16:31:38 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(e->file_name), path);
|
2007-02-19 18:58:32 +00:00
|
|
|
g_free(path);
|
|
|
|
}
|
2007-01-17 23:44:08 +00:00
|
|
|
#else
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* 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-12-07 16:31:38 +00:00
|
|
|
run_dialog(dialog, e->file_name);
|
2007-01-17 23:44:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
2013-08-11 14:10:57 +01:00
|
|
|
if (!EMPTY(name))
|
2007-01-17 23:44:08 +00:00
|
|
|
{
|
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);
|
2008-10-02 15:09:33 +00:00
|
|
|
if (project_prefs.project_file_in_basedir)
|
|
|
|
file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S, name, G_DIR_SEPARATOR_S,
|
|
|
|
name, "." GEANY_PROJECT_EXT, NULL);
|
|
|
|
else
|
|
|
|
file_name = g_strconcat(project_dir, G_DIR_SEPARATOR_S,
|
|
|
|
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
|
|
|
|
|
|
|
|
2010-03-10 16:20:34 +00:00
|
|
|
static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name);
|
2009-04-05 14:14:29 +00:00
|
|
|
|
|
|
|
ui_add_recent_project_file(utf8_filename);
|
|
|
|
g_free(utf8_filename);
|
2007-04-21 12:25:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename);
|
2007-04-21 12:25:17 +00:00
|
|
|
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;
|
2012-01-19 18:09:29 +00:00
|
|
|
GSList *node;
|
2007-01-21 17:43:52 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* there should not be an open project */
|
2007-01-21 17:43:52 +00:00
|
|
|
g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
|
|
|
|
|
|
|
|
config = g_key_file_new();
|
2007-11-18 18:24:23 +00:00
|
|
|
if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL))
|
2007-01-21 17:43:52 +00:00
|
|
|
{
|
|
|
|
g_key_file_free(config);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-27 12:55:04 +00:00
|
|
|
p = create_project();
|
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
foreach_slist(node, stash_groups)
|
|
|
|
stash_group_load_from_key_file(node->data, config);
|
2007-04-21 12:25:17 +00:00
|
|
|
|
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", "");
|
|
|
|
p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
|
|
|
|
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_behaviour = utils_get_setting_integer(config, "long line marker",
|
2010-03-12 15:09:48 +00:00
|
|
|
"long_line_behaviour", 1 /* follow global */);
|
2014-05-18 15:49:22 -07:00
|
|
|
p->priv->long_line_column = utils_get_setting_integer(config, "long line marker",
|
2010-11-23 17:36:29 +00:00
|
|
|
"long_line_column", editor_prefs.long_line_column);
|
2010-03-10 16:20:34 +00:00
|
|
|
apply_editor_prefs();
|
|
|
|
|
2009-09-16 14:13:38 +00:00
|
|
|
build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p);
|
2008-01-16 16:30:34 +00:00
|
|
|
if (project_prefs.project_session)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* save current (non-project) session (it could has been changed since program startup) */
|
2008-01-16 16:30:34 +00:00
|
|
|
configuration_save_default_session();
|
2008-02-27 13:17:29 +00:00
|
|
|
/* now close all open files */
|
2008-04-24 14:13:06 +00:00
|
|
|
document_close_all();
|
2008-02-27 13:17:29 +00:00
|
|
|
/* read session files so they can be opened with configuration_open_files() */
|
2009-04-15 22:46:13 +00:00
|
|
|
configuration_load_session_files(config, FALSE);
|
2011-06-02 21:16:43 +00:00
|
|
|
ui_focus_current_document();
|
2008-01-16 16:30:34 +00:00
|
|
|
}
|
2008-11-21 17:33:35 +00:00
|
|
|
g_signal_emit_by_name(geany_object, "project-open", config);
|
2007-01-21 17:43:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-25 17:43:39 +00:00
|
|
|
static void apply_editor_prefs(void)
|
2010-03-10 16:20:34 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
foreach_document(i)
|
|
|
|
editor_apply_update_prefs(documents[i]->editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-13 17:50:04 +00:00
|
|
|
/* Write the project settings as well as the project session files into its configuration files.
|
|
|
|
* emit_signal defines whether the project-save signal should be emitted. When write_config()
|
|
|
|
* is called while closing a project, this is used to skip emitting the signal because
|
|
|
|
* project-close will be emitted afterwards.
|
|
|
|
* Returns: TRUE if project file was written successfully. */
|
|
|
|
static gboolean write_config(gboolean emit_signal)
|
2007-01-21 17:43:52 +00:00
|
|
|
{
|
|
|
|
GeanyProject *p;
|
|
|
|
GKeyFile *config;
|
|
|
|
gchar *filename;
|
|
|
|
gchar *data;
|
2007-03-05 12:13:09 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-01-19 18:09:29 +00:00
|
|
|
GSList *node;
|
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();
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try to load an existing config to keep manually added comments */
|
2007-01-21 17:43:52 +00:00
|
|
|
filename = utils_get_locale_from_utf8(p->file_name);
|
2007-11-18 18:24:23 +00:00
|
|
|
g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
|
2007-01-21 17:43:52 +00:00
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
foreach_slist(node, stash_groups)
|
|
|
|
stash_group_save_to_key_file(node->data, config);
|
2008-12-27 12:55:04 +00:00
|
|
|
|
2007-01-21 17:43:52 +00:00
|
|
|
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->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
|
|
|
|
2014-05-18 15:49:22 -07:00
|
|
|
g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
|
|
|
|
g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);
|
2010-03-10 16:20:34 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* store the session files into the project too */
|
2008-01-16 16:30:34 +00:00
|
|
|
if (project_prefs.project_session)
|
|
|
|
configuration_save_session_files(config);
|
2009-09-16 14:13:38 +00:00
|
|
|
build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
|
2008-11-21 17:33:35 +00:00
|
|
|
if (emit_signal)
|
2007-11-21 18:54:12 +00:00
|
|
|
{
|
|
|
|
g_signal_emit_by_name(geany_object, "project-save", config);
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* write the file */
|
2007-01-21 17:43:52 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2007-10-28 17:02:36 +00:00
|
|
|
/* Constructs the project's base path which is used for "Make all" and "Execute".
|
|
|
|
* The result is an absolute string in UTF-8 encoding which is either the same as
|
|
|
|
* base path if it is absolute or it is built out of project file name's dir and base_path.
|
|
|
|
* If there is no project or project's base_path is invalid, NULL will be returned.
|
|
|
|
* The returned string should be freed when no longer needed. */
|
2009-04-16 17:55:26 +00:00
|
|
|
gchar *project_get_base_path(void)
|
2007-03-01 11:38:14 +00:00
|
|
|
{
|
2008-01-11 16:53:25 +00:00
|
|
|
GeanyProject *project = app->project;
|
|
|
|
|
2013-08-11 14:10:57 +01:00
|
|
|
if (project && !EMPTY(project->base_path))
|
2007-10-28 17:02:36 +00:00
|
|
|
{
|
2008-01-11 16:53:25 +00:00
|
|
|
if (g_path_is_absolute(project->base_path))
|
|
|
|
return g_strdup(project->base_path);
|
2007-10-28 17:02:36 +00:00
|
|
|
else
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* build base_path out of project file name's dir and base_path */
|
2007-10-28 17:02:36 +00:00
|
|
|
gchar *path;
|
2008-01-11 16:53:25 +00:00
|
|
|
gchar *dir = g_path_get_dirname(project->file_name);
|
2007-10-28 17:02:36 +00:00
|
|
|
|
2009-04-16 17:55:26 +00:00
|
|
|
if (utils_str_equal(project->base_path, "./"))
|
|
|
|
return dir;
|
2012-08-09 18:15:47 -07:00
|
|
|
|
|
|
|
path = g_build_filename(dir, project->base_path, NULL);
|
2007-10-28 17:02:36 +00:00
|
|
|
g_free(dir);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
2008-01-11 16:53:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-25 13:09:14 +00:00
|
|
|
/* This is to save project-related global settings, NOT project file settings. */
|
2007-04-21 12:25:17 +00:00
|
|
|
void project_save_prefs(GKeyFile *config)
|
|
|
|
{
|
|
|
|
GeanyProject *project = app->project;
|
|
|
|
|
|
|
|
if (cl_options.load_session)
|
|
|
|
{
|
2010-04-25 17:43:39 +00:00
|
|
|
const gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
|
2007-04-21 12:25:17 +00:00
|
|
|
|
|
|
|
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",
|
2013-08-11 14:10:57 +01:00
|
|
|
FALLBACK(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)
|
|
|
|
{
|
2012-08-09 18:15:47 -07:00
|
|
|
local_prefs.project_file_path = g_build_filename(g_get_home_dir(), PROJECT_DIR, NULL);
|
2007-04-29 16:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize project-related preferences in the Preferences dialog. */
|
2009-04-16 17:55:26 +00:00
|
|
|
void project_setup_prefs(void)
|
2007-04-29 16:36:42 +00:00
|
|
|
{
|
2008-12-18 21:21:53 +00:00
|
|
|
GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
|
|
|
|
GtkWidget *path_btn = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_button");
|
2009-05-26 19:49:18 +00:00
|
|
|
static gboolean callback_setup = FALSE;
|
2007-04-29 16:36:42 +00:00
|
|
|
|
|
|
|
g_return_if_fail(local_prefs.project_file_path != NULL);
|
2009-07-27 16:37:23 +00:00
|
|
|
|
2007-04-29 16:36:42 +00:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(path_entry), local_prefs.project_file_path);
|
2009-05-26 19:49:18 +00:00
|
|
|
if (! callback_setup)
|
|
|
|
{ /* connect the callback only once */
|
|
|
|
callback_setup = TRUE;
|
|
|
|
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. */
|
2009-04-16 17:55:26 +00:00
|
|
|
void project_apply_prefs(void)
|
2007-04-29 16:36:42 +00:00
|
|
|
{
|
2008-12-18 21:21:53 +00:00
|
|
|
GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry");
|
2007-04-29 16:36:42 +00:00
|
|
|
const gchar *str;
|
|
|
|
|
|
|
|
str = gtk_entry_get_text(GTK_ENTRY(path_entry));
|
2012-01-25 16:26:16 +00:00
|
|
|
SETPTR(local_prefs.project_file_path, g_strdup(str));
|
2007-04-21 12:25:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 16:36:42 +00:00
|
|
|
|
2012-01-19 18:09:29 +00:00
|
|
|
static void add_stash_group(StashGroup *group)
|
|
|
|
{
|
|
|
|
stash_groups = g_slist_prepend(stash_groups, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init_stash_prefs(void)
|
2008-12-27 12:55:04 +00:00
|
|
|
{
|
2010-03-18 17:04:17 +00:00
|
|
|
StashGroup *group;
|
2012-01-19 18:09:29 +00:00
|
|
|
GKeyFile *kf;
|
2008-12-27 12:55:04 +00:00
|
|
|
|
|
|
|
group = stash_group_new("indentation");
|
2012-01-19 18:09:29 +00:00
|
|
|
/* copy global defaults */
|
|
|
|
indentation = *editor_get_indent_prefs(NULL);
|
2008-12-27 12:55:04 +00:00
|
|
|
stash_group_set_use_defaults(group, FALSE);
|
2012-01-19 18:09:29 +00:00
|
|
|
add_stash_group(group);
|
2008-12-27 12:55:04 +00:00
|
|
|
|
|
|
|
stash_group_add_spin_button_integer(group, &indentation.width,
|
2011-10-22 11:58:09 -07:00
|
|
|
"indent_width", 4, "spin_indent_width_project");
|
2009-01-16 20:34:34 +00:00
|
|
|
stash_group_add_radio_buttons(group, (gint*)(gpointer)&indentation.type,
|
2008-12-27 12:55:04 +00:00
|
|
|
"indent_type", GEANY_INDENT_TYPE_TABS,
|
2011-10-22 11:58:09 -07:00
|
|
|
"radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
|
|
|
|
"radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
|
|
|
|
"radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
|
2008-12-27 12:55:04 +00:00
|
|
|
NULL);
|
2010-04-28 13:08:15 +00:00
|
|
|
/* This is a 'hidden' pref for backwards-compatibility */
|
|
|
|
stash_group_add_integer(group, &indentation.hard_tab_width,
|
|
|
|
"indent_hard_tab_width", 8);
|
2008-12-27 12:55:04 +00:00
|
|
|
stash_group_add_toggle_button(group, &indentation.detect_type,
|
2011-10-22 11:58:09 -07:00
|
|
|
"detect_indent", FALSE, "check_detect_indent_type_project");
|
2011-03-26 17:25:24 +00:00
|
|
|
stash_group_add_toggle_button(group, &indentation.detect_width,
|
2011-10-22 11:58:09 -07:00
|
|
|
"detect_indent_width", FALSE, "check_detect_indent_width_project");
|
2009-01-16 20:34:34 +00:00
|
|
|
stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode,
|
2011-10-22 11:58:09 -07:00
|
|
|
"indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");
|
2012-01-19 18:09:29 +00:00
|
|
|
|
|
|
|
group = stash_group_new("file_prefs");
|
|
|
|
stash_group_add_toggle_button(group, &priv.final_new_line,
|
|
|
|
"final_new_line", file_prefs.final_new_line, "check_new_line1");
|
|
|
|
stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines,
|
|
|
|
"ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
|
|
|
|
stash_group_add_toggle_button(group, &priv.strip_trailing_spaces,
|
|
|
|
"strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
|
|
|
|
stash_group_add_toggle_button(group, &priv.replace_tabs,
|
|
|
|
"replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
|
|
|
|
add_stash_group(group);
|
|
|
|
/* apply defaults */
|
|
|
|
kf = g_key_file_new();
|
|
|
|
stash_group_load_from_key_file(group, kf);
|
|
|
|
g_key_file_free(kf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define COPY_PREF(dest, prefname)\
|
|
|
|
(dest.prefname = priv.prefname)
|
|
|
|
|
|
|
|
const GeanyFilePrefs *project_get_file_prefs(void)
|
|
|
|
{
|
|
|
|
static GeanyFilePrefs fp;
|
|
|
|
|
|
|
|
if (!app->project)
|
|
|
|
return &file_prefs;
|
|
|
|
|
|
|
|
fp = file_prefs;
|
|
|
|
COPY_PREF(fp, final_new_line);
|
|
|
|
COPY_PREF(fp, ensure_convert_new_lines);
|
|
|
|
COPY_PREF(fp, strip_trailing_spaces);
|
|
|
|
COPY_PREF(fp, replace_tabs);
|
|
|
|
return &fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void project_init(void)
|
|
|
|
{
|
2008-12-27 12:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void project_finalize(void)
|
|
|
|
{
|
|
|
|
}
|