1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/********************************************************************************************
Clean OS Windows library module version 1.2.1.
This module is part of the Clean Object I/O library, version 1.2.1,
for the Windows platform.
********************************************************************************************/
/********************************************************************************************
About this module:
Routines related to standard file selector dialogues.
********************************************************************************************/
#include "cCrossCallFileSelectors_121.h"
#include "util_121.h"
#include "cCrossCall_121.h"
extern GtkWidget *gActiveTopLevelWindow;
void EvalCcRqDIRECTORYDIALOG (CrossCallInfo *pcci) /* no params; bool, textptr result; */
{
GtkWidget *file_selector = gtk_file_selection_new("Select directory");
if (gActiveTopLevelWindow)
{
gtk_window_set_transient_for(GTK_WINDOW(file_selector), GTK_WINDOW(gActiveTopLevelWindow));
}
for (;;)
{
if (gtk_dialog_run(GTK_DIALOG(file_selector)) == GTK_RESPONSE_OK)
{
gchar *file_name;
G_CONST_RETURN gchar *fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selector));
if (!g_file_test(fname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
{
GtkWidget *dialog =
gtk_message_dialog_new (GTK_WINDOW(file_selector),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s directory not found",
fname);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
continue;
}
file_name = g_strdup(fname);
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_true(), (int) file_name);
return;
}
else
{
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_false(), (int) NULL);
return;
}
}
}
void EvalCcRqFILEOPENDIALOG (CrossCallInfo *pcci) /* no params; bool, textptr result; */
{
GtkWidget *file_selector = gtk_file_selection_new("Open");
if (gActiveTopLevelWindow)
{
gtk_widget_set_parent(file_selector, gActiveTopLevelWindow);
gtk_window_set_transient_for(GTK_WINDOW(file_selector), GTK_WINDOW(gActiveTopLevelWindow));
}
for (;;)
{
if (gtk_dialog_run(GTK_DIALOG(file_selector)) == GTK_RESPONSE_OK)
{
gchar *file_name;
G_CONST_RETURN gchar *fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selector));
if (!g_file_test(fname, G_FILE_TEST_EXISTS))
{
GtkWidget *dialog =
gtk_message_dialog_new (GTK_WINDOW(file_selector),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s file not found",
fname);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
continue;
}
file_name = g_strdup(fname);
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_true(), (int) file_name);
return;
}
else
{
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_false(), (int) NULL);
return;
}
}
}
void EvalCcRqFILESAVEDIALOG (CrossCallInfo *pcci) /* promptptr, nameptr; bool, textptr result; */
{
GtkWidget *file_selector = gtk_file_selection_new((gchar *) pcci->p1);
if (gActiveTopLevelWindow)
{
gtk_widget_set_parent(file_selector, gActiveTopLevelWindow);
gtk_window_set_transient_for(GTK_WINDOW(file_selector), GTK_WINDOW(gActiveTopLevelWindow));
}
gtk_file_selection_set_filename(file_selector, (gchar *) pcci->p2);
for (;;)
{
if (gtk_dialog_run(GTK_DIALOG(file_selector)) == GTK_RESPONSE_OK)
{
gchar *file_name;
G_CONST_RETURN gchar *fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selector));
if (g_file_test(fname, G_FILE_TEST_EXISTS))
{
gint res;
GtkWidget *dialog =
gtk_message_dialog_new (GTK_WINDOW(file_selector),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_YES_NO,
"%s already exists. Do you want to replace id?",
fname);
res = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
if (res == GTK_RESPONSE_NO) continue;
}
file_name = g_strdup(fname);
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_true(), (int) file_name);
return;
}
else
{
gtk_widget_destroy(file_selector);
MakeReturn2Cci(pcci, gtk_false(), (int) NULL);
return;
}
}
}
/* Install the cross call procedures in the gCrossCallProcedureTable of cCrossCall_121.
*/
void InstallCrossCallFileSelectors()
{
CrossCallProcedureTable newTable;
newTable = EmptyCrossCallProcedureTable ();
AddCrossCallEntry (newTable, CcRqDIRECTORYDIALOG,EvalCcRqDIRECTORYDIALOG);
AddCrossCallEntry (newTable, CcRqFILEOPENDIALOG, EvalCcRqFILEOPENDIALOG);
AddCrossCallEntry (newTable, CcRqFILESAVEDIALOG, EvalCcRqFILESAVEDIALOG);
AddCrossCallEntries (gCrossCallProcedureTable, newTable);
}
|