First public contribution.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
29 #include <clock.h> // RMessageWindow::EMaxTextLength
36 #include <techview/eikrted.h>
38 #include <techview/eikcfdlg.h>
39 #include <techview/eikon.rsg>
45 #include "wpresources.h"
49 const TInt KExportTextWrapWidth=78;
50 const TInt KMaxTemplateMsgLen = KMaxFileName+32*2; // file name and a pre + post string
53 void CWordAppUi::CreateFileL(const TDesC& aFileName)
55 TFileName templateFileName=NormalTemplateFileNameL();
56 CreateFileL(aFileName, templateFileName);
59 void CWordAppUi::CreateFileL(const TDesC& aFileName, const TDesC& aTemplateFileName)
60 // Support a *switch file* create message from the shell
63 DoFileSaveL(EFalse); // do not echo any file save info message
64 Document()->DoFileNewL(aFileName, aTemplateFileName);
65 iEikonEnv->UpdateTaskNameL();
68 iRichEd->SetBookmark();
72 void CWordAppUi::CmdFileNewL()
73 // Get a filename and create that file
77 SetInitialPathL(fileName);
78 TFileName templateFileName;
79 CEikDialog* dialog=new(ELeave) CWordTemplateNewFileDialog(&fileName, templateFileName, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
80 if (dialog->ExecuteLD(R_WORD_TEMPLATE_FILE_NEW)) // confirms action if file already exists
81 CreateFileL(fileName, templateFileName);
85 void CWordAppUi::OpenFileL(const TDesC& aFileName)
86 // Supporta a *switch file* open message from the shell
89 DoFileSaveL(EFalse); // do not echo any file save info message
90 DoFileOpenL(aFileName);
91 Document()->SetChanged(EFalse);
93 iRichEd->SetBookmark();
97 void CWordAppUi::CmdFileOpenL()
98 // Get a filename from and open that file
102 SetInitialPathL(filename);
103 CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename);
104 dialog->RestrictToNativeDocumentFiles();
105 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
110 TFileName CWordAppUi::CurrentFilePath()const
112 TParsePtrC parser(Document()->Process()->MainDocFileName());
113 return parser.DriveAndPath();
117 void CWordAppUi::SetInitialPathL(TFileName& aFileName)const
118 // checks that the initial path exists, creating it if not
119 // if the path was read-only a default is used instead
121 aFileName=CurrentFilePath();
122 TRAPD(ret,ConeUtils::EnsurePathExistsL(aFileName) );
124 {// if the path is eg read-only default to C:
125 TWordFilePath::GetWordDefaultFilePath(aFileName);
126 ConeUtils::EnsurePathExistsL(aFileName);
130 TFileName CWordAppUi::NormalTemplateFileNameL()const
131 // Returns the name of the normal template
134 TFindFile ff(iEikonEnv->FsSession());
135 TFileName templateFileName;
136 TWordFilePath::GetNormalTemplateFolderName(templateFileName);
137 TFileName tempFileName;
138 iEikonEnv->ReadResource(tempFileName, R_WORD_NORMAL_TEMPLATE_FILE_NAME);
139 templateFileName.Append(tempFileName);
140 TParsePtr parse(templateFileName);
141 templateFileName[0] = 'Y';
142 TInt err = ff.FindByDir(parse.NameAndExt(),parse.DriveAndPath());
145 // no normal template, search ROM for blank
146 TWordFilePath::GetNormalTemplateFolderName(templateFileName);
147 iEikonEnv->ReadResource(tempFileName, R_WORD_BLANK_TEMPLATE_FILE_NAME);
148 templateFileName.Append(tempFileName);
149 templateFileName[0] = 'Z';
150 TParsePtr blankParse(templateFileName);
151 User::LeaveIfError(ff.FindByDir(blankParse.NameAndExt(),blankParse.DriveAndPath()));
156 void CWordAppUi::DoFileOpenL(const TFileName& aFileName)
158 Document()->DoFileOpenL(aFileName,EFileWrite);
159 iRichEd->ResetUndo();
160 iRichEd->SetBookmark();
161 iEikonEnv->UpdateTaskNameL();
162 HandleModelChangeL();
166 void CWordAppUi::CmdFileSaveL()
167 // Ascertain whether the document should be saved.
168 // If so, then save; otherwise do nothing.
170 {DoFileSaveL(ETrue);}
173 void CWordAppUi::DoFileSaveL(TBool aEchoFileSaved)
174 // If the current document has changed, then save it.
175 // An info message confirmation is only required when not running as embedded.
178 if (iRichEd->IsReadOnly())
179 return; // all changes are lost - allow print model etc.. to be changed.
182 __ASSERT_DEBUG(iDocument->AppFileMode()&EFileWrite,Panic(EWordSaveReadOnlyFile));
184 iRichEd->SetBookmark();
185 if (!iContainerAppUi && aEchoFileSaved)
186 iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED);
191 iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED);
196 void CWordAppUi::CmdFileSaveAsL()
199 SetInitialPathL(fileName);
200 CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&fileName,NULL,NULL);
201 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
203 if (Document()->FileNameExists(fileName))
209 if (!iEikonEnv->FsSession().Entry(fileName,entry))
210 User::LeaveIfError(iEikonEnv->FsSession().Delete(fileName));
211 Document()->DoFileSaveToNewL(fileName);
212 iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED);
213 // set the filename label to read correctly
214 iEikonEnv->UpdateTaskNameL();
215 UpdateFileNameLabelL();
217 iRichEd->SetBookmark();
222 void CWordAppUi::CmdFileRevertL()
226 if (ConfirmationDialogL(ERevertTitle,ERevertText))
228 Document()->DoFileRevertL();
230 HandleModelChangeL()); // resets document to not saved yet.
232 {// Just clear the screen cos we have new content but cannot draw it.
233 CWindowGc& gc=iEikonEnv->SystemGc();
234 gc.Activate(*iRichEd->DrawableWindow());
235 gc.Clear(iRichEd->TextView()->ViewRect());
239 Document()->SetChanged(EFalse);
240 iRichEd->ResetUndo();
241 iRichEd->SetBookmark();
245 iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED);
248 void CWordAppUi::CmdFileSaveAsTemplateL()
251 CEikDialog* dialog=new(ELeave) CWordSaveAsTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
252 if (dialog->ExecuteLD(R_WORD_TEMPLATE_SAVE_AS))
254 iEikonEnv->BusyMsgL(R_WORD_TEMPLATE_SAVING_FILE,KFileBusyInitialDelayInMicroSeconds);
256 parse.Set(filename,NULL,NULL);
257 if (!EikFileUtils::FolderExists(parse.DriveAndPath()))
258 iEikonEnv->FsSession().MkDirAll(parse.DriveAndPath());
259 if(ConeUtils::FileExists(filename))
260 iEikonEnv->FsSession().Delete(filename);
261 Document()->DoFileSaveToNewNoSwitchL(filename);
262 iEikonEnv->BusyMsgCancel();
263 TFileName file = parse.Name(); // can CEikUnifiedFileNameSelector has guaranteed the extra will fit
265 iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_PRE_DRIVE);
267 file.Append(parse.Drive()[0]);
268 iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_POST_DRIVE);
270 iEikonEnv->ReadResource(msg,R_WORD_TEMPLATE_SAVED_MESSAGE);
271 TBuf<KMaxTemplateMsgLen> fullmsg;
272 fullmsg.Format(msg,&file);
273 iEikonEnv->InfoMsg(fullmsg);
277 void CWordAppUi::CmdFileDeleteTemplateL()
279 TFileName filename=NormalTemplateFileNameL();
280 CEikDialog* dialog=new(ELeave) CWordDeleteTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
281 if (dialog->ExecuteLD(R_WORD_TEMPLATE_DELETE))
283 if (filename.Length())
284 iEikonEnv->FsSession().Delete(filename);
288 void CWordAppUi::CmdFileTextImportL()
290 TFileName filename=CurrentFilePath();
291 CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_TEXT_IMPORT_DIALOG_TITLE);
292 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
294 iCoeEnv->WsSession().Flush(); // !! check this out
295 iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds);
296 iRichEd->InsertFromTextFileL(filename,CPlainText::EOrganiseByParagraph);
297 SetPaginationOutOfDate(ETrue);
299 iEikonEnv->BusyMsgCancel();
304 void CWordAppUi::CmdFileTextExportL()const
306 TFileName filename=CurrentFilePath();
307 filename.Append(_L(".txt"));
308 ConeUtils::EnsurePathExistsL(filename);
309 CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&filename,NULL,R_WORD_TEXT_EXPORT_DIALOG_TITLE);
310 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
312 iEikonEnv->BusyMsgL(R_EIK_TBUF_EXPORTING,KFileBusyInitialDelayInMicroSeconds);
313 Text()->ExportAsTextL(filename,CPlainText::EOrganiseByParagraph,KExportTextWrapWidth);
314 iEikonEnv->BusyMsgCancel();
318 void CWordAppUi::CmdFileHtmlImportL()
320 TFileName filename=CurrentFilePath();
321 CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_HTML_IMPORT_DIALOG_TITLE);
322 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
324 iCoeEnv->WsSession().Flush();
325 iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds);
326 iRichEd->InsertFromHtmlFileL(filename);
327 SetPaginationOutOfDate(ETrue);
329 iEikonEnv->BusyMsgCancel();