| 1 |
/* AbiSource Application Framework |
| 2 |
* Copyright (C) 1998 AbiSource, Inc. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 |
* 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <stdio.h> |
| 22 |
#include <string.h> |
| 23 |
#include "ut_assert.h" |
| 24 |
#include "ut_string.h" |
| 25 |
#include "ut_debugmsg.h" |
| 26 |
#include "xap_App.h" |
| 27 |
#include "xap_Prefs.h" |
| 28 |
#include "xap_Dlg_FileOpenSaveAs.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
/***************************************************************** |
| 34 |
** The file-open and file-save-as dialogs have |
| 35 |
** app-persistence, but the persistence is |
| 36 |
** independent of each other. This code supports |
| 37 |
** both dialogs; one instance of this object will |
| 38 |
** be created for each. The object, once created, |
| 39 |
** will be recycled (reused) throughout the session. |
| 40 |
** |
| 41 |
** We observe the following basic policy: |
| 42 |
** [] we are to be given the pathname of the document |
| 43 |
** in the frame from which we were requested. if |
| 44 |
** it is 'untitled', give us a null pathname. |
| 45 |
** [] if the document has a pathname, we will start |
| 46 |
** the dialog in directory(pathname). |
| 47 |
** [] if the document does not have a pathname, we |
| 48 |
** will start in the directory we were in when |
| 49 |
** last OK'd. (we ignore previous CANCEL's.) |
| 50 |
** [] if the document does not have a pathname and |
| 51 |
** we have no previous OK'd use, we start the |
| 52 |
** dialog in the current directory (probably from |
| 53 |
** where the application was invoked from). |
| 54 |
** [] we do not let the current working directory |
| 55 |
** change. |
| 56 |
|
| 57 |
******************************************************************/ |
| 58 |
|
| 59 |
XAP_Dialog_FileOpenSaveAs::XAP_Dialog_FileOpenSaveAs(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id) |
| 60 |
: XAP_Dialog_AppPersistent(pDlgFactory,id, "interface/dialogopenlinux"), |
| 61 |
m_szPersistPathname(NULL), |
| 62 |
m_szInitialPathname(NULL), |
| 63 |
m_szFinalPathname(NULL), |
| 64 |
m_szDescriptions(NULL), |
| 65 |
m_szSuffixes(NULL), |
| 66 |
m_nTypeList(NULL), |
| 67 |
m_nFileType(XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO), |
| 68 |
m_nDefaultFileType(XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO), |
| 69 |
m_bSuggestName(false), |
| 70 |
m_answer(a_VOID), |
| 71 |
m_appendDefaultSuffixFunctor( getAppendDefaultSuffixFunctorUsing_IE_Exp_preferredSuffixForFileType() ) |
| 72 |
|
| 73 |
{ |
| 74 |
const gchar * savedir = 0; |
| 75 |
if (getApp()->getPrefsValue(XAP_PREF_KEY_DefaultSaveDirectory, &savedir) && strlen(savedir)) |
| 76 |
{ |
| 77 |
m_szPersistPathname = g_strdup(savedir); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
XAP_Dialog_FileOpenSaveAs::~XAP_Dialog_FileOpenSaveAs(void) |
| 82 |
{ |
| 83 |
UT_ASSERT(!m_bInUse); |
| 84 |
FREEP(m_szPersistPathname); |
| 85 |
FREEP(m_szInitialPathname); |
| 86 |
FREEP(m_szFinalPathname); |
| 87 |
} |
| 88 |
|
| 89 |
void XAP_Dialog_FileOpenSaveAs::useStart(void) |
| 90 |
{ |
| 91 |
XAP_Dialog_AppPersistent::useStart(); |
| 92 |
|
| 93 |
FREEP(m_szInitialPathname); |
| 94 |
FREEP(m_szFinalPathname); |
| 95 |
m_answer = a_VOID; |
| 96 |
m_bSuggestName = false; |
| 97 |
} |
| 98 |
|
| 99 |
void XAP_Dialog_FileOpenSaveAs::useEnd(void) |
| 100 |
{ |
| 101 |
XAP_Dialog_AppPersistent::useEnd(); |
| 102 |
|
| 103 |
FREEP(m_szInitialPathname); |
| 104 |
if (m_answer == a_OK) |
| 105 |
{ |
| 106 |
FREEP(m_szPersistPathname); |
| 107 |
m_szPersistPathname = m_szFinalPathname; |
| 108 |
m_szFinalPathname = NULL; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
void XAP_Dialog_FileOpenSaveAs::setCurrentPathname(const char * szPathname) |
| 113 |
{ |
| 114 |
// this lets us know the pathname of the document |
| 115 |
// in the frame from which we were invoked. |
| 116 |
|
| 117 |
FREEP(m_szInitialPathname); |
| 118 |
if (szPathname && *szPathname) |
| 119 |
m_szInitialPathname = g_strdup(szPathname); |
| 120 |
} |
| 121 |
|
| 122 |
void XAP_Dialog_FileOpenSaveAs::setSuggestFilename(bool bSuggestName) |
| 123 |
{ |
| 124 |
m_bSuggestName = bSuggestName; |
| 125 |
} |
| 126 |
|
| 127 |
XAP_Dialog_FileOpenSaveAs::tAnswer XAP_Dialog_FileOpenSaveAs::getAnswer(void) const |
| 128 |
{ |
| 129 |
// let our caller know if user hit ok or cancel. |
| 130 |
|
| 131 |
return m_answer; |
| 132 |
} |
| 133 |
|
| 134 |
const char * XAP_Dialog_FileOpenSaveAs::getPathname(void) const |
| 135 |
{ |
| 136 |
// give our caller a temporary string (valid until the next |
| 137 |
// use of this dialog) containing the pathname the user |
| 138 |
// chose. |
| 139 |
|
| 140 |
return m_szFinalPathname; |
| 141 |
} |
| 142 |
|
| 143 |
void XAP_Dialog_FileOpenSaveAs::setFileTypeList(const char ** szDescriptions, |
| 144 |
const char ** szSuffixes, |
| 145 |
const UT_sint32 * nTypeList) |
| 146 |
{ |
| 147 |
m_szDescriptions = szDescriptions; |
| 148 |
m_szSuffixes = szSuffixes; |
| 149 |
m_nTypeList = nTypeList; |
| 150 |
} |
| 151 |
|
| 152 |
void XAP_Dialog_FileOpenSaveAs::setDefaultFileType(UT_sint32 nType) |
| 153 |
{ |
| 154 |
m_nDefaultFileType = nType; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
UT_sint32 XAP_Dialog_FileOpenSaveAs::getFileType(void) const |
| 159 |
{ |
| 160 |
return m_nFileType; |
| 161 |
} |
| 162 |
|
| 163 |
void |
| 164 |
XAP_Dialog_FileOpenSaveAs::setAppendDefaultSuffixFunctor( m_appendDefaultSuffixFunctor_t f ) |
| 165 |
{ |
| 166 |
m_appendDefaultSuffixFunctor = f; |
| 167 |
} |
| 168 |
|
| 169 |
#include "../../../wp/impexp/xp/ie_types.h" |
| 170 |
#include "../../../wp/impexp/xp/ie_exp.h" |
| 171 |
#include <sstream> |
| 172 |
|
| 173 |
std::string |
| 174 |
AppendDefaultSuffixFunctorUsing_IE_Exp_preferredSuffixForFileType( std::string dialogFilename, UT_sint32 n ) |
| 175 |
{ |
| 176 |
UT_UTF8String suffix( IE_Exp::preferredSuffixForFileType( n )); |
| 177 |
std::stringstream ss; |
| 178 |
ss << dialogFilename << suffix.utf8_str(); |
| 179 |
return ss.str(); |
| 180 |
} |
| 181 |
|
| 182 |
XAP_Dialog_FileOpenSaveAs::m_appendDefaultSuffixFunctor_t |
| 183 |
getAppendDefaultSuffixFunctorUsing_IE_Exp_preferredSuffixForFileType() |
| 184 |
{ |
| 185 |
return AppendDefaultSuffixFunctorUsing_IE_Exp_preferredSuffixForFileType; |
| 186 |
} |