GetResourceString() public static method

Return a string from a resource ID.
public static GetResourceString ( string stid ) : string
stid string String resource id
return string
Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the m_btnImport control.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void m_btnImport_Click(object sender, EventArgs e)
        {
            if (!File.Exists(m_tbFilename.Text))
            {
                // "{0} does not exist!"
                string sFmt = TeResourceHelper.GetResourceString("kstidImportXmlNotAFile");
                string sMsg = String.Format(sFmt, m_tbFilename.Text);
                // "Warning"
                string sCaption = TeResourceHelper.GetResourceString("kstidImportXmlWarning");
                MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (VerifyLanguageInOxesFile() && EnsureProperOxesFile())
            {
                string validationErrors = Validator.GetAnyValidationErrors(m_tbFilename.Text);
                if (validationErrors == null)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    DisplayImportError(SUE_ErrorCode.OxesValidationFailed, null, null, validationErrors);
                }
            }
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Load the Paratext project and enumerator, preparing us to read the data files.
        /// </summary>
        /// <param name="paratextProjectId">3-letter Paratext project ID</param>
        /// <returns>true if the project was loaded, else false</returns>
        /// ------------------------------------------------------------------------------------
        protected virtual void LoadParatextProject(string paratextProjectId)
        {
            try
            {
                m_ptProjectText = ScriptureProvider.MakeScrText(paratextProjectId);
            }
            catch (Exception e)
            {
                // Can't load Paratext project if Paratext is not installed.
                throw new ParatextLoadException(
                          TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e);
            }

            try
            {
                // create ref objs of the Paratext lib
                Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " +
                                  m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString);

                // Now initialize the TextEnum with the range of Scripture text we want
                m_ptParser   = m_ptProjectText.Parser;
                m_ptCurrBook = ScriptureProvider.MakeVerseRef(m_settings.StartRef.Book, 0, 0);
                ResetParatextState();
            }
            catch (Exception e)
            {
                string msg = string.Format(
                    TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"),
                    paratextProjectId);
                throw new ParatextLoadException(msg, e);
            }
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportUsfmDialog"/> class.
        /// </summary>
        /// <param name="cache">database cache</param>
        /// <param name="filter">book filter to display which books we will export</param>
        /// <param name="appKey">location of registry</param>
        /// <param name="markup">type of markup format for export:
        /// Paratext (one domain, non-interleaved) OR Toolbox (optionally interleaved)</param>
        /// ------------------------------------------------------------------------------------
        public ExportUsfmDialog(FdoCache cache, FilteredScrBooks filter, RegistryKey appKey,
                                MarkupType markup) : this()
        {
            m_cache      = cache;
            m_markupType = markup;          // let dialog know if this is for Paratext or Toolbox
            if (appKey != null)             // might be null in tests - in this case derived class has to provide a m_regGroup
            {
                m_regGroup = new RegistryGroup(appKey, "ExportUsfmSettings");
            }

            // Display books and markup labels
            string filtered = (filter.AllBooks ? TeResourceHelper.GetResourceString("kstidExportDlgUnfiltered") :
                               TeResourceHelper.GetResourceString("kstidExportDlgFiltered"));
            string booksToExport = GetExportedBooksStr(filter);

            if (filter.BookCount == 1)
            {
                lblBooks.Text = string.Format(TeResourceHelper.GetResourceString("kstidBooksToExportSingularForm"),
                                              filtered, booksToExport);
            }
            else
            {
                lblBooks.Text = string.Format(lblBooks.Text, filter.BookCount, filtered, booksToExport);
            }
        }
Ejemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FilesOverwriteDialog"/> class.
        /// </summary>
        /// <param name="filename">name of the file that may be overwritten</param>
        /// ------------------------------------------------------------------------------------
        public FilesOverwriteDialog(string filename)
        {
            InitializeComponent();

            this.Text        = TeResourceHelper.GetResourceString("kstidApplicationName");
            lblFilename.Text = filename;
        }
Ejemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a string that describes the Scripture passage based on the selection.
        /// </summary>
        /// <param name="tag">The flid of the selected element</param>
        /// <param name="hvoSel">The hvo of the selected element, either a ScrSection (usually)
        /// or ScrBook (if in a title)</param>
        /// <param name="fSimpleFormat">Gets a simple, standardized reference (uses SIL 3-letter
        /// codes and no verse bridges)</param>
        /// <returns>
        /// String that describes the Scripture passage or null if the selection
        /// can't be interpreted as a book and/or section reference.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override string GetPassageAsString(int tag, int hvoSel, bool fSimpleFormat)
        {
            CheckDisposed();

            if (m_cache == null)
            {
                return(null);
            }

            string sEditRef = null;             // Title/reference/etc of text being edited in the draft pane

            switch (tag)
            {
            case (int)ScrBook.ScrBookTags.kflidFootnotes:
            {
                ScrBook book = new ScrBook(m_cache, hvoSel, false, false);
                sEditRef = (fSimpleFormat ? (book.BookId + " 0:0") : book.BestUIName);
                break;
            }

            default:
                return(base.GetPassageAsString(tag, hvoSel, fSimpleFormat));
            }

            // Add the back translation writing system info to the output string, if needed
            if (IsBackTranslation)
            {
                LgWritingSystem ws = new LgWritingSystem(m_cache, ViewConstructorWS);
                sEditRef = string.Format(
                    TeResourceHelper.GetResourceString("kstidCaptionInBackTrans"),
                    sEditRef, ws.Name.UserDefaultWritingSystem);
            }

            return(string.IsNullOrEmpty(sEditRef) ? null : sEditRef);
        }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Throws an exception. Release mode overrides the message.
        /// </summary>
        /// <param name="message">The message to display (in debug mode)</param>
        /// <param name="e">Optional inner exception</param>
        /// ------------------------------------------------------------------------------------
        static protected void ReportInvalidInstallation(string message, Exception e)
        {
#if !DEBUG
            message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
            throw new Exception(message, e);
        }
Ejemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when the user pressed the cancel button on the progress dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void OnCancelPressed(object sender, CancelEventArgs e)
        {
            CheckDisposed();
            Debug.Assert(!m_ctrl.InvokeRequired);

            try
            {
                // pause the import thread, while we ask if they really want to cancel
                m_importer.Pause();
                if (m_importer.PrevBook != null)
                {
                    string sMsg = string.Format(TeResourceHelper.GetResourceString("kstidConfirmStopImport"),
                                                m_importer.PrevBook);

                    if (MessageBox.Show(sMsg, FwUtils.ksTeAppName,
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        // the user does not wish to cancel the import, so cancel the event
                        e.Cancel = true;
                        return;
                    }
                }
                //Display "stopping" message in progress bar
                m_progressDialog.Message  = TeResourceHelper.GetResourceString("kstidStoppingImport");
                m_progressDialog.Position = m_progressDialog.Maximum;
            }
            finally
            {
                // resume the import thread
                m_importer.Resume();
            }
        }
Ejemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="BookPropertiesDialog"/> class.
        /// </summary>
        /// <param name="book">the current book</param>
        /// <param name="stylesheet">The stylesheet.</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// ------------------------------------------------------------------------------------
        public BookPropertiesDialog(IScrBook book, IVwStylesheet stylesheet, IHelpTopicProvider helpTopicProvider)
        {
            m_currentBook       = book;
            m_helpTopicProvider = helpTopicProvider;
            // TE-5663: make sure the book's name and abbreviation are updated if some were added
            IScrRefSystem scrRefSystem = book.Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().AllInstances().FirstOrDefault();

            book.Name.MergeAlternatives(scrRefSystem.BooksOS[book.CanonicalNum - 1].BookName);
            book.Abbrev.MergeAlternatives(scrRefSystem.BooksOS[book.CanonicalNum - 1].BookAbbrev);

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Put the book name in the dialog caption
            Text = string.Format(Text, book.Name.UserDefaultWritingSystem.Text);

            m_listBookInfo.Cache = book.Cache;
            m_listBookInfo.FieldsToDisplay.Add(new FwMultilingualPropView.ColumnInfo(
                                                   ScrBookTags.kflidName, TeResourceHelper.GetResourceString("kstidBookNameColHeader"), 60));
            m_listBookInfo.FieldsToDisplay.Add(new FwMultilingualPropView.ColumnInfo(
                                                   ScrBookTags.kflidAbbrev, TeResourceHelper.GetResourceString("kstidBookAbbrevColHeader"), 40));
            m_listBookInfo.RootObject = book.Hvo;

            foreach (IWritingSystem ws in book.Cache.ServiceLocator.WritingSystems.AllWritingSystems)
            {
                m_listBookInfo.WritingSystemsToDisplay.Add(ws.Handle);
            }

            // Initialize the ID textbox.
            m_txtScrBookIdText.Text = m_currentBook.IdText;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a string that describes the Scripture passage based on the selection.
        /// </summary>
        /// <param name="tag">The flid of the selected element</param>
        /// <param name="hvoSel">The hvo of the selected element, either a ScrSection (usually)
        /// or ScrBook (if in a title)</param>
        /// <param name="fSimpleFormat">Gets a simple, standardized reference (uses SIL 3-letter
        /// codes and no verse bridges)</param>
        /// <returns>
        /// String that describes the Scripture passage or null if the selection
        /// can't be interpreted as a book and/or section reference.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override string GetPassageAsString(int tag, int hvoSel, bool fSimpleFormat)
        {
            CheckDisposed();

            if (m_cache == null)
            {
                return(null);
            }

            string sEditRef = null;             // Title/reference/etc of text being edited in the draft pane

            switch (tag)
            {
            case ScrBookTags.kflidFootnotes:
                IScrBook book =
                    m_cache.ServiceLocator.GetInstance <IScrBookRepository>().GetObject(hvoSel);
                sEditRef = (fSimpleFormat ? (book.BookId + " 0:0") : book.BestUIName);
                break;

            default:
                return(base.GetPassageAsString(tag, hvoSel, fSimpleFormat));
            }

            // Add the back translation writing system info to the output string, if needed
            if (IsBackTranslation)
            {
                IWritingSystem ws = m_cache.ServiceLocator.WritingSystemManager.Get(ViewConstructorWS);

                sEditRef = string.Format(
                    TeResourceHelper.GetResourceString("kstidCaptionInBackTrans"),
                    sEditRef, ws.DisplayLabel);
            }

            return(string.IsNullOrEmpty(sEditRef) ? null : sEditRef);
        }
Ejemplo n.º 10
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Complain if the context is not valid for the tool that is loading the styles.
 /// TE currently allows all but Flex's private context
 /// </summary>
 /// <returns></returns>
 /// ------------------------------------------------------------------------------------
 protected override void ValidateContext(ContextValues context, string styleName)
 {
     if (context == ContextValues.InternalConfigureView)
     {
         ReportInvalidInstallation(String.Format(TeResourceHelper.GetResourceString("ksInvalidStyleContext"),
                                                 styleName, context.ToString(), ResourceFileName));
     }
 }
Ejemplo n.º 11
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Throw an exception if the specified context is not valid for the specified paragraph
 /// style. TE overrides to forbid 'general' paragraph styles.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="styleName"></param>
 /// ------------------------------------------------------------------------------------
 protected override void ValidateParagraphContext(ContextValues context, string styleName)
 {
     if (context == ContextValues.General)
     {
         ReportInvalidInstallation(String.Format(TeResourceHelper.GetResourceString("ksInvalidParagraphStyleContext"),
                                                 styleName, context.ToString()));
     }
 }
Ejemplo n.º 12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SaveVersionDialog"/> class.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public SaveVersionDialog(FdoCache cache, IHelpTopicProvider helpTopicProvider)
        {
            m_cache             = cache;
            m_scr               = m_cache.LangProject.TranslatedScriptureOA;
            m_helpTopicProvider = helpTopicProvider;

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            if (m_cache == null)
            {
                return;
            }

            m_BooksToSave = new List <IScrBook>();
            m_treeView.BeginUpdate();

            List <TreeNode> otBooks = new List <TreeNode>();
            List <TreeNode> ntBooks = new List <TreeNode>();

            foreach (IScrBook book in m_scr.ScriptureBooksOS)
            {
                TreeNode node = new TreeNode(book.BestUIName);
                node.Tag = book;

                if (book.CanonicalNum < ScriptureTags.kiNtMin)
                {
                    otBooks.Add(node);                     // OT book
                }
                else
                {
                    ntBooks.Add(node);                     // NT book
                }
            }
            TreeNode bibleNode = new TreeNode(TeResourceHelper.GetResourceString("kstidBibleNode"));

            if (otBooks.Count > 0)
            {
                bibleNode.Nodes.Add(new TreeNode(TeResourceHelper.GetResourceString("kstidOtNode"),
                                                 otBooks.ToArray()));
            }
            if (ntBooks.Count > 0)
            {
                bibleNode.Nodes.Add(new TreeNode(TeResourceHelper.GetResourceString("kstidNtNode"),
                                                 ntBooks.ToArray()));
            }

            m_treeView.Nodes.Add(bibleNode);

            // REVIEW: once we have sections we probably don't want to expand below book level
            m_treeView.ExpandAll();
            m_treeView.EndUpdate();
            // update the ok button enabled state
            m_treeView_NodeCheckChanged(null, EventArgs.Empty);
        }
Ejemplo n.º 13
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Update the interleaved labels to reflect the current state of the check boxes.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void UpdateInterleavedLabels()
 {
     // If Scripture is checked, then mark back translation as interleaved
     chkBackTranslation.Text = m_defaultBtLabel;
     if (ExportScriptureDomain)
     {
         chkBackTranslation.Text += " " + TeResourceHelper.GetResourceString("kstidExportUSFMInterleavedLabel");
     }
 }
Ejemplo n.º 14
0
        /// -------------------------------------------------------------------------------------
        /// <summary>
        /// Create publications and header/footer sets (in the DB) from the given XML document.
        /// </summary>
        /// <remarks>tests are able to call this method</remarks>
        /// <param name="progressDlg">Progress dialog</param>
        /// <param name="rootNode">The XmlNode from which to read the publication info</param>
        /// -------------------------------------------------------------------------------------
        protected void SetNamesAndAbbreviations(IProgress progressDlg, XmlNode rootNode)
        {
            IScrRefSystem srs = m_cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton;

            Debug.Assert(srs != null && srs.BooksOS.Count == BCVRef.LastBook);

            XmlNodeList tagList = rootNode.SelectNodes("/ScrBookRef/writingsystem");

            progressDlg.Minimum  = 0;
            progressDlg.Maximum  = tagList.Count * BCVRef.LastBook;
            progressDlg.Position = 0;
            progressDlg.Title    = TeResourceHelper.GetResourceString("kstidCreatingBookNames");
            ITsStrFactory  tsf = m_cache.TsStrFactory;
            IWritingSystem ws;

            foreach (XmlNode writingSystem in tagList)
            {
                XmlAttributeCollection attributes = writingSystem.Attributes;
                string sWsTag = attributes.GetNamedItem("xml:lang").Value;
                m_cache.ServiceLocator.WritingSystemManager.GetOrSet(sWsTag, out ws);

                XmlNodeList WSBooks = writingSystem.SelectNodes("book");
                foreach (XmlNode book in WSBooks)
                {
                    XmlAttributeCollection bookAttributes = book.Attributes;
                    string sSilBookId = bookAttributes.GetNamedItem("SILBookId").Value;
                    Debug.Assert(sSilBookId != null);
                    int    nCanonicalBookNum = BCVRef.BookToNumber(sSilBookId);
                    string sName             = bookAttributes.GetNamedItem("Name").Value;
                    string sAbbrev           = bookAttributes.GetNamedItem("Abbreviation").Value;
                    string sAltName          = bookAttributes.GetNamedItem("AlternateName").Value;
                    progressDlg.Message = string.Format(
                        TeResourceHelper.GetResourceString("kstidCreatingBookNamesStatusMsg"), sName);
                    progressDlg.Step(0);

                    // check for the book id
                    IScrBookRef bookRef = srs.BooksOS[nCanonicalBookNum - 1];

                    int wsHandle = ws.Handle;
                    if (sName != null)
                    {
                        bookRef.BookName.set_String(wsHandle, tsf.MakeString(sName, wsHandle));
                    }
                    if (sAbbrev != null)
                    {
                        bookRef.BookAbbrev.set_String(wsHandle, tsf.MakeString(sAbbrev, wsHandle));
                    }
                    if (sAltName != null)
                    {
                        bookRef.BookNameAlt.set_String(wsHandle, tsf.MakeString(sAltName, wsHandle));
                    }
                }
            }
            // Finally, update resource version in database.
            SetNewResourceVersion(GetVersion(rootNode));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This must be called before starting import.
        /// </summary>
        public void StartImportingFiles()
        {
            Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler() != null);
            Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler().CurrentDepth == 0);
            m_hMark = m_cache.DomainDataByFlid.GetActionHandler().Mark();
            IActionHandler actionHandler = m_cache.ActionHandlerAccessor;

            actionHandler.BeginUndoTask("Create saved version", "Create saved version");
            m_backupVersion = GetOrCreateVersion(TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal"));
        }
Ejemplo n.º 16
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Fills in the versification system combo box
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void FillVersificationSchemes()
 {
     for (int iVers = 1; iVers <= 6; iVers++)
     {
         ScrVers vers = (ScrVers)iVers;
         m_cboVersification.Items.Add(TeResourceHelper.GetResourceString(
                                          "kstid" + vers.ToString() + "Versification"));
         if (m_scr.Versification == vers)
         {
             m_cboVersification.SelectedIndex = iVers - 1;
         }
     }
 }
Ejemplo n.º 17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Update the existing categories and terms with new localized strings.
        /// </summary>
        /// <param name="dlg">The progress dialog.</param>
        /// <param name="parameters">The parameters: 1) the BiblicalTermsLocalization object
        /// representing the contents of the XML file with the localized strings; 2) The ICU
        /// locale (string).</param>
        /// <returns>always null</returns>
        /// ------------------------------------------------------------------------------------
        protected object UpdateLocalization(IThreadedProgress dlg, params object[] parameters)
        {
            BiblicalTermsLocalization loc = (BiblicalTermsLocalization)parameters[0];
            string locale = (string)parameters[1];

            const int kcStepsToBuildLookupTable = 4;

            dlg.Position = 0;
            dlg.Minimum  = 0;
            dlg.Maximum  = loc.Categories.Count + loc.Terms.Count + kcStepsToBuildLookupTable;
            dlg.Title    = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBCaption");
            dlg.Message  = TeResourceHelper.FormatResourceString("kstidLoadKeyTermsLocalizations",
                                                                 m_wsf.get_Engine(locale).LanguageName);

            m_wsDefault = m_servLoc.WritingSystemManager.GetWsFromStr("en");

            int hvoLocWs = loc.WritingSystemHvo = m_wsf.GetWsFromStr(locale);

            IEnumerable <ICmPossibility> categories = ((ILangProject)m_scr.Owner).KeyTermsList.PossibilitiesOS;

            foreach (CategoryLocalization localizedCategory in loc.Categories)
            {
                ICmPossibility category = categories.FirstOrDefault(
                    p => p.Abbreviation.get_String(m_wsDefault).Text == localizedCategory.Id);
                if (category != null)
                {
                    category.Name.set_String(hvoLocWs, localizedCategory.Gloss);
                }
                dlg.Step(1);
            }

            Dictionary <int, IChkTerm> termLookupTable =
                m_servLoc.GetInstance <IChkTermRepository>().AllInstances().ToDictionary(t => t.TermId);

            dlg.Step(kcStepsToBuildLookupTable);

            IChkTerm term;
            string   message = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBStatus");

            foreach (TermLocalization localizedTerm in loc.Terms)
            {
                dlg.Message = string.Format(message, localizedTerm.Gloss);

                if (termLookupTable.TryGetValue(localizedTerm.Id, out term))
                {
                    SetLocalizedGlossAndDescription(term, localizedTerm, loc.WritingSystemHvo);
                }
                dlg.Step(1);
            }
            return(null);
        }
Ejemplo n.º 18
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Save results when closed.
 /// </summary>
 /// <param name="e">The <see cref="T:System.EventArgs"/> that contains the event data.</param>
 /// ------------------------------------------------------------------------------------
 protected override void OnClosed(EventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         using (new UndoRedoTaskHelper(m_draft.Cache,
                                       TeResourceHelper.GetResourceString("ksUndoDraftProperties"),
                                       TeResourceHelper.GetResourceString("ksRedoDraftProperties")))
         {
             m_draft.Protected   = m_cbProtected.Checked;
             m_draft.Description = m_tbDescription.Text;
         }
     }
     base.OnClosed(e);
 }
Ejemplo n.º 19
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Handle the Folder browse button to locate a folder to write to.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected virtual void btnFolderBrowse_Click(object sender, System.EventArgs e)
 {
     using (FolderBrowserDialog dlg = new FolderBrowserDialog())
     {
         dlg.SelectedPath        = BaseOutputFolder;
         dlg.Description         = TeResourceHelper.GetResourceString(StidExportDlgFolderBrowserPrompt);
         dlg.ShowNewFolderButton = true;
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             BaseOutputFolder      = dlg.SelectedPath;
             m_fUserModifiedFolder = true;
         }
     }
 }
Ejemplo n.º 20
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Handles the NodeMouseClick event of the m_treeArchives control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.Windows.Forms.TreeNodeMouseClickEventArgs"/>
 /// instance containing the event data.</param>
 /// ------------------------------------------------------------------------------------
 private void m_treeArchives_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         TreeNode node = e.Node;
         if (node == null || !(node.Tag is IScrDraft))
         {
             return;
         }
         m_treeArchives.SelectedNode = node;
         ContextMenuStrip menu = new ContextMenuStrip();
         menu.Items.Add(new ToolStripMenuItem(TeResourceHelper.GetResourceString("kstidProperties"), null,
                                              new EventHandler(propertiesClick)));
         menu.Show(m_treeArchives, e.Location);
     }
 }
Ejemplo n.º 21
0
        /// -------------------------------------------------------------------------------------
        /// <summary>
        /// Perform one-time initialization of a new Scripture project
        /// </summary>
        /// <returns>true if data loaded successfully; false, otherwise</returns>
        /// -------------------------------------------------------------------------------------
        protected bool Initialize(IFwSplashScreen splashScreen)
        {
            ILangProject lp = m_cache.LangProject;

            if (m_scr != null)
            {
                // Preload all book, section and paragraphs if we already have Scripture
                PreloadData(m_cache, splashScreen);

                if (m_scr.BookAnnotationsOS.Count != 0 &&
                    m_cache.ScriptureReferenceSystem.BooksOS.Count != 0 && m_scr.PublicationsOC.Count != 0 &&
                    lp.KeyTermsList.PossibilitiesOS.Count >= 1 &&
                    m_scr.NoteCategoriesOA != null && m_scr.NoteCategoriesOA.PossibilitiesOS.Count > 0)
                {
                    return(true);
                }
            }

            IAdvInd4 existingProgressDlg = null;

            if (splashScreen != null)
            {
                existingProgressDlg = splashScreen.ProgressBar as IAdvInd4;
            }

            using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(Form.ActiveForm))
            {
                try
                {
                    dlg.RunTask(existingProgressDlg, true, new BackgroundTaskInvoker(InitializeScriptureProject));
                }
                catch (WorkerThreadException e)
                {
                    UndoResult ures;
                    while (m_cache.Undo(out ures))
                    {
                        ;                                                // Enhance JohnT: make use of ures?
                    }
                    MessageBox.Show(Form.ActiveForm, e.InnerException.Message,
                                    TeResourceHelper.GetResourceString("kstidApplicationName"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Save results when closed.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> that contains the event data.</param>
        /// ------------------------------------------------------------------------------------
        protected override void OnClosed(EventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper(
                           m_draft.Cache.ServiceLocator.GetInstance <IActionHandler>(),
                           TeResourceHelper.GetResourceString("ksUndoDraftProperties"),
                           TeResourceHelper.GetResourceString("ksRedoDraftProperties")))
                {
                    m_draft.Protected   = m_cbProtected.Checked;
                    m_draft.Description = m_tbDescription.Text;

                    undoHelper.RollBack = false;
                }
            }
            base.OnClosed(e);
        }
Ejemplo n.º 23
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the invalid path character.
        /// </summary>
        /// <param name="textbox">The textbox containing a directory or file name.</param>
        /// <param name="iInvalidChar">The character index of the invalid character in the
        /// textbox.</param>
        /// ------------------------------------------------------------------------------------
        protected void HandleInvalidPathChar(TextBox textbox, int iInvalidChar)
        {
            toolTipInvalidChar.Active = false;
            // Remove the invalid character
            textbox.Text = textbox.Text.Remove(iInvalidChar, 1);

            // Reset selection in textbox so it doesn't move back to the start of the output file name.
            textbox.SelectionStart = iInvalidChar < textbox.Text.Length - 1 ?
                                     iInvalidChar : iInvalidChar - 1;

            // Display a tooltip with a list of invalid path characters
            string msg = string.Format(TeResourceHelper.GetResourceString("kstidInvalidPathCharToolTip"),
                                       InvalidPathCharString);

            toolTipInvalidChar.Active = true;
            toolTipInvalidChar.SetToolTip(textbox, msg);             // Seems dumb to have this here, but without it, the first time, the tooltip displays wrong.
            toolTipInvalidChar.Show(msg, textbox, textbox.Width / 2, textbox.Height, 5000);
        }
Ejemplo n.º 24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UndoImportInfo"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="bookFilter">The book filter.</param>
        /// ------------------------------------------------------------------------------------
        public UndoImportManager(FdoCache cache, FilteredScrBooks bookFilter)
        {
            m_cache      = cache;
            m_bookFilter = bookFilter;
            m_scr        = m_cache.LangProject.TranslatedScriptureOA;

            Debug.Assert(m_cache.ActionHandlerAccessor != null);
            Debug.Assert(m_cache.ActionHandlerAccessor.CurrentDepth == 0);
            m_hMark = m_cache.ActionHandlerAccessor.Mark();
            IActionHandler actionHandler = m_cache.ActionHandlerAccessor;

            m_suppressor = new SuppressSubTasks(m_cache);             // don't need to undo setting properties.
            // Create new archive for saving backup versions of imported book
            m_savedVersion = new ScrDraft();
            m_scr.ArchivedDraftsOC.Add(m_savedVersion);
            actionHandler.AddAction(new UndoImportObjectAction(m_savedVersion));
            m_savedVersion.Description =
                TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal");
        }
Ejemplo n.º 25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when the user pressed the cancel button on the progress dialog.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// ------------------------------------------------------------------------------------
        private void OnCancelPressed(object sender)
        {
            Debug.Assert(!m_ctrl.InvokeRequired);

            //Display "stopping" message in progress bar
            if (m_importer.PrevBook != null)
            {
                string sMsg = string.Format(TeResourceHelper.GetResourceString("kstidConfirmStopImport"),
                                            m_importer.PrevBook);

                if (MessageBox.Show(m_progressDialog.OwnerForm, sMsg,
                                    TeResourceHelper.GetResourceString("kstidApplicationName"),
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }
            m_progressDialog.StatusMessage = TeResourceHelper.GetResourceString("kstidStoppingImport");
            m_progressDialog.Position      = m_progressDialog.Maximum;
            m_fCancel = true;
        }
Ejemplo n.º 26
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a string of book names in the filter.
        /// </summary>
        /// <param name="filter">book filter</param>
        /// <returns>string with comma-delimited list of books in the filter</returns>
        /// ------------------------------------------------------------------------------------
        private string GetExportedBooksStr(FilteredScrBooks filter)
        {
            StringBuilder filteredBooks = new StringBuilder();

            if (filter.BookCount > 3)
            {
                return(string.Empty);
            }

            // Append all scripture books in filter to string
            for (int bookIndex = 0; bookIndex < filter.BookCount; bookIndex++)
            {
                if (bookIndex > 0)
                {
                    filteredBooks.Append(", ");
                }
                filteredBooks.Append(((ScrBookRef)filter.GetBook(bookIndex).BookIdRA).UIBookName);
            }

            return(string.Format(TeResourceHelper.GetResourceString("kstidExportDlgMultipleBooks"),
                                 filteredBooks.ToString()));
        }
Ejemplo n.º 27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets all the available Key Terms localizations.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected virtual List <BiblicalTermsLocalization> GetLocalizations()
        {
            int defaultUserWs = m_scr.Cache.DefaultUserWs;

            string[] locFiles = FwDirectoryFinder.KeyTermsLocalizationFiles;
            List <BiblicalTermsLocalization> localizations =
                new List <BiblicalTermsLocalization>(locFiles.Length);
            bool fFoundDefaultLoc = false;

            foreach (string localizationFile in locFiles)
            {
                int hvoWs = GetWsFromLocFile(m_wsf, localizationFile);
                if (hvoWs > 0)
                {
                    BiblicalTermsLocalization loc = DeserializeBiblicalTermsLocFile(localizationFile);
                    if (loc != null)
                    {
                        fFoundDefaultLoc    |= (hvoWs == defaultUserWs);
                        loc.WritingSystemHvo = hvoWs;
                        localizations.Add(loc);
                    }
                }
            }
            if (!fFoundDefaultLoc || localizations.Count == 0)
            {
                string icuLocale = m_wsf.GetStrFromWs(defaultUserWs);
                string message   = String.Format("File {0} is missing", FwDirectoryFinder.GetKeyTermsLocFilename(icuLocale));
                Debug.Fail(message);
                Logger.WriteEvent(message);
                if (icuLocale == "en" || localizations.Count == 0)
                {
#if !DEBUG
                    message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
                    throw new InstallationException(message, null);
                }
            }
            return(localizations);
        }
Ejemplo n.º 28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deserializes the biblical terms file.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns>a BiblicalTermsList object</returns>
        /// ------------------------------------------------------------------------------------
        static protected BiblicalTermsList DeserializeBiblicalTermsFile(string filename)
        {
            try
            {
                using (TextReader reader = new StreamReader(filename))
                {
                    XmlSerializer     deserializer = new XmlSerializer(typeof(BiblicalTermsList));
                    BiblicalTermsList data         = (BiblicalTermsList)deserializer.Deserialize(reader);
                    reader.Close();
                    return(data);
                }
            }
            catch (Exception e)
            {
                string message;
#if DEBUG
                message = "Error reading " + filename + ": file is missing or has invalid XML syntax.";
#else
                message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
                throw new InstallationException(message, e);
            }
        }
Ejemplo n.º 29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Load the Paratext project and enumerator, preparing us to read the data files.
        /// </summary>
        /// <param name="paratextProjectId">3-letter Paratext project ID</param>
        /// <returns>true if the project was loaded, else false</returns>
        /// ------------------------------------------------------------------------------------
        protected virtual void LoadParatextProject(string paratextProjectId)
        {
            try
            {
                m_scParatextText        = new SCRIPTUREOBJECTSLib.SCScriptureTextClass();
                m_scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass();
            }
            catch (Exception e)
            {
                // Can't load Paratext project if Paratext is not installed.
                throw new ParatextLoadException(
                          TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e);
            }

            try
            {
                m_scParatextText.Load(paratextProjectId);
                // create ref objs of the Paratext lib
                SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference();
                SCRIPTUREOBJECTSLib.SCReference endRefPT   = new SCRIPTUREOBJECTSLib.SCReference();
                startRefPT.Parse(m_settings.StartRef.AsString);
                endRefPT.Parse(m_settings.EndRef.AsString);

                // Now initialize the TextEnum with the range of scripture text we want
                m_scParatextTextEnum = m_scParatextText.TextEnum(startRefPT, endRefPT,
                                                                 (SCRIPTUREOBJECTSLib.SCTextType) 0, //scTitle | scSection | scVerseText | scNoteText | scOther)
                                                                 (SCRIPTUREOBJECTSLib.SCTextProperties) 0);
            }
            catch (Exception e)
            {
                string msg = string.Format(
                    TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"),
                    paratextProjectId);
                throw new ParatextLoadException(msg, e);
            }
        }
Ejemplo n.º 30
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ExportXmlDialog"/> class.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ExportXmlDialog(FdoCache cache, FilteredScrBooks filter, int defaultBookNum,
                               IVwStylesheet stylesheet, FileType exportType, IHelpTopicProvider helpTopicProvider)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            m_helpTopicProvider = helpTopicProvider;
            m_scr         = cache.LangProject.TranslatedScriptureOA;
            m_eExportType = exportType;

            string key;
            string descriptionFmt = "kstidOxesExportDescription";

            switch (m_eExportType)
            {
            case FileType.XHTML:
                Text = TeResourceHelper.GetResourceString("kstidExportXHTML");                         // "Export XHTML"
                key  = "ExportFolderForXhtml";
                break;

            case FileType.ODT:
                Text = TeResourceHelper.GetResourceString("kstidExportODT");                         // "Export Open Office file"
                key  = "ExportFolderForXhtml";
                break;

            case FileType.PDF:
                Text = TeResourceHelper.GetResourceString("kstidExportPDF");                         // "Export Adobe Portable Document"
                key  = "ExportFolderForXhtml";
                break;

            case FileType.OXEKT:
                Text = TeResourceHelper.GetResourceString("kstidExportOXEKT");                         // "Export Open XML for Exchanging Key Terms"
                m_lblExportWhat.Text = TeResourceHelper.GetResourceString("kstidExportWhatOXEKT");
                key            = "ExportFolderForXml";
                descriptionFmt = "kstidOxektExportDescription";
                break;

            case FileType.OXES:
            default:
                key = "ExportFolderForXml";
                break;
            }

            m_xmlFolder = new RegistryStringSetting(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                                    key, FwSubKey.TE);
            string fileName = m_xmlFolder.Value;

            m_fileDialog = new TeImportExportFileDialog(cache.ProjectId.Name, m_eExportType);

            // Append a filename if it was set to just a directory
            if (Directory.Exists(fileName))
            {
                fileName = Path.Combine(fileName, m_fileDialog.DefaultFileName);
            }
            m_txtOutputFile.Text = fileName;
            // Ensure that the end of the filename is visible.
            m_txtOutputFile.Select(fileName.Length, 0);

            FillFilterListLabel(filter);

            // Set the single book from the current one in use if possible, otherwise set
            // it from the first available book, if any are available.
            if (defaultBookNum < 1 || defaultBookNum > BCVRef.LastBook)
            {
                defaultBookNum = 1;
                if (m_scr.ScriptureBooksOS.Count > 0)
                {
                    defaultBookNum = m_scr.ScriptureBooksOS[0].CanonicalNum;
                }
            }

            m_scrBook.Initialize(defaultBookNum, m_scr.ScriptureBooksOS.Select(b => b.CanonicalNum).ToArray());
            m_scrBook.PassageChanged += m_scrBook_PassageChanged;

            // Initialize the combo boxes, and then adjust their heights (and the locations
            // of following controls) as needed.
            m_oldComboHeight = cboFrom.Height;
            m_gap            = cboTo.Top - cboFrom.Bottom;
            m_fntVern        = ((FwStyleSheet)stylesheet).GetUiFontForWritingSystem(
                cache.DefaultVernWs, FontInfo.kDefaultFontSize);
            cboFrom.Font = cboTo.Font = m_fntVern;

            // Now that the sizes are fixed, load the combo box lists.
            LoadSectionsForBook(defaultBookNum);

            m_nBookForSections = defaultBookNum;
            m_sRangeBookFmt    = m_grpSectionRange.Text;
            UpdateBookSectionGroupLabel();

            //m_scrBook.Enabled = false;
            //m_grpSectionRange.Enabled = false;
            m_grpSectionRange.Visible = true;

            // Initialize the description.
            DateTime now = DateTime.Now;

            // "{0} exported by {1} on {2} {3}, {4} at {5}"
            m_txtDescription.Text = String.Format(DlgResources.ResourceString(descriptionFmt),
                                                  cache.ProjectId.Name,
                                                  System.Security.Principal.WindowsIdentity.GetCurrent().Name.Normalize(),
                                                  now.ToString("MMMM"), now.Day, now.Year, now.ToShortTimeString());

            // TODO: Set export type from the stored registry setting.
        }