It doesn't do anything yet --- it's just an editor.
src/ui/gui/psppire-var-store.h \
src/ui/gui/sort-cases-dialog.c \
src/ui/gui/sort-cases-dialog.h \
+ src/ui/gui/syntax-editor.c \
src/ui/gui/val-labs-dialog.c \
src/ui/gui/val-labs-dialog.h \
src/ui/gui/var-sheet.c \
-/*
+/*
PSPPIRE --- A Graphical User Interface for PSPP
Copyright (C) 2004, 2005, 2006 Free Software Foundation
Written by John Darrington
psppire_set_window_title(const gchar *text)
{
GtkWidget *data_editor = get_widget_assert(xml, "data_editor");
-
+
gchar *title = g_strdup_printf("%s --- %s", text, gettext(window_title));
gtk_window_set_title(GTK_WINDOW(data_editor), title);
g_free(title);
}
-/* Clear the active file and set the data and var sheets to
+/* Clear the active file and set the data and var sheets to
reflect this.
*/
gboolean
PsppireDataStore *data_store ;
struct dictionary *new_dict;
struct sfm_read_info ri;
- struct sfm_reader *reader ;
+ struct sfm_reader *reader ;
GtkWidget *data_sheet = get_widget_assert(xml, "data_sheet");
GtkWidget *var_sheet = get_widget_assert(xml, "variable_sheet");
clear_file();
- psppire_handle =
+ psppire_handle =
fh_create_file (handle_name, file_name, fh_default_properties());
- if ( !psppire_handle )
+ if ( !psppire_handle )
{
- g_warning("Cannot read handle for reading system file \"%s\"\n",
+ g_warning("Cannot read handle for reading system file \"%s\"\n",
file_name);
return FALSE;
}
reader = sfm_open_reader (psppire_handle, &new_dict, &ri);
-
- if ( ! reader )
+
+ if ( ! reader )
return FALSE;
/* FIXME: We need a better way of updating a dictionary than this */
the_dictionary = psppire_dict_new_from_dict(new_dict);
- var_store =
+ var_store =
PSPPIRE_VAR_STORE(gtk_sheet_get_model(GTK_SHEET(var_sheet)));
-
+
psppire_var_store_set_dictionary(var_store, the_dictionary);
- data_store =
+ data_store =
PSPPIRE_DATA_STORE(gtk_sheet_get_model(GTK_SHEET(data_sheet)));
-
+
psppire_data_store_set_dictionary(data_store,
the_dictionary);
psppire_set_window_title(basename(file_name));
var_cnt = dict_get_next_value_idx(the_dictionary->dict);
- if ( var_cnt == 0 )
+ if ( var_cnt == 0 )
return FALSE;
break;
}
- if ( !psppire_case_file_append_case(data_store->case_file, &c) )
+ if ( !psppire_case_file_append_case(data_store->case_file, &c) )
{
g_warning("Cannot write case to casefile\n");
break;
}
case_destroy(&c);
}
-
- sfm_close_reader(reader);
+
+ sfm_close_reader(reader);
psppire_case_file_get_case_count(data_store->case_file);
return TRUE;
}
-
void
-on_open1_activate (GtkMenuItem *menuitem,
- gpointer user_data)
+open_data (GtkMenuItem *menuitem,
+ gpointer user_data)
{
bool finished = FALSE;
GtkWidget *dialog;
GtkWidget *data_editor = get_widget_assert(xml, "data_editor");
GtkFileFilter *filter ;
-
+
dialog = gtk_file_chooser_dialog_new (_("Open"),
GTK_WINDOW(data_editor),
GTK_FILE_CHOOSER_ACTION_OPEN,
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
- gchar *file_name =
+ gchar *file_name =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
-
+
finished = load_system_file(file_name) ;
g_free(file_name);
}
+void
+on_data3_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ open_data(menuitem, user_data);
+}
+
+void
+on_data5_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ open_data(menuitem, user_data);
+}
+
+
/* Re initialise HANDLE, by interrogating the user for a new file name */
static gboolean
recreate_save_handle(struct file_handle **handle)
(GTK_FILE_CHOOSER (dialog));
- if ( *handle )
+ if ( *handle )
fh_free(*handle);
- *handle = fh_create_file (handle_name, file_name,
+ *handle = fh_create_file (handle_name, file_name,
fh_default_properties());
psppire_set_window_title(basename(file_name));
GtkSheet *data_sheet ;
PsppireDataStore *data_store ;
- if ( ! psppire_handle )
+ if ( ! psppire_handle )
{
- if ( ! recreate_save_handle(&psppire_handle) )
+ if ( ! recreate_save_handle(&psppire_handle) )
return;
}
-
+
data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
-
- if ( psppire_handle )
+
+ if ( psppire_handle )
psppire_data_store_create_system_file(data_store,
psppire_handle);
}
GtkSheet *data_sheet ;
PsppireDataStore *data_store ;
- if ( ! recreate_save_handle(&psppire_handle) )
+ if ( ! recreate_save_handle(&psppire_handle) )
return ;
- if ( ! psppire_handle )
+ if ( ! psppire_handle )
return ;
data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
- if ( psppire_handle )
+ if ( psppire_handle )
psppire_data_store_create_system_file(data_store,
psppire_handle);
}
page = gtk_notebook_get_current_page(notebook);
- switch (page)
+ switch (page)
{
case PAGE_VAR_SHEET:
break;
case PAGE_DATA_SHEET:
{
GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
- PsppireDataStore *data_store =
+ PsppireDataStore *data_store =
PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
-
- switch ( data_sheet->state )
+
+ switch ( data_sheet->state )
{
case GTK_SHEET_ROW_SELECTED:
psppire_case_file_delete_cases(data_store->case_file,
- data_sheet->range.rowi
+ data_sheet->range.rowi
- data_sheet->range.row0 + 1,
data_sheet->range.row0);
break;
case GTK_SHEET_COLUMN_SELECTED:
{
gint fv;
- struct PsppireVariable *pv =
- psppire_dict_get_variable(the_dictionary,
+ struct PsppireVariable *pv =
+ psppire_dict_get_variable(the_dictionary,
data_sheet->range.col0);
fv = psppire_variable_get_fv(pv);
-
-
- psppire_dict_delete_variables(the_dictionary,
+
+
+ psppire_dict_delete_variables(the_dictionary,
data_sheet->range.col0,
1);
- psppire_case_file_insert_values(data_store->case_file,
+ psppire_case_file_insert_values(data_store->case_file,
-1, fv);
}
break;
default:
- gtk_sheet_cell_clear(data_sheet,
+ gtk_sheet_cell_clear(data_sheet,
data_sheet->active_cell.row,
data_sheet->active_cell.col);
break;
gpointer user_data)
{
GtkWidget *about = get_widget_assert(xml, "aboutdialog1");
-
-
+
+
GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_size( "pspplogo.png", 64, 64, 0);
gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), pb);
gtk_widget_show(about);
- gtk_window_set_transient_for(GTK_WINDOW(about),
+ gtk_window_set_transient_for(GTK_WINDOW(about),
GTK_WINDOW(get_widget_assert(xml, "data_editor")));
}
gpointer user_data)
{
GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
- GtkCheckMenuItem *item =
+ GtkCheckMenuItem *item =
GTK_CHECK_MENU_ITEM(get_widget_assert(xml, "menuitem-value-labels"));
PsppireDataStore *ds = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
gboolean show_value_labels = gtk_toggle_tool_button_get_active(toggle_tool_button);
-
+
gtk_check_menu_item_set_active(item, show_value_labels);
psppire_data_store_show_labels(ds, show_value_labels);
gpointer user_data)
{
GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
- GtkToggleToolButton *tb =
+ GtkToggleToolButton *tb =
GTK_TOGGLE_TOOL_BUTTON(get_widget_assert(xml, "togglebutton-value-labels"));
PsppireDataStore *ds = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
gpointer user_data)
{
- if ( gtk_check_menu_item_get_active(menuitem) )
+ if ( gtk_check_menu_item_get_active(menuitem) )
gtk_widget_show(get_widget_assert(xml, "statusbar1"));
else
gtk_widget_hide(get_widget_assert(xml, "statusbar1"));
gpointer user_data)
{
- const bool grid_visible = gtk_check_menu_item_get_active(menuitem);
+ const bool grid_visible = gtk_check_menu_item_get_active(menuitem);
gtk_sheet_show_grid(GTK_SHEET(get_widget_assert(xml, "variable_sheet")),
grid_visible);
on_fonts1_activate(GtkMenuItem *menuitem,
gpointer user_data)
{
- static GtkWidget *dialog = 0 ;
- if ( !dialog )
+ static GtkWidget *dialog = 0 ;
+ if ( !dialog )
dialog = gtk_font_selection_dialog_new(_("Font Selection"));
- gtk_window_set_transient_for(GTK_WINDOW(dialog),
+ gtk_window_set_transient_for(GTK_WINDOW(dialog),
GTK_WINDOW(get_widget_assert(xml, "data_editor")));
- if ( GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(dialog)) )
+ if ( GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(dialog)) )
{
- GtkSheet *data_sheet =
+ GtkSheet *data_sheet =
GTK_SHEET(get_widget_assert(xml, "data_sheet"));
- GtkSheet *var_sheet =
+ GtkSheet *var_sheet =
GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
PsppireDataStore *ds = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
PsppireVarStore *vs = PSPPIRE_VAR_STORE(gtk_sheet_get_model(var_sheet));
- const gchar *font = gtk_font_selection_dialog_get_font_name
+ const gchar *font = gtk_font_selection_dialog_get_font_name
(GTK_FONT_SELECTION_DIALOG(dialog));
- PangoFontDescription* font_desc =
+ PangoFontDescription* font_desc =
pango_font_description_from_string(font);
psppire_var_store_set_font(vs, font_desc);
psppire_data_store_set_font(ds, font_desc);
}
-
+
gtk_widget_hide(dialog);
}
GtkWidget *insert_variable = get_widget_assert(xml, "insert-variable");
GtkWidget *insert_cases = get_widget_assert(xml, "insert-cases");
- switch (page)
+ switch (page)
{
case PAGE_VAR_SHEET:
gtk_widget_hide(menuitems[PAGE_VAR_SHEET]);
GtkWidget *dialog = get_widget_assert(xml, "go_to_case_dialog");
GtkEntry *entry = GTK_ENTRY(get_widget_assert(xml, "entry_go_to_case"));
GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
-
+
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
-
-
+
+
switch (result)
{
case GTK_RESPONSE_OK:
gtk_sheet_get_active_cell(data_sheet, &row, &column);
if ( column < 0 ) column = 0;
if ( row < 0 ) row = 0;
-
+
gtk_sheet_set_active_cell(data_sheet, casenum, column);
}
break;
data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet));
- if ( NULL == dialog)
+ if ( NULL == dialog)
dialog = sort_cases_dialog_create(xml);
response = sort_cases_dialog_run(dialog, the_dictionary, &criteria);
- switch ( response)
+ switch ( response)
{
case GTK_RESPONSE_OK:
psppire_case_file_sort(data_store->case_file, &criteria);
}
-static void
+static void
insert_case(void)
{
gint row, col;
}
void
-on_insert_case_clicked (GtkButton *button, gpointer user_data)
+on_insert_case_clicked (GtkButton *button, gpointer user_data)
{
insert_case();
}
<widget class="GtkWindow" id="data_editor">
<property name="visible">True</property>
- <property name="title">Psppire</property>
+ <property name="title">Psppire Data Editor</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="visible">True</property>
<property name="label">gtk-new</property>
<property name="use_stock">True</property>
- <signal name="activate" handler="on_new1_activate" last_modification_time="Tue, 23 Mar 2004 10:22:51 GMT"/>
+
+ <child>
+ <widget class="GtkMenu" id="new1_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="syntax1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Syntax</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_syntax1_activate" last_modification_time="Tue, 05 Dec 2006 01:39:48 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="data2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Data</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
</widget>
</child>
<property name="visible">True</property>
<property name="label">gtk-open</property>
<property name="use_stock">True</property>
- <signal name="activate" handler="on_open1_activate" last_modification_time="Tue, 23 Mar 2004 10:22:51 GMT"/>
+
+ <child>
+ <widget class="GtkMenu" id="open1_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="syntax2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Syntax</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_syntax2_activate" last_modification_time="Tue, 05 Dec 2006 01:39:48 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="data3">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Data</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_data3_activate" last_modification_time="Tue, 05 Dec 2006 01:39:48 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
</widget>
</child>
<property name="use_underline">True</property>
<child internal-child="image">
- <widget class="GtkImage" id="image10">
+ <widget class="GtkImage" id="image15">
<property name="visible">True</property>
<property name="stock">gtk-find</property>
<property name="icon_size">1</property>
<property name="sensitive">False</property>
<property name="label" translatable="yes">Insert Variable</property>
<property name="use_underline">True</property>
- <signal name="activate" handler="on_insert_variable" />
+ <signal name="activate" handler="on_insert_variable"/>
</widget>
</child>
<signal name="activate" handler="on_go_to_case_activate" last_modification_time="Mon, 19 Jun 2006 10:29:37 GMT"/>
<child internal-child="image">
- <widget class="GtkImage" id="image11">
+ <widget class="GtkImage" id="image16">
<property name="visible">True</property>
<property name="stock">gtk-jump-to</property>
<property name="icon_size">1</property>
<property name="visible_horizontal">True</property>
<property name="visible_vertical">True</property>
<property name="is_important">False</property>
- <signal name="clicked" handler="on_open1_activate" last_modification_time="Thu, 10 Nov 2005 12:22:50 GMT"/>
</widget>
<packing>
<property name="expand">False</property>
<widget class="GtkToolButton" id="variables">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Variables</property>
- <property name="stock_id">pspp-goto-variable</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToolButton" id="insert_case">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Insert Case</property>
- <property name="stock_id">pspp-insert-case</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToolButton" id="insert_variable">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Insert Variable</property>
- <property name="stock_id">pspp-insert-variable</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToolButton" id="toolbutton8">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Split File</property>
- <property name="stock_id">pspp-split-file</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToolButton" id="toolbutton9">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Weight Cases</property>
- <property name="stock_id">pspp-weight-cases</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToolButton" id="toolbutton10">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Select Cases</property>
- <property name="stock_id">pspp-select-cases</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
<widget class="GtkToggleToolButton" id="togglebutton-value-labels">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Value Labels</property>
- <property name="stock_id">pspp-value-labels</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="visible_horizontal">True</property>
</child>
</widget>
+<widget class="GtkWindow" id="syntax_editor">
+ <property name="width_request">640</property>
+ <property name="height_request">480</property>
+ <property name="can_focus">True</property>
+ <property name="title" translatable="yes">Psppire Syntax Editor</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="resizable">True</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="decorated">True</property>
+ <property name="skip_taskbar_hint">False</property>
+ <property name="skip_pager_hint">False</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+ <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+ <property name="focus_on_map">True</property>
+ <property name="urgency_hint">False</property>
+
+ <child>
+ <widget class="GtkVBox" id="vbox14">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkMenuBar" id="menubar2">
+ <property name="visible">True</property>
+ <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property>
+ <property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property>
+
+ <child>
+ <widget class="GtkMenuItem" id="menu_syntax_file">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_File</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="menu_syntax_file_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="new2">
+ <property name="visible">True</property>
+ <property name="label">gtk-new</property>
+ <property name="use_stock">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="new2_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="file_new_syntax">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Syntax</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="data4">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Data</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="open2">
+ <property name="visible">True</property>
+ <property name="label">gtk-open</property>
+ <property name="use_stock">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="open2_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="file_open_syntax">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Syntax</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_syntax4_activate" last_modification_time="Tue, 05 Dec 2006 01:43:21 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="data5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Data</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_data5_activate" last_modification_time="Tue, 05 Dec 2006 01:43:21 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save">
+ <property name="visible">True</property>
+ <property name="label">gtk-save</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save_as">
+ <property name="visible">True</property>
+ <property name="label">gtk-save-as</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separatormenuitem2">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_quit">
+ <property name="visible">True</property>
+ <property name="label">gtk-quit</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="menuitem7">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="menuitem7_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="cut2">
+ <property name="visible">True</property>
+ <property name="label">gtk-cut</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="copy2">
+ <property name="visible">True</property>
+ <property name="label">gtk-copy</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="paste2">
+ <property name="visible">True</property>
+ <property name="label">gtk-paste</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="delete1">
+ <property name="visible">True</property>
+ <property name="label">gtk-delete</property>
+ <property name="use_stock">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="run1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Run</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="run1_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="all1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">All</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="selection1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Selection</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="current_line1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Current Line</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="to_end1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">To End</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="menuitem9">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Help</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="menuitem9_menu">
+
+ <child>
+ <widget class="GtkMenuItem" id="about2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_About</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow8">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTextView" id="syntax_text_view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="overwrite">False</property>
+ <property name="accepts_tab">True</property>
+ <property name="justification">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap_mode">GTK_WRAP_NONE</property>
+ <property name="cursor_visible">True</property>
+ <property name="pixels_above_lines">0</property>
+ <property name="pixels_below_lines">0</property>
+ <property name="pixels_inside_wrap">0</property>
+ <property name="left_margin">0</property>
+ <property name="right_margin">0</property>
+ <property name="indent">0</property>
+ <property name="text" translatable="yes"></property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkStatusbar" id="statusbar2">
+ <property name="visible">True</property>
+ <property name="has_resize_grip">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
</glade-interface>
--- /dev/null
+/*
+ PSPPIRE --- A Graphical User Interface for PSPP
+ Copyright (C) 2006 Free Software Foundation
+ Written by John Darrington
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#include <config.h>
+#include <stdlib.h>
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+#include <glade/glade.h>
+#include <gtk/gtk.h>
+#include <libpspp/message.h>
+
+#include "helper.h"
+
+extern GladeXML *xml;
+
+struct syntax_editor
+{
+ GtkWidget *window; /* The top level window of the editor */
+ GtkTextBuffer *buffer; /* The buffer which contains the text */
+ gchar *name; /* The name of this syntax buffer/editor */
+};
+
+static gboolean save_editor_to_file (struct syntax_editor *se,
+ const gchar *filename,
+ GError **err);
+
+/* If the buffer's modified flag is set, then save it, and close the window.
+ Otherwise just close the window.
+*/
+static void
+save_if_modified (struct syntax_editor *se)
+{
+ if ( TRUE == gtk_text_buffer_get_modified (se->buffer))
+ {
+ gint response;
+ GtkWidget *dialog =
+ gtk_message_dialog_new (GTK_WINDOW(se->window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("Save contents of syntax editor to %s?"),
+ se->name ? se->name : _("Untitled")
+ );
+
+ gtk_dialog_add_button (GTK_DIALOG(dialog),
+ GTK_STOCK_YES,
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_add_button (GTK_DIALOG(dialog),
+ GTK_STOCK_NO,
+ GTK_RESPONSE_REJECT);
+ gtk_dialog_add_button (GTK_DIALOG(dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+
+
+ response = gtk_dialog_run (GTK_DIALOG(dialog));
+
+ gtk_widget_destroy (dialog);
+
+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ GError *err = NULL;
+
+ if ( ! save_editor_to_file (se, se->name ? se->name : _("Untitled"),
+ err) )
+ {
+ msg (ME, err->message);
+ g_error_free (err);
+ }
+ }
+
+ if ( response == GTK_RESPONSE_CANCEL )
+ return ;
+ }
+
+ gtk_widget_destroy (se->window);
+}
+
+/* Callback for the File->SaveAs menuitem */
+static void
+on_syntax_save_as (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GtkFileFilter *filter;
+ gint response;
+ struct syntax_editor *se = user_data;
+
+ GtkWidget *dialog =
+ gtk_file_chooser_dialog_new (_("Save Syntax"),
+ GTK_WINDOW(se->window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
+
+ 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);
+
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(dialog),
+ TRUE);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ GError *err = NULL;
+ char *filename =
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog) );
+
+ if ( save_editor_to_file (se, filename, &err) )
+ {
+ g_free (se->name);
+ se->name = g_strdup (filename);
+ }
+ else
+ {
+ msg ( ME, err->message );
+ g_error_free (err);
+ }
+
+ free (filename);
+ }
+
+ gtk_widget_destroy ( dialog );
+}
+
+/* Callback for the File->Save menuitem */
+void
+on_syntax_save (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ struct syntax_editor *se = user_data;
+
+ if ( se->name == NULL )
+ on_syntax_save_as (menuitem, user_data);
+ else
+ {
+ GError *err;
+ save_editor_to_file (se, se->name, &err);
+ msg (ME, err->message);
+ g_error_free (err);
+ }
+}
+
+
+/* Callback for the "delete" action (clicking the x on the top right
+ hand corner of the window) */
+static gboolean
+on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
+{
+ struct syntax_editor *se = user_data;
+ save_if_modified (se);
+ return TRUE;
+}
+
+
+/* Callback for the File->Quit menuitem */
+static gboolean
+on_quit (GtkMenuItem *menuitem, gpointer user_data)
+{
+ struct syntax_editor *se = user_data;
+ save_if_modified (se);
+ return FALSE;
+}
+
+void
+new_syntax_window (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+
+
+static void open_syntax_window (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+
+/* Create a new syntax editor with NAME.
+ If NAME is NULL, a name will be automatically assigned
+*/
+static struct syntax_editor *
+new_syntax_editor (const gchar *name)
+{
+ GladeXML *new_xml ;
+ GtkWidget *text_view;
+ struct syntax_editor *se ;
+
+ new_xml = glade_xml_new (xml->filename, "syntax_editor", NULL);
+
+ se = g_malloc (sizeof (*se));
+
+ se->window = get_widget_assert (new_xml, "syntax_editor");
+ text_view = get_widget_assert (new_xml, "syntax_text_view");
+ se->buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view));
+ if ( name )
+ se->name = g_strdup (name);
+ else
+ se->name = NULL;
+
+ g_signal_connect (get_widget_assert (new_xml,"file_new_syntax"),
+ "activate",
+ G_CALLBACK(new_syntax_window),
+ se->window);
+
+ g_signal_connect (get_widget_assert (new_xml,"file_open_syntax"),
+ "activate",
+ G_CALLBACK(open_syntax_window),
+ se->window);
+
+ g_signal_connect (get_widget_assert (new_xml,"file_quit"),
+ "activate",
+ G_CALLBACK(on_quit),
+ se);
+
+ g_signal_connect (get_widget_assert (new_xml,"file_save"),
+ "activate",
+ G_CALLBACK(on_syntax_save),
+ se);
+
+ g_signal_connect (get_widget_assert (new_xml,"file_save_as"),
+ "activate",
+ G_CALLBACK(on_syntax_save_as),
+ se);
+
+ g_object_unref (new_xml);
+
+ g_signal_connect (se->window, "delete-event",
+ G_CALLBACK(on_delete), se);
+
+ return se;
+}
+
+/* Callback for the File->New->Syntax menuitem */
+void
+new_syntax_window (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ struct syntax_editor *se = new_syntax_editor (NULL);
+ gtk_widget_show (se->window);
+}
+
+
+static void
+set_window_title_from_filename (struct syntax_editor *se,
+ const gchar *filename)
+{
+ gchar *title;
+ gchar *basename ;
+ g_free (se->name);
+ se->name = strdup (filename);
+ basename = g_path_get_basename (filename);
+ title =
+ g_strdup_printf (_("%s --- PSPP Syntax Editor"), basename);
+ g_free (basename);
+ gtk_window_set_title (GTK_WINDOW(se->window), title);
+ g_free (title);
+}
+
+
+/* Save BUFFER to the file called FILENAME.
+ If successful, clears the buffer's modified flag */
+static gboolean
+save_editor_to_file (struct syntax_editor *se,
+ const gchar *filename,
+ GError **err)
+{
+ GtkTextBuffer *buffer = se->buffer;
+ gboolean result ;
+ GtkTextIter start, stop;
+ gchar *text;
+
+ gchar *glibfilename;
+ g_assert (filename);
+
+ glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
+
+ if ( ! glibfilename )
+ return FALSE;
+
+ gtk_text_buffer_get_iter_at_line (buffer, &start, 0);
+ gtk_text_buffer_get_iter_at_offset (buffer, &stop, -1);
+
+ text = gtk_text_buffer_get_text (buffer, &start, &stop, FALSE);
+
+ result = g_file_set_contents (glibfilename, text, -1, err);
+
+ if ( result )
+ {
+ set_window_title_from_filename (se, filename);
+ gtk_text_buffer_set_modified (buffer, FALSE);
+ }
+
+ return result;
+}
+
+
+/* Loads the buffer from the file called FILENAME
+*/
+static gboolean
+load_editor_from_file (struct syntax_editor *se,
+ const gchar *filename,
+ GError **err)
+{
+ GtkTextBuffer *buffer = se->buffer;
+ gchar *text;
+ GtkTextIter iter;
+
+ gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
+
+ if ( ! glibfilename )
+ return FALSE;
+
+ /* FIXME: What if it's a very big file ? */
+ if ( ! g_file_get_contents (glibfilename, &text, NULL, err) )
+ {
+ g_free (glibfilename);
+ return FALSE;
+ }
+ g_free (glibfilename);
+
+ gtk_text_buffer_get_iter_at_line (buffer, &iter, 0);
+
+ gtk_text_buffer_insert (buffer, &iter, text, -1);
+
+ set_window_title_from_filename (se, filename);
+ gtk_text_buffer_set_modified (buffer, FALSE);
+
+ return TRUE;
+}
+
+
+/* Callback for the File->Open->Syntax menuitem */
+static void
+open_syntax_window (GtkMenuItem *menuitem, gpointer parent)
+{
+ GtkFileFilter *filter;
+ gint response;
+
+ GtkWidget *dialog =
+ gtk_file_chooser_dialog_new (_("Open Syntax"),
+ GTK_WINDOW(parent),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
+ gtk_file_filter_add_pattern (filter, "*.sps");
+ gtk_file_filter_add_pattern (filter, "*.SPS");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
+
+ 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);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ const char *file_name = gtk_file_chooser_get_filename
+ (GTK_FILE_CHOOSER (dialog));
+
+ struct syntax_editor *se = new_syntax_editor (file_name);
+
+ load_editor_from_file (se, file_name, NULL);
+
+ gtk_widget_show (se->window);
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+
+#if 1
+/* FIXME: get rid of these functions */
+void
+on_syntax4_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ g_print ("%s\n", __FUNCTION__);
+}
+
+
+
+void
+on_syntax2_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ g_print ("%s\n", __FUNCTION__);
+}
+
+void
+on_syntax1_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ g_print ("%s\n", __FUNCTION__);
+ new_syntax_window (menuitem, user_data);
+}
+#endif
+