1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 0.4
5  * October 1998
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26 
27 #include "vdk/FileSaveAsDialog.h"
28 #include <unistd.h>
29 #include <config.h>
30 
31 #ifdef VDKDEBUG
32 extern int objectC;
33 extern int objectD;
34 #endif
35 static char buff[256];
36 ///////////////////////////////////////////////////
DEFINE_SIGNAL_MAP(VDKFileSaveAsDialog,VDKFileDialog)37 DEFINE_SIGNAL_MAP(VDKFileSaveAsDialog,VDKFileDialog)
38   ON_SIGNAL(open,clicked_signal,SaveClick),
39   ON_SIGNAL(filelist,select_row_signal,FileSelected),
40   ON_SIGNAL(filetype,activate_signal,SetFileMask)
41 END_SIGNAL_MAP
42 ///////////////////////////
43 //
44 //////////////////////////
45 bool VDKFileSaveAsDialog::CheckOverwrite(char* file)
46 {
47 char locbuff[256];
48 if (!access(file,F_OK))
49   {
50     sprintf(locbuff,"File: %s\nexists, overwrite it ?",file);
51     int answer =
52       Application()->VDKMessageBox("File SaveAs Dialog",
53 			      locbuff,
54 			      VDK_YESNO | VDK_ICONINFORMATION);
55     return answer == VDK_IDYES;
56   }
57  else
58    return true;
59 }
60 ////////////////////////////
61 // response method
62 ///////////////////////////
FileSelected(VDKObject *)63 bool VDKFileSaveAsDialog::FileSelected(VDKObject*)
64 {
65   int sel = filelist->Selected.Row();
66   if(sel < 0) return true;
67   filetype->Text = (char*) filelist->Tuples[sel][0];
68   return true;
69 }
70 /*
71  */
SaveClick(VDKObject *)72 bool VDKFileSaveAsDialog::SaveClick(VDKObject*)
73 {
74   sprintf(buff,"%s/%s",(char*) pcwd,(char*) filetype->Text);
75   if(CheckOverwrite(buff))
76     {
77       selections->resize(1);
78       VDKUString s(buff);
79       (*selections)[0] = s;
80       Close();
81     }
82   return true;
83 }
84 /*
85  */
SetFileMask(VDKObject *)86 bool VDKFileSaveAsDialog::SetFileMask(VDKObject*)
87 {
88 SaveClick(NULL);
89 return true;
90 }
91 /*
92  */
VDKFileSaveAsDialog(VDKForm * owner,FileStringArray * selections,char * title,GtkWindowType display)93 VDKFileSaveAsDialog::VDKFileSaveAsDialog(VDKForm* owner,
94 		FileStringArray* selections,
95 		char* title,
96 	      GtkWindowType display):
97   VDKFileDialog(owner,selections,title,display)
98 {
99   gtk_clist_set_selection_mode(GTK_CLIST(filelist->CustomWidget()),
100 			     GTK_SELECTION_SINGLE);
101  filetypeLabel->Caption = "Save file as";
102  open->Caption = "Save";
103 }
104 
105 /*
106  */
~VDKFileSaveAsDialog()107 VDKFileSaveAsDialog::~VDKFileSaveAsDialog()
108 {
109 }
110 /*
111 */
112 
113 
114 
115 
116 
117 
118