/// <summary> /// Generates an email with the <paramref name="topMessage">topMessage</paramref> if the launch count = <paramref name="noLaunches">noLaunches</paramref>. /// </summary> /// <param name="emailAddress">email address to send report to</param> /// <param name="topMessage">Message for report</param> /// <param name="noLaunches">number of launches at which report should be generated.</param> public static void UsageReport(string emailAddress, string topMessage, int noLaunches) { int launchCount = int.Parse(Utils.UsageEmailDialog.RegistryAccess.GetStringRegistryValue(utilityLabel, "0")); if (launchCount == noLaunches) { // Set the Application label to the name of the app Assembly assembly = Assembly.GetExecutingAssembly(); IExporter exporter = DynamicLoader.CreateObject("PsExport.dll", "SIL.PublishingSolution.PsExport") as IExporter; if (exporter != null) { assembly = exporter.GetType().Assembly; } string version = Application.ProductVersion; if (assembly != null) { object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); version = (attributes != null && attributes.Length > 0) ? ((AssemblyFileVersionAttribute)attributes[0]).Version : Application.ProductVersion; } string emailSubject = string.Format("{0} {1} Report {2} Launches", utilityLabel, version, launchCount); string emailBody = string.Format("<report app='{0}' version='{1}'><stat type='launches' value='{2}'/></report>", utilityLabel, version, launchCount); string body = emailBody.Replace(Environment.NewLine, "%0A").Replace("\"", "%22").Replace("&", "%26"); Process p = new Process(); p.StartInfo.FileName = String.Format("mailto:{0}?subject={1}&body={2}", emailAddress, emailSubject, body); p.Start(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the ChooseScriptureDialog class. /// WARNING: this constructor is called by reflection, at least in the Interlinear /// Text DLL. If you change its parameters be SURE to find and fix those callers also. /// </summary> /// <param name="cache">The cache.</param> /// <param name="objList">A list of texts and books to check as an array of hvos</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// <param name="importer">The Paratext book importer.</param> /// ------------------------------------------------------------------------------------ public FilterTextsDialogTE(FdoCache cache, IStText[] objList, IHelpTopicProvider helpTopicProvider, IBookImporter importer) : base(cache, objList, helpTopicProvider) { m_bookImporter = importer; using (var progressDlg = new ProgressDialogWithTask(this)) { // This somewhat duplicates some logic in FieldWorks.GetHelpTopicProvider, but it feels // wrong to reference the main exe even though I can't find an actual circular dependency. // As far as I can discover, the help topic provider is only used if the user has modified // TE styles and TE needs to display a dialog about it (possibly because it has loaded a // new version of the standard ones?). Anyway, I don't think it will be used at all if TE // is not installed, so it should be safe to use the regular FLEx one. IHelpTopicProvider helpProvider; if (FwUtils.FwUtils.IsTEInstalled) { helpProvider = (IHelpTopicProvider)DynamicLoader.CreateObject(FwDirectoryFinder.TeDll, "SIL.FieldWorks.TE.TeHelpTopicProvider"); } else { helpProvider = (IHelpTopicProvider)DynamicLoader.CreateObject(FwDirectoryFinder.FlexDll, "SIL.FieldWorks.XWorks.LexText.FlexHelpTopicProvider"); } NonUndoableUnitOfWorkHelper.Do(cache.ActionHandlerAccessor, () => TeScrInitializer.EnsureMinimalScriptureInitialization(cache, progressDlg, helpProvider)); } }
/// <summary> /// Used to launch various import dialogs, but could do other things /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnLaunchConnectedDialog(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; System.Xml.XmlNode first = command.Parameters[0]; System.Xml.XmlNode classInfo = first.SelectSingleNode("dynamicloaderinfo"); Form formActive = ActiveForm; FwXWindow wndActive = formActive as FwXWindow; IFwExtension dlg = null; try { try { dlg = (IFwExtension)DynamicLoader.CreateObject(classInfo); } catch (Exception error) { string message = XmlUtils.GetOptionalAttributeValue(classInfo, "notFoundMessage", null); // Make this localizable! if (message != null) { throw new ApplicationException(message, error); } } var oldWsUser = Cache.WritingSystemFactory.UserWs; dlg.Init(Cache, wndActive.Mediator); DialogResult dr = ((Form)dlg).ShowDialog(ActiveForm); if (dr == DialogResult.OK) { if (dlg is LexOptionsDlg) { LexOptionsDlg loDlg = dlg as LexOptionsDlg; if ((oldWsUser != Cache.WritingSystemFactory.UserWs) || loDlg.PluginsUpdated) { ReplaceMainWindow(wndActive); } } else if (dlg is LinguaLinksImportDlg || dlg is InterlinearImportDlg || dlg is LexImportWizard || dlg is NotebookImportWiz || dlg is LiftImportDlg) { // Make everything we've imported visible. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } } finally { if (dlg != null && dlg is IDisposable) { (dlg as IDisposable).Dispose(); } } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// a factory method for RecordFilterListProvider /// </summary> /// <param name="mediator">The mediator.</param> /// <param name="configuration">The configuration.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ static public RecordFilterListProvider Create(Mediator mediator, XmlNode configuration) { RecordFilterListProvider p = (RecordFilterListProvider)DynamicLoader.CreateObject(configuration); if (p != null) { p.Init(mediator, configuration); } return(p); }
/// <summary> /// Install a virtual property (often a subclass implementation) from specified XML. Return the tag. /// </summary> public static int InstallVirtual(FdoCache cache, string source) { XmlDocument doc = new XmlDocument(); doc.LoadXml(source); XmlNode virtualNode = doc.DocumentElement; // This one is used so widely we will create it here if not already done. IVwVirtualHandler vh = (IVwVirtualHandler)DynamicLoader.CreateObject( virtualNode.SelectSingleNode("dynamicloaderinfo"), new object[] { virtualNode, cache }); cache.VwCacheDaAccessor.InstallVirtual(vh); return(vh.Tag); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="XmlSeqView"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public XmlSeqView(FdoCache cache, int hvoRoot, int flid, XmlNode xnSpec, ISilDataAccessManaged sda, IApp app, ICmPossibility publication) : base(null) { m_app = app; var useSda = sda; var decoratorSpec = XmlUtils.FindNode(xnSpec, "decoratorClass"); if (decoratorSpec != null) { // For example, this may create a DictionaryPublicationDecorator. useSda = (ISilDataAccessManaged)DynamicLoader.CreateObject(decoratorSpec, new object[] { cache, sda, flid, publication }); } InitXmlViewRootSpec(hvoRoot, flid, xnSpec, useSda); }
static public RecordBarHandler Create(Mediator mediator, PropertyTable propertyTable, XmlNode toolConfiguration) { RecordBarHandler handler; XmlNode node = toolConfiguration.SelectSingleNode("treeBarHandler"); if (node == null) { handler = new RecordBarListHandler(); } else { handler = (TreeBarHandler)DynamicLoader.CreateObject(node); } handler.Init(mediator, propertyTable, node); return(handler); }
/// <summary> /// Looks for a node called "virtuals" and under it collects nodes of type "virtual", /// each having at least "modelclass", "virtualfield", "assemblyPath", and "class". /// Here 'class' is the name of the C# class that implements the VH, while 'modelclass' /// is the name of the virtual property. The node is passed to the VH as a constructor /// argument, so other attributes may be required. /// </summary> /// <returns>the list of installed virtual handlers</returns> public static List <IVwVirtualHandler> InstallVirtuals(XmlNode virtualsNode, FdoCache cache, bool okToFail) { List <IVwVirtualHandler> installedHandlers = new List <IVwVirtualHandler>(); foreach (XmlNode virtualNode in virtualsNode.SelectNodes("virtual")) { IVwCacheDa cda = cache.MainCacheAccessor as IVwCacheDa; IVwVirtualHandler vh = cda.GetVirtualHandlerName( XmlUtils.GetManditoryAttributeValue(virtualNode, "modelclass"), XmlUtils.GetManditoryAttributeValue(virtualNode, "virtualfield")); if (vh != null && vh is BaseVirtualHandler) { // already exists, hope it's the same one. Make sure its cache is valid. (vh as BaseVirtualHandler).Reinitialize(virtualNode, cache); installedHandlers.Add(vh); continue; } try { vh = (IVwVirtualHandler)DynamicLoader.CreateObject( virtualNode.SelectSingleNode("dynamicloaderinfo"), new object[] { virtualNode, cache }); } catch (Exception err) { if (!okToFail) { throw err; } // Otherwise we're in some special test situation or really just want the IText ones // and we ignore the problem. continue; } try { cda.InstallVirtual(vh); } catch (Exception err) { Debug.WriteLine(err.Message); throw err; } installedHandlers.Add(vh); } return(installedHandlers); }
public void SetDlgInfo(Mediator mediator, XmlNode configurationParameters) { CheckDisposed(); Debug.Assert(mediator != null); Debug.Assert(configurationParameters != null); m_mediator = mediator; // <parameters title="FieldWorks Project Utilities" filename="Language Explorer\Configuration\UtilityCatalogInclude.xml"/> this.Text = XmlUtils.GetLocalizedAttributeValue(mediator.StringTbl, configurationParameters, "title", "FieldWorks Project Utilities"); string utilsPathname = Path.Combine(FwDirectoryFinder.CodeDirectory, XmlUtils.GetManditoryAttributeValue(configurationParameters, "filename")); // Get the folder path: string utilsFolderName = Path.GetDirectoryName(utilsPathname); // Get the file name: string utilsFileName = Path.GetFileName(utilsPathname); // Insert an asterisk before the ".XML" so we can search for similar files: string searchPattern = utilsFileName.Replace(".", "*."); string[] files = Directory.GetFiles(utilsFolderName, searchPattern, SearchOption.TopDirectoryOnly); foreach (string pathname in files) { XmlDocument document = new XmlDocument(); document.Load(pathname); foreach (XmlNode node in document.SelectNodes("utilityCatalog/utility")) { /* * <utilityCatalog> * <utility assemblyPath="LexEdDll.dll" class="SIL.FieldWorks.XWorks.LexEd.HomographResetter"/> * </utilityCatalog> */ IUtility util = DynamicLoader.CreateObject(node) as IUtility; util.Dialog = this; // Must be set before adding it to the control. util.LoadUtilities(); } } m_clbUtilities.Sorted = true; if (m_clbUtilities.Items.Count > 0) { m_clbUtilities.SelectedIndex = 0; } }
/// <summary> /// In SE Fieldworks we can't depend upon ScrControls.dll We need some decoupling to /// prevent the linker from trying to load ScrControls.dll and crashing. /// This seems to work. (Although I wonder if we could get away with just calling this method /// if IsTEInstalled?) /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void LaunchFilterTextsDialog(object sender, EventArgs args) { IFilterTextsDialog <IStText> dlg = null; try { var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_cache.ServiceLocator); var textsToChooseFrom = new List <IStText>(interestingTextsList.InterestingTexts); if (!FwUtils.IsTEInstalled) { // TE is not installed, so remove scripture from the list textsToChooseFrom = textsToChooseFrom.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)).ToList(); } var interestingTexts = textsToChooseFrom.ToArray(); if (FwUtils.IsTEInstalled) { dlg = (IFilterTextsDialog <IStText>)DynamicLoader.CreateObject( "ScrControls.dll", "SIL.FieldWorks.Common.Controls.FilterTextsDialogTE", m_cache, interestingTexts, m_mediator.HelpTopicProvider, m_bookImporter); } else { dlg = new FilterTextsDialog(m_cache, interestingTexts, m_mediator.HelpTopicProvider); } // LT-12181: Was 'PruneToSelectedTexts(text) and most others were deleted. // We want 'PruneToInterestingTextsAndSelect(interestingTexts, selectedText)' dlg.PruneToInterestingTextsAndSelect(interestingTexts, (IStText)m_objRoot); // LT-12140 Dialog name shouldn't change from Choose Texts //dlg.Text = ITextStrings.ksExportInterlinearizedTexts; dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported; if (dlg.ShowDialog(this) == DialogResult.OK) { m_objs.AddRange(dlg.GetListOfIncludedTexts()); } } finally { if (dlg != null) { ((IDisposable)dlg).Dispose(); } } }
private void ReadParameters() { m_sRegKeyName = XmlUtils.GetManditoryAttributeValue(m_configurationParameters, "regKeyName"); m_sProgressDialogTitle = XmlUtils.GetManditoryAttributeValue(m_configurationParameters, "dialogTitle"); m_sFileNameKey = XmlUtils.GetManditoryAttributeValue(m_configurationParameters, "fileNameKey"); m_sStringsPath = XmlUtils.GetManditoryAttributeValue(m_configurationParameters, "stringsPath"); foreach (XmlNode rNode in m_configurationParameters.ChildNodes) { if (rNode.Name == "retriever") { m_retrieverNode = rNode; m_retriever = (IDataRetriever)DynamicLoader.CreateObject(m_retrieverNode.SelectSingleNode("dynamicloaderinfo")); } else if (rNode.Name == "transforms") { m_transformsNode = rNode; } } }
private void AddConfigurableControls() { // Load the controls. // 1. Initialize the preview pane (lower pane) m_previewPane = new XmlView(0, "publicationNew", false); m_previewPane.Cache = m_cache; m_previewPane.StyleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(m_propertyTable); BasicPaneBarContainer pbc = new BasicPaneBarContainer(); pbc.Init(m_mediator, m_propertyTable, m_previewPane); pbc.Dock = DockStyle.Fill; pbc.PaneBar.Text = LexEdStrings.ksFindExampleSentenceDlgPreviewPaneTitle; panel2.Controls.Add(pbc); if (m_previewPane.RootBox == null) { m_previewPane.MakeRoot(); } // 2. load the browse view. (upper pane) XmlNode xnBrowseViewControlParameters = this.BrowseViewControlParameters; // First create our Clerk, since we can't set it's OwningObject via the configuration/mediator/PropertyTable info. m_clerk = RecordClerkFactory.CreateClerk(m_mediator, m_propertyTable, xnBrowseViewControlParameters, true); m_clerk.OwningObject = m_owningSense; m_rbv = DynamicLoader.CreateObject(xnBrowseViewControlParameters.ParentNode.SelectSingleNode("dynamicloaderinfo")) as ConcOccurrenceBrowseView; m_rbv.Init(m_mediator, m_propertyTable, xnBrowseViewControlParameters, m_previewPane, m_clerk.VirtualListPublisher); m_rbv.CheckBoxChanged += m_rbv_CheckBoxChanged; // add it to our controls. BasicPaneBarContainer pbc1 = new BasicPaneBarContainer(); pbc1.Init(m_mediator, m_propertyTable, m_rbv); pbc1.BorderStyle = BorderStyle.FixedSingle; pbc1.Dock = DockStyle.Fill; pbc1.PaneBar.Text = LexEdStrings.ksFindExampleSentenceDlgBrowseViewPaneTitle; panel1.Controls.Add(pbc1); CheckAddBtnEnabling(); }
static public RecordBarHandler Create(XCore.Mediator mediator, XmlNode toolConfiguration) { RecordBarHandler handler = null; XmlNode node = toolConfiguration.SelectSingleNode("treeBarHandler"); //if (node != null) //{ // handler = (TreeBarHandler)DynamicLoader.CreateObject(node); // handler.Init(mediator, node); //} if (node == null) { handler = new RecordBarListHandler(); } else { handler = (TreeBarHandler)DynamicLoader.CreateObject(node); } handler.Init(mediator, node); return(handler); }
protected internal bool OnAddTexts(object args) { CheckDisposed(); // get saved scripture choices var interestingTextsList = GetInterestingTextList(); var interestingTexts = interestingTextsList.InterestingTexts.ToArray(); IFilterTextsDialog <IStText> dlg = null; try { if (FwUtils.IsTEInstalled) { dlg = (IFilterTextsDialog <IStText>)DynamicLoader.CreateObject( "ScrControls.dll", "SIL.FieldWorks.Common.Controls.FilterTextsDialogTE", Cache, interestingTexts, m_mediator.HelpTopicProvider, (IBookImporter)this); } else { dlg = new FilterTextsDialog(Cache, interestingTexts, m_mediator.HelpTopicProvider); } if (dlg.ShowDialog(((IApp)m_mediator.PropertyTable.GetValue("App")).ActiveMainWindow) == DialogResult.OK) { interestingTextsList.SetInterestingTexts(dlg.GetListOfIncludedTexts()); UpdateFilterStatusBarPanel(); } } finally { if (dlg != null) { ((IDisposable)dlg).Dispose(); } } return(true); }
protected void ReplaceMatchingItemsControl() { if (m_mediator == null) { return; } XmlNode xnWindow = (XmlNode)m_mediator.PropertyTable.GetValue("WindowConfiguration"); if (xnWindow == null) { return; } XmlNode xnControl = xnWindow.SelectSingleNode("controls/parameters/guicontrol[@id=\"matchingReversalEntries\"]"); if (xnControl == null) { return; } // Replace the current matchingEntries object with the one specified in the XML. MatchingEntries newME = DynamicLoader.CreateObject(xnControl) as MatchingEntries; if (newME != null) { CopyBasicControlInfo(matchingEntries, newME); this.Controls.Remove(matchingEntries); matchingEntries.Dispose(); matchingEntries = newME; this.Controls.Add(matchingEntries); (matchingEntries as MatchingEntries).SelectionChanged += new SIL.FieldWorks.Common.Utils.FwSelectionChangedEventHandler(this.matchingEntries_SelectionChanged); (matchingEntries as MatchingEntries).RestoreFocus += new EventHandler(matchingEntries_RestoreFocus); // Reset Tab indices of direct child controls of the form. ResetTabOrder(); (newME as MatchingReversalEntriesBrowser).Initialize(m_cache, FontHeightAdjuster.StyleSheetFromMediator(m_mediator), m_mediator, m_owningIndex); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the ChooseScriptureDialog class. /// WARNING: this constructor is called by reflection, at least in the Interlinear /// Text DLL. If you change its parameters be SURE to find and fix those callers also. /// </summary> /// <param name="cache">The cache.</param> /// <param name="objList">A list of texts and books to check as an array of hvos</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// <param name="importer">The Paratext book importer.</param> /// ------------------------------------------------------------------------------------ public FilterTextsDialogTE(FdoCache cache, IStText[] objList, IHelpTopicProvider helpTopicProvider, IBookImporter importer) : base(cache, objList, helpTopicProvider) { m_bookImporter = importer; using (var progressDlg = new ProgressDialogWithTask(null, cache.ThreadHelper)) { NonUndoableUnitOfWorkHelper.Do(cache.ActionHandlerAccessor, () => TeScrInitializer.EnsureMinimalScriptureInitialization(cache, progressDlg, (IHelpTopicProvider)DynamicLoader.CreateObject(DirectoryFinder.TeDll, "SIL.FieldWorks.TE.TeHelpTopicProvider"))); } }
private void MakeSubControl(XmlNode configuration, Size parentSizeHint, bool isFirst) { XmlNode dynLoaderNode = configuration.SelectSingleNode("dynamicloaderinfo"); if (dynLoaderNode == null) { throw new ArgumentException("Required 'dynamicloaderinfo' XML node not found, while trying to make control for MultiPane.", "configuration"); } string contentAssemblyPath = XmlUtils.GetManditoryAttributeValue(dynLoaderNode, "assemblyPath"); string contentClass = XmlUtils.GetManditoryAttributeValue(dynLoaderNode, "class"); try { Control subControl = (Control)DynamicLoader.CreateObject(contentAssemblyPath, contentClass); if (subControl.AccessibleName == null) { subControl.AccessibleName = contentClass; } if (!(subControl is IxCoreColleague)) { throw new ApplicationException( "XCore can only handle controls which implement IxCoreColleague. " + contentClass + " does not."); } if (!(subControl is IXCoreUserControl)) { throw new ApplicationException( "XCore can only handle controls which implement IXCoreUserControl. " + contentClass + " does not."); } subControl.SuspendLayout(); subControl.Dock = DockStyle.Fill; // we add this before Initializing so that this child control will have access // to its eventual height and width, in case it needs to make initialization // decisions based on that. for example, if the child is another multipane, it // will use this to come up with a reasonable default location for its splitter. if (subControl is MultiPane) { MultiPane mpSubControl = subControl as MultiPane; mpSubControl.ParentSizeHint = parentSizeHint; // cause our subcontrol to inherit our DefaultPrintPane property. mpSubControl.DefaultPrintPaneId = m_defaultPrintPaneId; } // we add this before Initializing so that this child control will have access // to its eventual height and width, in case it needs to make initialization // decisions based on that. for example, if the child is another multipane, it // will use this to come up with a reasonable default location for its splitter. if (subControl is PaneBarContainer) { PaneBarContainer mpSubControl = subControl as PaneBarContainer; mpSubControl.ParentSizeHint = parentSizeHint; // cause our subcontrol to inherit our DefaultPrintPane property. mpSubControl.DefaultPrintPaneId = m_defaultPrintPaneId; } XmlNode parameters = null; if (configuration != null) { parameters = configuration.SelectSingleNode("parameters"); } ((IxCoreColleague)subControl).Init(m_mediator, parameters); // in normal situations, colleagues add themselves to the mediator when // initialized. in this case, we don't want this colleague to add itself // because we want it to be subservient to this "papa" control. however, since // this control is only experimental, I'm loathe to change the interfaces in // such a way as to tell a colleague that it should not add itself to the // mediator. so, for now, we will just do this hack and remove the colleague // from the mediator. m_mediator.RemoveColleague((IxCoreColleague)subControl); if (isFirst) { subControl.AccessibleName += ".First"; FirstControl = subControl; } else { subControl.AccessibleName += ".Second"; SecondControl = subControl; } subControl.ResumeLayout(false); } catch (Exception error) { string s = "Something went wrong trying to create a " + contentClass + "."; XWindow window = (XWindow)m_mediator.PropertyTable.GetValue("window"); ErrorReporter.ReportException(new ApplicationException(s, error), window.ApplicationRegistryKey, m_mediator.FeedbackInfoProvider.SupportEmailAddress); } }
/// <summary></summary> public static Slice Create(FdoCache cache, string editor, int flid, XmlNode node, ICmObject obj, StringTable stringTbl, IPersistenceProvider persistenceProvider, Mediator mediator, XmlNode caller, ObjSeqHashMap reuseMap) { Slice slice; switch (editor) { case "multistring": // first, these are the most common slices. { if (flid == 0) { throw new ApplicationException("field attribute required for multistring " + node.OuterXml); } string wsSpec = XmlUtils.GetOptionalAttributeValue(node, "ws"); int wsMagic = WritingSystemServices.GetMagicWsIdFromName(wsSpec); if (wsMagic == 0) { throw new ApplicationException( "ws must be 'all vernacular', 'all analysis', 'analysis vernacular', or 'vernacular analysis'" + " it said '" + wsSpec + "'."); } bool forceIncludeEnglish = XmlUtils.GetOptionalBooleanAttributeValue(node, "forceIncludeEnglish", false); bool spellCheck = XmlUtils.GetOptionalBooleanAttributeValue(node, "spell", true); // Either the part or the caller can specify that it isn't editable. // (The part may 'know' this, e.g. because it's a virtual attr not capable of editing; // more commonly the caller knows there isn't enough context for safe editing. bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true) && XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true); string optionalWsSpec = XmlUtils.GetOptionalAttributeValue(node, "optionalWs"); int wsMagicOptional = WritingSystemServices.GetMagicWsIdFromName(optionalWsSpec); MultiStringSlice msSlice = reuseMap.GetSliceToReuse("MultiStringSlice") as MultiStringSlice; if (msSlice == null) { slice = new MultiStringSlice(obj, flid, wsMagic, wsMagicOptional, forceIncludeEnglish, editable, spellCheck); } else { slice = msSlice; msSlice.Reuse(obj, flid, wsMagic, wsMagicOptional, forceIncludeEnglish, editable, spellCheck); } break; } case "defaultvectorreference": // second most common. { var rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorSlice") as ReferenceVectorSlice; if (rvSlice == null) { slice = new ReferenceVectorSlice(cache, obj, flid); } else { slice = rvSlice; rvSlice.Reuse(obj, flid); } break; } case "possvectorreference": { var prvSlice = reuseMap.GetSliceToReuse("PossibilityReferenceVectorSlice") as PossibilityReferenceVectorSlice; if (prvSlice == null) { slice = new PossibilityReferenceVectorSlice(cache, obj, flid); } else { slice = prvSlice; prvSlice.Reuse(obj, flid); } break; } case "semdomvectorreference": { var prvSlice = reuseMap.GetSliceToReuse("SemanticDomainReferenceVectorSlice") as SemanticDomainReferenceVectorSlice; if (prvSlice == null) { slice = new SemanticDomainReferenceVectorSlice(cache, obj, flid); } else { slice = prvSlice; prvSlice.Reuse(obj, flid); } break; } case "string": { if (flid == 0) { throw new ApplicationException("field attribute required for basic properties " + node.OuterXml); } int ws = GetWs(mediator, cache, node); if (ws != 0) { slice = new StringSlice(obj, flid, ws); } else { slice = new StringSlice(obj, flid); } var fShowWsLabel = XmlUtils.GetOptionalBooleanAttributeValue(node, "labelws", false); if (fShowWsLabel) { (slice as StringSlice).ShowWsLabel = true; } int wsEmpty = GetWs(mediator, cache, node, "wsempty"); if (wsEmpty != 0) { (slice as StringSlice).DefaultWs = wsEmpty; } break; } case "jtview": { string layout = XmlUtils.GetOptionalAttributeValue(caller, "param"); if (layout == null) { layout = XmlUtils.GetManditoryAttributeValue(node, "layout"); } // Editable if BOTH the caller (part ref) AND the node itself (the slice) say so...or at least if neither says not. bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true) && XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true); slice = new ViewSlice(new XmlView(obj.Hvo, layout, stringTbl, editable)); break; } case "summary": { slice = new SummarySlice(); break; } case "enumcombobox": { slice = new EnumComboSlice(cache, obj, flid, stringTbl, node["deParams"]); break; } case "referencecombobox": { slice = new ReferenceComboBoxSlice(cache, obj, flid, persistenceProvider); break; } case "typeaheadrefatomic": { slice = new AtomicRefTypeAheadSlice(obj, flid); break; } case "msareferencecombobox": { slice = new MSAReferenceComboBoxSlice(cache, obj, flid, persistenceProvider); break; } case "lit": // was "message" { string message = XmlUtils.GetManditoryAttributeValue(node, "message"); if (stringTbl != null) { string sTranslate = XmlUtils.GetOptionalAttributeValue(node, "translate", ""); if (sTranslate.Trim().ToLower() != "do not translate") { message = stringTbl.LocalizeLiteralValue(message); } } slice = new MessageSlice(message); break; } case "picture": { slice = new PictureSlice((ICmPicture)obj); break; } case "image": { try { slice = new ImageSlice(DirectoryFinder.FWCodeDirectory, XmlUtils.GetManditoryAttributeValue(node, "param1")); } catch (Exception error) { slice = new MessageSlice(String.Format(DetailControlsStrings.ksImageSliceFailed, error.Message)); } break; } case "checkbox": { slice = new CheckboxSlice(cache, obj, flid, node); break; } case "checkboxwithrefresh": { slice = new CheckboxRefreshSlice(cache, obj, flid, node); break; } case "time": { slice = new DateSlice(cache, obj, flid); break; } case "integer": // produced in the auto-generated parts from the conceptual model case "int": // was "integer" { slice = new IntegerSlice(cache, obj, flid); break; } case "gendate": { slice = new GenDateSlice(cache, obj, flid); break; } case "morphtypeatomicreference": { slice = new MorphTypeAtomicReferenceSlice(cache, obj, flid); break; } case "atomicreferencepos": { slice = new AtomicReferencePOSSlice(cache, obj, flid, persistenceProvider, mediator); break; } case "possatomicreference": { slice = new PossibilityAtomicReferenceSlice(cache, obj, flid); break; } case "atomicreferenceposdisabled": { slice = new AutomicReferencePOSDisabledSlice(cache, obj, flid, persistenceProvider, mediator); break; } case "defaultatomicreference": { slice = new AtomicReferenceSlice(cache, obj, flid); break; } case "defaultatomicreferencedisabled": { slice = new AtomicReferenceDisabledSlice(cache, obj, flid); break; } case "derivmsareference": { slice = new DerivMSAReferenceSlice(cache, obj, flid); break; } case "inflmsareference": { slice = new InflMSAReferenceSlice(cache, obj, flid); break; } case "phoneenvreference": { slice = new PhoneEnvReferenceSlice(cache, obj, flid); break; } case "sttext": { slice = new StTextSlice(obj, flid, GetWs(mediator, cache, node)); break; } case "custom": { slice = (Slice)DynamicLoader.CreateObject(node); break; } case "customwithparams": { slice = (Slice)DynamicLoader.CreateObject(node, new object[] { cache, editor, flid, node, obj, stringTbl, persistenceProvider, GetWs(mediator, cache, node) }); break; } case "ghostvector": { slice = new GhostReferenceVectorSlice(cache, obj, node); break; } case "command": { slice = new CommandSlice(node["deParams"]); break; } case null: //grouping nodes do not necessarily have any editor { slice = new Slice(); break; } case "message": // case "integer": // added back in to behave as "int" above throw new Exception("use of obsolete editor type (message->lit, integer->int)"); case "autocustom": slice = MakeAutoCustomSlice(cache, obj, caller); if (slice == null) { return(null); } break; case "defaultvectorreferencedisabled": // second most common. { ReferenceVectorDisabledSlice rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorDisabledSlice") as ReferenceVectorDisabledSlice; if (rvSlice == null) { slice = new ReferenceVectorDisabledSlice(cache, obj, flid); } else { slice = rvSlice; rvSlice.Reuse(obj, flid); } break; } default: { //Since the editor has not been implemented yet, //is there a bitmap file that we can show for this editor? //Such bitmaps belong in the distFiles xde directory string fwCodeDir = DirectoryFinder.FWCodeDirectory; string editorBitmapRelativePath = "xde/" + editor + ".bmp"; if (File.Exists(Path.Combine(fwCodeDir, editorBitmapRelativePath))) { slice = new ImageSlice(fwCodeDir, editorBitmapRelativePath); } else { slice = new MessageSlice(String.Format(DetailControlsStrings.ksBadEditorType, editor)); } break; } } slice.AccessibleName = editor; return(slice); }
/// <summary> /// Used to launch various import dialogs, but could do other things /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnLaunchConnectedDialog(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; System.Xml.XmlNode first = command.Parameters[0]; System.Xml.XmlNode classInfo = first.SelectSingleNode("dynamicloaderinfo"); Form formActive = ActiveForm; FwXWindow wndActive = formActive as FwXWindow; IFwExtension dlg = null; if (((classInfo as System.Xml.XmlElement)?.Attributes["class"]?.Value ?? "").Contains( "LinguaLinks")) { // Message is deliberately not localized. We expect this to affect maybe one person every couple of years based on recent // occurrences. Doubt it's worth translating. // The reason for the disabling is that model changes require significant changes to the Import code, // and we don't think it's worth the effort. What few LinguaLinks projects still require import can be handled // by installing a version 7 FieldWorks, importing, and then migrating. // (For example, the currently generated stage 5 XML assumes Senses still reference ReveralEntries, rather than the // current opposite link; and there were problems importing texts even in FLEx 8 (LT-2084)). MessageBox.Show( @"Fieldworks no longer supports import of LinguaLinks data. For any remaining projects that need this, our support staff can help convert your data. Please send a message to [email protected]", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } try { try { dlg = (IFwExtension)DynamicLoader.CreateObject(classInfo); } catch (Exception error) { string message = XmlUtils.GetOptionalAttributeValue(classInfo, "notFoundMessage", null); // Make this localizable! if (message != null) { throw new ApplicationException(message, error); } } var oldWsUser = Cache.WritingSystemFactory.UserWs; dlg.Init(Cache, wndActive.Mediator, wndActive.PropTable); DialogResult dr = ((Form)dlg).ShowDialog(ActiveForm); if (dr == DialogResult.OK) { if (dlg is LexOptionsDlg) { LexOptionsDlg loDlg = dlg as LexOptionsDlg; if (oldWsUser != Cache.WritingSystemFactory.UserWs || loDlg.PluginsUpdated) { wndActive.SaveSettings(); MessageBoxUtils.Show(wndActive, LexTextStrings.LexTextApp_RestartToChangeUI_Content, LexTextStrings.LexTextApp_RestartToChangeUI_Title, MessageBoxButtons.OK); } } else if (dlg is LinguaLinksImportDlg || dlg is InterlinearImportDlg || dlg is LexImportWizard || dlg is NotebookImportWiz || dlg is LiftImportDlg) { // Make everything we've imported visible. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } } finally { if (dlg != null && dlg is IDisposable) { (dlg as IDisposable).Dispose(); } } return(true); }
public static Slice Create(FdoCache cache, string editor, int flid, XmlNode node, ICmObject obj, StringTable stringTbl, IPersistenceProvider persistenceProvider, Mediator mediator, XmlNode caller) { Slice slice = null; switch (editor) { case "string": { if (flid == 0) { throw new ApplicationException("field attribute required for basic properties " + node.OuterXml); } int ws = GetWs(mediator, cache, node); if (ws != 0) { slice = new StringSlice(obj.Hvo, flid, ws); } else { slice = new StringSlice(obj.Hvo, flid); } break; } case "multistring": { if (flid == 0) { throw new ApplicationException("field attribute required for multistring " + node.OuterXml); } string wsSpec = XmlUtils.GetOptionalAttributeValue(node, "ws"); int wsMagic; wsMagic = LangProject.GetMagicWsIdFromName(wsSpec); if (wsMagic == 0) { throw new ApplicationException( "ws must be 'all vernacular', 'all analysis', 'analysis vernacular', or 'vernacular analysis'" + " it said '" + wsSpec + "'."); } bool forceIncludeEnglish = XmlUtils.GetOptionalBooleanAttributeValue(node, "forceIncludeEnglish", false); bool spellCheck = XmlUtils.GetOptionalBooleanAttributeValue(node, "spell", true); bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true); slice = new MultiStringSlice(obj.Hvo, flid, wsMagic, forceIncludeEnglish, editable, spellCheck); break; } case "jtview": { string layout = XmlUtils.GetOptionalAttributeValue(caller, "param"); if (layout == null) { layout = XmlUtils.GetManditoryAttributeValue(node, "layout"); } // Editable if BOTH the caller (part ref) AND the node itself (the slice) say so...or at least if neither says not. bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true) && XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true); slice = new ViewSlice(new XmlView(obj.Hvo, layout, stringTbl, editable)); break; } case "summary": { slice = new SummarySlice(obj, caller, node, stringTbl); break; } case "enumcombobox": { slice = new EnumComboSlice(cache, obj, flid, stringTbl, node["deParams"]); break; } case "referencecombobox": { slice = new ReferenceComboBoxSlice(cache, obj, flid, persistenceProvider, mediator); break; } case "typeaheadrefatomic": { slice = new AtomicRefTypeAheadSlice(obj.Hvo, flid); break; } case "msareferencecombobox": { slice = new MSAReferenceComboBoxSlice(cache, obj, flid, persistenceProvider, mediator); break; } case "lit": // was "message" { string message = XmlUtils.GetManditoryAttributeValue(node, "message"); if (stringTbl != null) { string sTranslate = XmlUtils.GetOptionalAttributeValue(node, "translate", ""); if (sTranslate.Trim().ToLower() != "do not translate") { message = stringTbl.LocalizeLiteralValue(message); } } slice = new MessageSlice(message); break; } case "picture": { slice = new PictureSlice((FDO.Cellar.CmPicture)obj); break; } case "image": { try { slice = new ImageSlice(DirectoryFinder.FWCodeDirectory, XmlUtils.GetManditoryAttributeValue(node, "param1")); } catch (Exception error) { slice = new MessageSlice(String.Format(DetailControlsStrings.ksImageSliceFailed, error.Message)); } break; } case "checkbox": { slice = new CheckboxSlice(cache, obj, flid, node); break; } case "time": { slice = new DateSlice(cache, obj, flid); break; } case "integer": // produced in the auto-generated parts from the conceptual model case "int": // was "integer" { slice = new IntegerSlice(cache, obj, flid); break; } case "morphtypeatomicreference": { slice = new MorphTypeAtomicReferenceSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "atomicreferencepos": { slice = new AtomicReferencePOSSlice(cache, obj, flid, persistenceProvider, mediator); break; } case "defaultatomicreference": { slice = new AtomicReferenceSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "derivmsareference": { slice = new DerivMSAReferenceSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "inflmsareference": { slice = new InflMSAReferenceSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "defaultvectorreference": { slice = new ReferenceVectorSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "phoneenvreference": { slice = new PhoneEnvReferenceSlice(cache, obj, flid, node, persistenceProvider, mediator, stringTbl); break; } case "sttext": { slice = new StTextSlice(obj.Hvo, flid, GetWs(mediator, cache, node)); break; } case "custom": { slice = (Slice)DynamicLoader.CreateObject(node); break; } case "customwithparams": { slice = (Slice)DynamicLoader.CreateObject(node, new object[] { cache, editor, flid, node, obj, stringTbl, persistenceProvider, GetWs(mediator, cache, node) }); break; } case "command": { slice = new CommandSlice(node["deParams"]); break; } case null: //grouping nodes do not necessarily have any editor { slice = new Slice(); break; } case "message": // case "integer": // added back in to behave as "int" above throw new Exception("use of obsolete editor type (message->lit, integer->int)"); case "autocustom": slice = MakeAutoCustomSlice(cache, node, obj, caller); if (slice == null) { return(null); } break; default: { //Since the editor has not been implemented yet, //is there a bitmap file that we can show for this editor? //Such bitmaps belong in the distFiles xde directory string fwCodeDir = DirectoryFinder.FWCodeDirectory; string editorBitmapRelativePath = @"xde\" + editor + ".bmp"; if (System.IO.File.Exists(Path.Combine(fwCodeDir, editorBitmapRelativePath))) { slice = new ImageSlice(fwCodeDir, editorBitmapRelativePath); } else { slice = new MessageSlice(String.Format(DetailControlsStrings.ksBadEditorType, editor)); } break; } } slice.AccessibleName = editor; return(slice); }
/// <summary> /// Have the utility do what it does. /// </summary> public void Process() { const string MainXhtml = "main.xhtml"; const string RevXhtml = "FlexRev.xhtml"; const string SketchXml = "sketch.xml"; IExportContents sf = DynamicLoader.CreateObject("CssDialog.dll", "SIL.PublishingSolution.Contents") as IExportContents; Debug.Assert(sf != null); FdoCache cache = (FdoCache)exportDialog.Mediator.PropertyTable.GetValue("cache"); sf.DatabaseName = cache.DatabaseName; sf.ExportReversal = sf.ReversalExists = ContentsExists("lexicon", "reversalToolEditComplete", "ReversalIndexXHTML"); sf.GrammarExists = false; DialogResult result = sf.ShowDialog(); if (result == DialogResult.Cancel) { return; } string outPath = Path.Combine(sf.OutputLocationPath, sf.DictionaryName); if (sf.ExistingDirectoryInput) { string inputPath = sf.ExistingDirectoryLocationPath; if (inputPath != outPath) { string dirFilter = string.Empty; if (sf.OutputLocationPath == inputPath) { dirFilter = sf.DictionaryName; } try { if (!MyFolders.Copy(inputPath, outPath, dirFilter)) { return; } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } if (!MyFolders.CreateDirectory(outPath)) { return; } string mainFullName = Path.Combine(outPath, MainXhtml); string revFullXhtml = Path.Combine(outPath, RevXhtml); string gramFullName = Path.Combine(outPath, SketchXml); if (!sf.ExportMain) { mainFullName = ""; } if (!sf.ExportReversal) { revFullXhtml = ""; } switch (result) { // No = Skip export of data from Flex but still prepare exported output (ODT, PDF or whatever) case DialogResult.No: break; case DialogResult.Yes: if (!DeFlexExports(ExpCss, mainFullName, revFullXhtml, gramFullName)) { return; } break; } IExporter exporter = DynamicLoader.CreateObject("PsExport.dll", "SIL.PublishingSolution.PsExport") as IExporter; Debug.Assert(exporter != null); exporter.DataType = "Dictionary"; exporter.ProgressBar = exportDialog.ProgressBar; exporter.Export(mainFullName != "" ? mainFullName : revFullXhtml); Reporting(); }