Debian Codegraph @

src/af/xap/xp/xap_Dlg_ListDocuments.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 2003 Tomas Frydrych <[email protected]>
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
27 #include "xap_Dlg_ListDocuments.h"
28 #include "xap_App.h"
29 #include "xad_Document.h"
30
31 #include "xap_Dialog_Id.h"
32 #include "xap_DialogFactory.h"
33 #include "xap_Dlg_MessageBox.h"
34 #include "xap_Frame.h"
35
36 XAP_Dialog_ListDocuments::XAP_Dialog_ListDocuments(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id):
37 XAP_Dialog_NonPersistent(pDlgFactory,id, "interface/dialoglistdocument"),
38 m_answer(a_OK),
39 m_ndxSelDoc(-1),
40 m_bIncludeActiveDoc(false)
41 {
42 _init();
43 }
44
45 XAP_Dialog_ListDocuments::~XAP_Dialog_ListDocuments(void)
46 {
47 }
48
49 void XAP_Dialog_ListDocuments::_init()
50 {
51 m_vDocs.clear();
52 UT_return_if_fail(m_pApp);
53 AD_Document * pExclude = NULL;
54
55 if(!m_bIncludeActiveDoc)
56 {
57 XAP_Frame * pF = m_pApp->getLastFocussedFrame();
58
59 if(pF)
60 {
61 pExclude = pF->getCurrentDoc();
62 }
63 }
64
65 m_pApp->enumerateDocuments(m_vDocs,pExclude);
66 }
67
68 AD_Document * XAP_Dialog_ListDocuments::getDocument(void) const
69 {
70 UT_ASSERT(m_answer == a_OK);
71 UT_ASSERT_HARMLESS(m_pApp);
72
73 if (m_pApp && (m_ndxSelDoc >= 0))
74 {
75 return (AD_Document *)m_vDocs.getNthItem(m_ndxSelDoc);
76 }
77
78 return NULL;
79 }
80
81 void XAP_Dialog_ListDocuments::_setSelDocumentIndx(UT_sint32 i)
82 {
83 UT_return_if_fail(i <= m_vDocs.getItemCount());
84 m_ndxSelDoc = i;
85 }
86
87 const char * XAP_Dialog_ListDocuments::_getNthDocumentName(UT_sint32 n) const
88 {
89 if(n >= m_vDocs.getItemCount())
90 return NULL;
91
92 const AD_Document * pDoc = (const AD_Document *)m_vDocs.getNthItem(n);
93
94 if(!pDoc)
95 return NULL;
96
97 return pDoc->getFilename();
98 }
99
100 void XAP_Dialog_ListDocuments::setIncludeActiveDoc(bool b)
101 {
102 if(b != m_bIncludeActiveDoc)
103 {
104 m_bIncludeActiveDoc = b;
105 _init();
106 }
107 }
108
109 const char * XAP_Dialog_ListDocuments::_getTitle() const
110 {
111 const XAP_StringSet * pSS = m_pApp->getStringSet();
112 UT_return_val_if_fail(pSS, NULL);
113
114 return pSS->getValue(XAP_STRING_ID_DLG_LISTDOCS_Title);
115 }
116
117 const char * XAP_Dialog_ListDocuments::_getHeading() const
118 {
119 const XAP_StringSet * pSS = m_pApp->getStringSet();
120 UT_return_val_if_fail(pSS, NULL);
121
122 return pSS->getValue(XAP_STRING_ID_DLG_LISTDOCS_Heading1);
123 }
124
125 const char * XAP_Dialog_ListDocuments::_getOKButtonText() const
126 {
127
128 const XAP_StringSet * pSS = m_pApp->getStringSet();
129 UT_return_val_if_fail(pSS, NULL);
130
131 switch(getDialogId())
132 {
133 case XAP_DIALOG_ID_LISTDOCUMENTS:
134 return pSS->getValue(XAP_STRING_ID_DLG_Select);
135
136 case XAP_DIALOG_ID_COMPAREDOCUMENTS:
137 return pSS->getValue(XAP_STRING_ID_DLG_Compare);
138
139 case XAP_DIALOG_ID_MERGEDOCUMENTS:
140 return pSS->getValue(XAP_STRING_ID_DLG_Merge);
141
142 default:
143 UT_return_val_if_fail(UT_NOT_REACHED, NULL);
144 }
145
146 return NULL;
147 }
148
149