Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        private bool Export(string fmtFileName, string fileTypeFilter, string defaultFileType,
                            bool openAfterExport, Func <PaProject, string, PaWordListGrid, bool, bool> exportAction)
        {
            if (!m_activeView)
            {
                return(false);
            }

            var defaultFileName = string.Format(fmtFileName,
                                                PaProject.GetCleanNameForFileName(Project.LanguageName));

            var fileTypes = fileTypeFilter + "|" + App.kstidFileTypeAllFiles;

            int filterIndex    = 0;
            var outputFileName = App.SaveFileDialog(defaultFileType, fileTypes, ref filterIndex,
                                                    App.kstidSaveFileDialogGenericCaption, defaultFileName, Project.Folder);

            if (string.IsNullOrEmpty(outputFileName))
            {
                return(false);
            }

            exportAction(Project, outputFileName, WordListGrid, openAfterExport);
            return(true);
        }
        /// ------------------------------------------------------------------------------------
        private string GetSuggestedTargetFolder(int index)
        {
            var prjName    = PaProject.GetCleanNameForFileName(AvailableBackups[index].Key);
            var backupFile = AvailableBackups[index].Value;

            var folder = Path.Combine(App.ProjectFolder, prjName);

            if (!Directory.Exists(folder) || Directory.GetFiles(folder, "*.pap").Length == 0)
            {
                return(folder);
            }

            folder = Path.Combine(App.ProjectFolder, Path.GetFileNameWithoutExtension(backupFile));
            if (!Directory.Exists(folder) || Directory.GetFiles(folder, "*.pap").Length == 0)
            {
                return(folder);
            }

            int i = 2;

            do
            {
                folder = Path.Combine(App.ProjectFolder, string.Format("{0} ({1})", prjName, i++));
            }while (Directory.Exists(folder) && Directory.GetFiles(folder, "*.pap").Length > 0);
            return(folder);
        }
        /// ------------------------------------------------------------------------------------
        private string GetExportFileName(string fmtFileName, string fileTypeFilter, string defaultFileType)
        {
            if (!_activeView)
            {
                return(null);
            }

            var defaultOutputFileName = string.Format(fmtFileName,
                                                      PaProject.GetCleanNameForFileName(Project.LanguageName));

            var fileTypes = fileTypeFilter + "|" + App.kstidFileTypeAllFiles;

            int filterIndex = 0;

            return(App.SaveFileDialog(defaultFileType, fileTypes, ref filterIndex,
                                      App.kstidSaveFileDialogGenericCaption, defaultOutputFileName, Project.Folder));
        }
        /// ------------------------------------------------------------------------------------
        private bool GetProjectFolderAndCreateIfNecessary(out string prjFileName, out string prjFolder)
        {
            prjFileName = (txtProjName.Text.Trim() == string.Empty ? Project.Name : txtProjName.Text.Trim());
            prjFileName = PaProject.GetCleanNameForFileName(prjFileName);

            if (!_chkMakeFolder.Checked)
            {
                prjFolder = (Properties.Settings.Default.LastFolderForSavedProject ?? string.Empty);
                if (!Directory.Exists(prjFolder))
                {
                    prjFolder = App.ProjectFolder;
                }

                return(false);
            }

            var preferredProjectFileName = prjFileName;

            prjFolder = Path.Combine(App.ProjectFolder, prjFileName);

            if (Directory.Exists(prjFolder))
            {
                if (!Directory.GetFiles(prjFolder, "*.pap").Any())
                {
                    return(false);
                }

                int i = 2;
                while (Directory.Exists(prjFolder))
                {
                    prjFileName = string.Format("{0} ({1})", preferredProjectFileName, i++);
                    prjFolder   = Path.Combine(App.ProjectFolder, prjFileName);
                }
            }

            Directory.CreateDirectory(prjFolder);
            return(true);
        }