public DataEntryNote(ControlRow control, Dictionary <string, string> autocompletions, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.NoteTextBox, ControlLabelStyleEnum.DefaultLabel) { // Now configure the various elements this.ContentControl.Autocompletions = autocompletions; this.ContentChanged = false; }
private static ComboBox CreateComboBox(DataEntryControls styleProvider, ControlRow control) { ComboBox comboBox = new ComboBox() { ToolTip = control.Tooltip, Width = control.Width, Style = styleProvider.FindResource(ControlContentStyleEnum.ChoiceComboBox.ToString()) as Style }; // Add items to the combo box List <string> choices = control.GetChoices(out bool includesEmptyChoice); foreach (string choice in choices) { comboBox.Items.Add(choice); } if (includesEmptyChoice) { // put empty choices at the end below a separator for visual clarity comboBox.Items.Add(new Separator()); comboBox.Items.Add(String.Empty); } comboBox.SelectedIndex = 0; return(comboBox); }
// Need to //-disable the menu when nothing is in it //-handle overview //-put in edit menu private void MenuItemRestoreDefaultValues_Click(object sender, RoutedEventArgs e) { // Retrieve the controls foreach (KeyValuePair <string, DataEntryControl> pair in this.DataEntryControls.ControlsByDataLabel) { DataEntryControl control = pair.Value; if (control.DataLabel == Constant.DatabaseColumn.File || control.DataLabel == Constant.DatabaseColumn.Folder || control.DataLabel == Constant.DatabaseColumn.RelativePath || control.DataLabel == Constant.DatabaseColumn.Date || control.DataLabel == Constant.DatabaseColumn.Time || control.DataLabel == Constant.DatabaseColumn.DateTime || control.DataLabel == Constant.DatabaseColumn.UtcOffset) { // Ignore stock controls continue; } ControlRow imageDatabaseControl = this.templateDatabase.GetControlFromTemplateTable(control.DataLabel); if (this.MarkableCanvas.ThumbnailGrid.IsVisible == false && this.MarkableCanvas.ThumbnailGrid.IsGridActive == false) { // Only a single image is displayed: update the database for the current row with the control's value this.DataHandler.FileDatabase.UpdateFile(this.DataHandler.ImageCache.Current.ID, control.DataLabel, imageDatabaseControl.DefaultValue); System.Diagnostics.Debug.Print(control.DataLabel + ":" + control.Content + ":" + imageDatabaseControl.DefaultValue); } else { // Multiple images are displayed: update the database for all selected rows with the control's value this.DataHandler.FileDatabase.UpdateFiles(this.MarkableCanvas.ThumbnailGrid.GetSelected(), control.DataLabel, imageDatabaseControl.DefaultValue); } control.SetContentAndTooltip(imageDatabaseControl.DefaultValue); } }
public DataEntryDateTime(ControlRow control, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.DateTimeBox, ControlLabelStyleEnum.DefaultLabel) { // configure the various elements DataEntryHandler.Configure(this.ContentControl, null); this.ContentControl.GotKeyboardFocus += this.ContentControl_GotKeyboardFocus; this.ContentControl.LostKeyboardFocus += this.ContentControl_LostKeyboardFocus; }
public DataEntryUtcOffset(ControlRow control, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.UTCOffsetBox, ControlLabelStyleEnum.DefaultLabel) { // Callback to change the look of the control whenever it gets the focus this.ContentControl.GotKeyboardFocus += this.ContentControl_GotKeyboardFocus; this.ContentControl.LostKeyboardFocus += this.ContentControl_LostKeyboardFocus; // configure the various elements }
public DataEntryChoice(ControlRow control, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.ChoiceComboBox, ControlLabelStyleEnum.DefaultLabel) { // The behaviour of the combo box this.ContentControl.Focusable = true; this.ContentControl.IsEditable = false; this.ContentControl.IsTextSearchEnabled = true; // Callback used to allow Enter to select the highlit item this.ContentControl.PreviewKeyDown += this.ContentCtl_PreviewKeyDown; // Add items to the combo box. If we have an EmptyChoiceItem, then add an 'empty string' to the end // Check the arguments for null List <string> choiceList; bool includesEmptyChoice; if (control == null) { // this should not happen TracePrint.PrintStackTrace(1); choiceList = new List <string>(); includesEmptyChoice = true; } else { choiceList = control.GetChoices(out includesEmptyChoice); } ComboBoxItem cbi; foreach (string choice in choiceList) { cbi = new ComboBoxItem() { Content = choice }; this.ContentControl.Items.Add(cbi); } if (includesEmptyChoice) { // put empty choice at the beginning of the control below a separator for visual clarity cbi = new ComboBoxItem() { Content = String.Empty }; this.ContentControl.Items.Insert(0, cbi); } // We include an invisible ellipsis menu item. This allows us to display an ellipsis in the combo box text field // when multiple images with different values are selected cbi = new ComboBoxItem() { Content = Constant.Unicode.Ellipsis }; this.ContentControl.Items.Insert(0, cbi); ((ComboBoxItem)this.ContentControl.Items[0]).Visibility = System.Windows.Visibility.Collapsed; this.ContentControl.SelectedIndex = 1; }
private static Label CreateLabel(DataEntryControls styleProvider, ControlRow control) { Label label = new Label() { Content = control.Label, ToolTip = control.Tooltip, Style = styleProvider.FindResource(ControlLabelStyleEnum.DefaultLabel.ToString()) as Style }; return(label); }
public static ControlRow[] Create(int size) { var retval = new ControlRow[size]; for (int i = 0; i < size; i++) { retval[i] = new ControlRow(); } return(retval); }
private static TextBox CreateTextBox(DataEntryControls styleProvider, ControlRow control) { TextBox textBox = new TextBox() { Text = control.DefaultValue, ToolTip = control.Tooltip, Width = control.Width, Style = styleProvider.FindResource(ControlContentStyleEnum.NoteTextBox.ToString()) as Style }; return(textBox); }
private CheckBox CreateFlag(DataEntryControls styleProvider, ControlRow control) { CheckBox checkBox = new CheckBox() { Visibility = Visibility.Visible, ToolTip = control.Tooltip, Style = styleProvider.FindResource(ControlContentStyleEnum.FlagCheckBox.ToString()) as Style }; checkBox.GotFocus += this.Control_GotFocus; checkBox.LostFocus += this.Control_LostFocus; return(checkBox); }
private UtcOffsetUpDown CreateUtcOffsetPicker(ControlRow control) { UtcOffsetUpDown utcOffsetPicker = new UtcOffsetUpDown() { ToolTip = control.Tooltip, Value = Constant.ControlDefault.DateTimeValue.Offset, Width = control.Width }; utcOffsetPicker.GotFocus += this.Control_GotFocus; utcOffsetPicker.LostFocus += this.Control_LostFocus; return(utcOffsetPicker); }
public DataEntryCounter(ControlRow control, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.CounterTextBox, ControlLabelStyleEnum.CounterButton) { // Configure the various elements if needed // Assign all counters to a single group so that selecting a new counter deselects any currently selected counter this.LabelControl.GroupName = "DataEntryCounter"; this.LabelControl.Click += this.LabelControl_Click; this.ContentControl.Width += 18; // to account for the width of the spinner this.ContentControl.PreviewKeyDown += this.ContentControl_PreviewKeyDown; this.ContentControl.PreviewTextInput += this.ContentControl_PreviewTextInput; this.ContentControl.GotKeyboardFocus += this.ContentControl_GotKeyboardFocus; this.ContentControl.LostKeyboardFocus += this.ContentControl_LostKeyboardFocus; }
private DateTimePicker CreateDateTimePicker(ControlRow control) { DateTimePicker dateTimePicker = new DateTimePicker() { ToolTip = control.Tooltip, Width = control.Width, CultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-US") }; DataEntryHandler.Configure(dateTimePicker, Constant.ControlDefault.DateTimeValue.DateTime); dateTimePicker.GotFocus += this.Control_GotFocus; dateTimePicker.LostFocus += this.Control_LostFocus; return(dateTimePicker); }
protected DataEntryControl(ControlRow control, DataEntryControls styleProvider) { // Check the arguments for null ThrowIf.IsNullArgument(control, nameof(control)); ThrowIf.IsNullArgument(styleProvider, nameof(styleProvider)); // populate properties from database definition of control // this.Content and Tooltip can't be set, however, as the caller hasn't instantiated the content control yet this.Copyable = control.Copyable; this.DataLabel = control.DataLabel; // Create the stack panel this.Container = new StackPanel(); Style style = styleProvider.FindResource(Constant.ControlStyle.ContainerStyle) as Style; this.Container.Style = style; // use the containers's tag to point back to this so event handlers can access the DataEntryControl // this is needed by callbacks such as DataEntryHandler.Container_PreviewMouseRightButtonDown() and TimelapseWindow.CounterControl_MouseLeave() this.Container.Tag = this; }
public void Execute() { if (null != this.WixBBControlTable) { RowDictionary <BBControlRow> bbControlRows = new RowDictionary <BBControlRow>(this.BBControlTable); foreach (Row wixRow in this.WixBBControlTable.Rows) { BBControlRow bbControlRow = bbControlRows.Get(wixRow.GetPrimaryKey()); bbControlRow.Text = this.ReadTextFile(bbControlRow.SourceLineNumbers, wixRow.FieldAsString(2)); } } if (null != this.WixControlTable) { RowDictionary <ControlRow> controlRows = new RowDictionary <ControlRow>(this.ControlTable); foreach (Row wixRow in this.WixControlTable.Rows) { ControlRow controlRow = controlRows.Get(wixRow.GetPrimaryKey()); controlRow.Text = this.ReadTextFile(controlRow.SourceLineNumbers, wixRow.FieldAsString(2)); } } }
public FileTableUtcOffsetColumn(ControlRow control) : base(control) { }
public FileTableNoteColumn(ControlRow control) : base(control) { }
public DataEntryFlag(ControlRow control, DataEntryControls styleProvider) : base(control, styleProvider, ControlContentStyleEnum.FlagCheckBox, ControlLabelStyleEnum.DefaultLabel) { // Callback used to allow Enter to select the highlit item this.ContentControl.PreviewKeyDown += this.ContentControl_PreviewKeyDown; }
private static IntegerUpDown CreateIntegerUpDown(DataEntryControls styleProvider, ControlRow control) { IntegerUpDown integerUpDown = new IntegerUpDown() { Text = control.DefaultValue, ToolTip = control.Tooltip, Minimum = 0, Width = control.Width + 18, // accounts for the width of the spinner DisplayDefaultValueOnEmptyText = true, DefaultValue = null, UpdateValueOnEnterKey = true, Style = styleProvider.FindResource(ControlContentStyleEnum.CounterTextBox.ToString()) as Style }; return(integerUpDown); }
private static RadioButton CreateCounterLabelButton(DataEntryControls styleProvider, ControlRow control) { RadioButton radioButton = new RadioButton() { GroupName = "DataEntryCounter", Content = control.Label, ToolTip = control.Tooltip, Style = styleProvider.FindResource(ControlLabelStyleEnum.CounterButton.ToString()) as Style }; return(radioButton); }
/// <summary> /// FileTableUtcOffsetColumn - A FileTable Column holding a UTCOffset (a double) /// </summary> #region Constructors public FileTableUtcOffsetColumn(ControlRow control) : base(control) { }
// Load the specified database template and then the associated images. // templateDatabasePath is the Fully qualified path to the template database file. // Returns true only if both the template and image database file are loaded (regardless of whether any images were loaded) , false otherwise private async Task <bool> TryOpenTemplateAndBeginLoadFoldersAsync(string templateDatabasePath) { // Try to create or open the template database // First, check the file path length and notify the user the template couldn't be loaded because its path is too long if (IsCondition.IsPathLengthTooLong(templateDatabasePath)) { Mouse.OverrideCursor = null; Dialogs.TemplatePathTooLongDialog(this, templateDatabasePath); return(false); } // Second, check to see if we can actually open it. // As we can't have out parameters in an async method, we return the state and the desired templateDatabase as a tuple Tuple <bool, TemplateDatabase> tupleResult = await TemplateDatabase.TryCreateOrOpenAsync(templateDatabasePath).ConfigureAwait(true); this.templateDatabase = tupleResult.Item2; if (!tupleResult.Item1) { // Notify the user the template couldn't be loaded rather than silently doing nothing Mouse.OverrideCursor = null; Dialogs.TemplateFileNotLoadedAsCorruptDialog(this, templateDatabasePath); return(false); } // The .tdb templateDatabase should now be loaded // Try to get the image database file path // importImages will be true if its a new image database file, (meaning we should later ask the user to try to import some images) if (this.TrySelectDatabaseFile(templateDatabasePath, out string fileDatabaseFilePath, out bool importImages) == false) { // No image database file was selected return(false); } // Check the file path length of the .ddb file and notify the user the ddb couldn't be loaded because its path is too long if (IsCondition.IsPathLengthTooLong(fileDatabaseFilePath)) { Mouse.OverrideCursor = null; Dialogs.DatabasePathTooLongDialog(this, fileDatabaseFilePath); return(false); } // Check the expected file path length of the backup files, and warn the user if backups may not be made because thier path is too long if (IsCondition.IsBackupPathLengthTooLong(templateDatabasePath) || IsCondition.IsBackupPathLengthTooLong(fileDatabaseFilePath)) { Mouse.OverrideCursor = null; Dialogs.BackupPathTooLongDialog(this); } // Before fully loading an existing image database, // - upgrade the template tables if needed for backwards compatability (done automatically) // - compare the controls in the .tdb and .ddb template tables to see if there are any added or missing controls TemplateSyncResults templateSyncResults = new Database.TemplateSyncResults(); bool backUpJustMade = false; using (FileDatabase fileDB = await FileDatabase.UpgradeDatabasesAndCompareTemplates(fileDatabaseFilePath, this.templateDatabase, templateSyncResults).ConfigureAwait(true)) { // A file database was available to open if (fileDB != null) { if (templateSyncResults.ControlSynchronizationErrors.Count > 0 || (templateSyncResults.ControlSynchronizationWarnings.Count > 0 && templateSyncResults.SyncRequiredAsDataLabelsDiffer == false)) { // There are unresolvable syncronization issues. Report them now as we cannot use this template. // Depending on the user response, we either abort Timelapse or use the template found in the ddb file Mouse.OverrideCursor = null; Dialog.TemplateSynchronization templatesNotCompatibleDialog; templatesNotCompatibleDialog = new Dialog.TemplateSynchronization(templateSyncResults.ControlSynchronizationErrors, templateSyncResults.ControlSynchronizationWarnings, this); bool?result = templatesNotCompatibleDialog.ShowDialog(); if (result == false) { // user indicates exiting rather than continuing. Application.Current.Shutdown(); return(false); } else { templateSyncResults.UseTemplateDBTemplate = templatesNotCompatibleDialog.UseNewTemplate; templateSyncResults.SyncRequiredAsChoiceMenusDiffer = templateSyncResults.ControlSynchronizationWarnings.Count > 0; } } else if (templateSyncResults.SyncRequiredAsDataLabelsDiffer) { // If there are any new or missing columns, report them now // Depending on the user response, set the useTemplateDBTemplate to signal whether we should: // - update the template and image data columns in the image database // - use the old template Mouse.OverrideCursor = null; TemplateChangedAndUpdate templateChangedAndUpdate = new TemplateChangedAndUpdate(templateSyncResults, this); bool?result1 = templateChangedAndUpdate.ShowDialog(); templateSyncResults.UseTemplateDBTemplate = result1 == true; } else if (templateSyncResults.SyncRequiredAsNonCriticalFieldsDiffer) { // Non critical differences in template, so these don't need reporting templateSyncResults.UseTemplateDBTemplate = true; } backUpJustMade = fileDB.mostRecentBackup != DateTime.MinValue; } else if (File.Exists(fileDatabaseFilePath) == true) { // The .ddb file (which exists) is for some reason unreadable. // It is likely due to an empty or corrupt or otherwise unreadable database in the file. // Raise an error message bool isEmpty = File.Exists(fileDatabaseFilePath) && new FileInfo(fileDatabaseFilePath).Length == 0; Mouse.OverrideCursor = null; Dialogs.DatabaseFileNotLoadedAsCorruptDialog(this, fileDatabaseFilePath, isEmpty); return(false); } ; } // At this point: // - for backwards compatability, all old databases will have been updated (if needed) to the current version standard // - we should have a valid template and image database loaded // - we know if the user wants to use the old or the new template // So lets load the database for real. The useTemplateDBTemplate signals whether to use the template stored in the DDB, or to use the TDB template. FileDatabase fileDatabase = await FileDatabase.CreateOrOpenAsync(fileDatabaseFilePath, this.templateDatabase, this.State.CustomSelectionTermCombiningOperator, templateSyncResults, backUpJustMade).ConfigureAwait(true); // The next test is to test and syncronize (if needed) the default values stored in the fileDB table schema to those stored in the template Dictionary <string, string> columndefaultdict = fileDatabase.SchemaGetColumnsAndDefaultValues(Constant.DBTables.FileData); char[] quote = { '\'' }; foreach (KeyValuePair <string, string> pair in columndefaultdict) { ControlRow row = this.templateDatabase.GetControlFromTemplateTable(pair.Key); if (row != null && pair.Value.Trim(quote) != row.DefaultValue) { // If even one default is different between the schema default and the template default, update the entire file table. fileDatabase.UpgradeFileDBSchemaDefaultsFromTemplate(); break; } } // Check to see if the root folder stored in the database is the same as the actual root folder. If not, ask the user if it should be changed. this.CheckAndCorrectRootFolder(fileDatabase); // Check to see if there are any missing folders as specified by the relative paths. For those missing, ask the user to try to locate those folders. int missingFoldersCount = TimelapseWindow.GetMissingFolders(fileDatabase).Count; if (missingFoldersCount > 0) { Dialogs.MissingFoldersInformationDialog(this, missingFoldersCount); } // Generate and render the data entry controls, regardless of whether there are actually any files in the files database. this.DataHandler = new DataEntryHandler(fileDatabase); this.DataEntryControls.CreateControls(fileDatabase, this.DataHandler); this.SetUserInterfaceCallbacks(); this.MarkableCanvas.DataEntryControls = this.DataEntryControls; // so the markable canvas can access the controls this.DataHandler.ThumbnailGrid = this.MarkableCanvas.ThumbnailGrid; this.DataHandler.MarkableCanvas = this.MarkableCanvas; this.Title = Constant.Defaults.MainWindowBaseTitle + " (" + Path.GetFileName(fileDatabase.FilePath) + ")"; this.State.MostRecentImageSets.SetMostRecent(templateDatabasePath); this.RecentFileSets_Refresh(); // Record the version number of the currently executing version of Timelapse only if its greater than the one already stored in the ImageSet Table. // This will indicate the latest timelapse version that is compatable with the database structure. string currentVersionNumberAsString = VersionChecks.GetTimelapseCurrentVersionNumber().ToString(); if (VersionChecks.IsVersion1GreaterThanVersion2(currentVersionNumberAsString, this.DataHandler.FileDatabase.ImageSet.VersionCompatability)) { this.DataHandler.FileDatabase.ImageSet.VersionCompatability = currentVersionNumberAsString; this.DataHandler.FileDatabase.UpdateSyncImageSetToDatabase(); } // Create an index on RelativePath, File,and RelativePath/File if it doesn't already exist // This is really just a version check in case old databases don't have the index created, // Newer databases (from 2.2.4.4 onwards) will have these indexes created and updated whenever images are loaded or added for the first time. // If the index exists, this is a very cheap operation so there really is no need to do it by a version number check. this.DataHandler.FileDatabase.IndexCreateForFileAndRelativePathIfNotExists(); // If this is a new image database, try to load images (if any) from the folder... if (importImages) { this.TryBeginImageFolderLoad(this.FolderPath, this.FolderPath); } else { await this.OnFolderLoadingCompleteAsync(false).ConfigureAwait(true); } return(true); }
private static void UpdateControl(XmlNode selectedNode, TemplateDatabase templateDatabase, string typeWanted, ControlRow control, ref List <string> errorMessages, ref List <string> dataLabels) { XmlNodeList selectedData = selectedNode.SelectNodes(Constant.ImageXml.Data); control.DefaultValue = GetColumn(selectedData, Constant.Control.DefaultValue); // Default control.Width = Int32.Parse(GetColumn(selectedData, Constant.Control.TextBoxWidth)); // Width // The tempTable should have defaults filled in at this point for labels, datalabels, and tooltips // Thus if we just get empty values, we should use those defaults rather than clearing them string label = GetColumn(selectedData, Constant.Control.Label); if (!String.IsNullOrEmpty(label)) { control.Label = label; } string controlType = typeWanted; if (EditorControls.IsStandardControlType(typeWanted) == false) { controlType = GetColumn(selectedData, Constant.Control.DataLabel); if (String.IsNullOrWhiteSpace(controlType)) { controlType = label; // If there is no data label, use the label's value into it. } // string dataLabel = Regex.Replace(controlType, @"\s+", String.Empty); // remove any white space that may be there string dataLabel = Regex.Replace(controlType, "[^a-zA-Z0-9_]", String.Empty); // only allow alphanumeric and '_'. if (!dataLabel.Equals(controlType, StringComparison.InvariantCulture)) { errorMessages.Add("illicit characters: '" + controlType + "' changed to '" + dataLabel + "'"); controlType = dataLabel; } foreach (string sqlKeyword in EditorConstant.ReservedSqlKeywords) { if (String.Equals(sqlKeyword, dataLabel, StringComparison.OrdinalIgnoreCase)) { errorMessages.Add("reserved word: '" + controlType + "' changed to '" + controlType + "_'"); controlType += "_"; break; } } } // Now set the actual data label // First, check to see if the datalabel already exsists in the list, i.e., its not a unique key // If it doesn't, keep trying to add an integer to its end to make it unique. int j = 0; string temp_datalabel = controlType; while (dataLabels.Contains(temp_datalabel)) { temp_datalabel = controlType + j.ToString(); } if (!controlType.Equals(temp_datalabel, StringComparison.InvariantCulture)) { errorMessages.Add("duplicate data label:" + Environment.NewLine + " '" + controlType + "' changed to '" + temp_datalabel + "'"); controlType = temp_datalabel; } if (!String.IsNullOrEmpty(controlType)) { if (controlType.Equals("Delete", StringComparison.InvariantCulture)) { controlType = Constant.ControlDefault.DeleteFlagLabel; // Delete is a reserved word! } control.DataLabel = controlType; } else { // If the data label was empty, the priority is to use the non-empty label contents // otherwise we stay with the default contents of the data label filled in previously label = Regex.Replace(label, @"\s+", String.Empty); if (!string.IsNullOrEmpty(label)) { control.DataLabel = label; } } dataLabels.Add(controlType); // and add it to the list of data labels seen string tooltip = GetColumn(selectedData, Constant.Control.Tooltip); if (!String.IsNullOrEmpty(tooltip)) { control.Tooltip = tooltip; } // If there is no value supplied for Copyable, default is false for these data types (as they are already filled in by the system). // Counters are also not copyable be default, as we expect counts to change image by image. But there are cases where they user may want to alter this. bool defaultCopyable = true; if (EditorControls.IsStandardControlType(typeWanted)) { defaultCopyable = false; } control.Copyable = ConvertToBool(TextFromNode(selectedData, 0, Constant.Control.Copyable), defaultCopyable); // If there is no value supplied for Visibility, default is true (i.e., the control will be visible in the interface) control.Visible = ConvertToBool(TextFromNode(selectedData, 0, Constant.Control.Visible), true); // if the type has a list, we have to do more work. if (typeWanted == Constant.DatabaseColumn.ImageQuality) { // For Image Quality, use the new list (longer than the one in old templates) control.List = Constant.ImageQuality.ListOfValues; } else if (typeWanted == Constant.DatabaseColumn.ImageQuality || typeWanted == Constant.Control.FixedChoice) { // Load up the menu items control.List = String.Empty; // For others, generate the list from what is stored XmlNodeList nodes = selectedData[0].SelectNodes(Constant.Control.List + Constant.ImageXml.Slash + Constant.ImageXml.Item); bool firstTime = true; foreach (XmlNode node in nodes) { if (firstTime) { control.List = node.InnerText; // also clears the list's default values } else { control.List += "|" + node.InnerText; } firstTime = false; } } templateDatabase.SyncControlToDatabase(control); }
/// <summary> /// Creates a new row in the table. /// </summary> /// <param name="sourceLineNumbers">Original source lines for this row.</param> /// <param name="add">Specifies whether to only create the row or add it to the table automatically.</param> /// <returns>Row created in table.</returns> public Row CreateRow(SourceLineNumber sourceLineNumbers, bool add = true) { Row row; switch (this.Name) { case "BBControl": row = new BBControlRow(sourceLineNumbers, this); break; case "WixBundlePackage": row = new WixBundlePackageRow(sourceLineNumbers, this); break; case "WixBundleExePackage": row = new WixBundleExePackageRow(sourceLineNumbers, this); break; case "WixBundleMsiPackage": row = new WixBundleMsiPackageRow(sourceLineNumbers, this); break; case "WixBundleMspPackage": row = new WixBundleMspPackageRow(sourceLineNumbers, this); break; case "WixBundleMsuPackage": row = new WixBundleMsuPackageRow(sourceLineNumbers, this); break; case "Component": row = new ComponentRow(sourceLineNumbers, this); break; case "WixBundleContainer": row = new WixBundleContainerRow(sourceLineNumbers, this); break; case "Control": row = new ControlRow(sourceLineNumbers, this); break; case "File": row = new FileRow(sourceLineNumbers, this); break; case "WixBundleMsiFeature": row = new WixBundleMsiFeatureRow(sourceLineNumbers, this); break; case "WixBundleMsiProperty": row = new WixBundleMsiPropertyRow(sourceLineNumbers, this); break; case "Media": row = new MediaRow(sourceLineNumbers, this); break; case "WixBundlePayload": row = new WixBundlePayloadRow(sourceLineNumbers, this); break; case "Property": row = new PropertyRow(sourceLineNumbers, this); break; case "WixRelatedBundle": row = new WixRelatedBundleRow(sourceLineNumbers, this); break; case "WixBundleRelatedPackage": row = new WixBundleRelatedPackageRow(sourceLineNumbers, this); break; case "WixBundleRollbackBoundary": row = new WixBundleRollbackBoundaryRow(sourceLineNumbers, this); break; case "Upgrade": row = new UpgradeRow(sourceLineNumbers, this); break; case "WixBundleVariable": row = new WixBundleVariableRow(sourceLineNumbers, this); break; case "WixAction": row = new WixActionRow(sourceLineNumbers, this); break; case "WixApprovedExeForElevation": row = new WixApprovedExeForElevationRow(sourceLineNumbers, this); break; case "WixBundle": row = new WixBundleRow(sourceLineNumbers, this); break; case "WixBundlePackageExitCode": row = new WixBundlePackageExitCodeRow(sourceLineNumbers, this); break; case "WixBundlePatchTargetCode": row = new WixBundlePatchTargetCodeRow(sourceLineNumbers, this); break; case "WixBundleSlipstreamMsp": row = new WixBundleSlipstreamMspRow(sourceLineNumbers, this); break; case "WixBundleUpdate": row = new WixBundleUpdateRow(sourceLineNumbers, this); break; case "WixBundleCatalog": row = new WixBundleCatalogRow(sourceLineNumbers, this); break; case "WixChain": row = new WixChainRow(sourceLineNumbers, this); break; case "WixChainItem": row = new WixChainItemRow(sourceLineNumbers, this); break; case "WixBundlePackageCommandLine": row = new WixBundlePackageCommandLineRow(sourceLineNumbers, this); break; case "WixComplexReference": row = new WixComplexReferenceRow(sourceLineNumbers, this); break; case "WixDeltaPatchFile": row = new WixDeltaPatchFileRow(sourceLineNumbers, this); break; case "WixDeltaPatchSymbolPaths": row = new WixDeltaPatchSymbolPathsRow(sourceLineNumbers, this); break; case "WixFile": row = new WixFileRow(sourceLineNumbers, this); break; case "WixGroup": row = new WixGroupRow(sourceLineNumbers, this); break; case "WixMedia": row = new WixMediaRow(sourceLineNumbers, this); break; case "WixMediaTemplate": row = new WixMediaTemplateRow(sourceLineNumbers, this); break; case "WixMerge": row = new WixMergeRow(sourceLineNumbers, this); break; case "WixPayloadProperties": row = new WixPayloadPropertiesRow(sourceLineNumbers, this); break; case "WixProperty": row = new WixPropertyRow(sourceLineNumbers, this); break; case "WixSimpleReference": row = new WixSimpleReferenceRow(sourceLineNumbers, this); break; case "WixUpdateRegistration": row = new WixUpdateRegistrationRow(sourceLineNumbers, this); break; case "WixVariable": row = new WixVariableRow(sourceLineNumbers, this); break; default: row = new Row(sourceLineNumbers, this); break; } if (add) { this.Rows.Add(row); } return(row); }
// Given a quickPasteItem (essential the information representing a single data control and its value), // - add a row to the grid with controls that display that information, // - add a checkbox that can be selected to indicate whether that information should be included in a paste operation private void BuildRow(QuickPasteItem quickPasteItem, int gridRowIndex) { // USE Column: A checkbox to indicate whether the current search row should be used as part of the search Thickness thickness = new Thickness(0, 2, 0, 2); CheckBox useCurrentRow = new CheckBox() { Margin = thickness, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, IsChecked = quickPasteItem.Use, Tag = quickPasteItem }; useCurrentRow.Checked += this.UseCurrentRow_CheckChanged; useCurrentRow.Unchecked += this.UseCurrentRow_CheckChanged; this.UseCheckboxes.Add(useCurrentRow); Grid.SetRow(useCurrentRow, gridRowIndex); Grid.SetColumn(useCurrentRow, GridColumnUse); this.QuickPasteGridRows.Children.Add(useCurrentRow); // LABEL column: The label associated with the control (Note: not the data label) TextBlock controlLabel = new TextBlock() { Margin = new Thickness(5), Text = quickPasteItem.Label, Foreground = quickPasteItem.Use ? Brushes.Black : Brushes.Gray, }; Grid.SetRow(controlLabel, gridRowIndex); Grid.SetColumn(controlLabel, GridColumnLabel); this.QuickPasteGridRows.Children.Add(controlLabel); // Value column: The value is presented as an editable field particular to its control type if (quickPasteItem.ControlType == Constant.Control.Note || quickPasteItem.ControlType == Constant.Control.Counter) { // Notes and Counters both uses a text field, so they can be constructed as a textbox AutocompleteTextBox textBoxValue = new AutocompleteTextBox() { Autocompletions = null, Text = quickPasteItem.Value, Height = ValuesHeight, Width = ValuesWidth, TextWrapping = TextWrapping.NoWrap, VerticalAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; if (quickPasteItem.ControlType == Constant.Control.Note) { textBoxValue.Autocompletions = this.dataEntryControls.AutocompletionGetForNote(quickPasteItem.DataLabel); } // Counter text fields are modified to only allow numeric input if (quickPasteItem.ControlType == Constant.Control.Counter) { textBoxValue.PreviewTextInput += this.Counter_PreviewTextInput; DataObject.AddPastingHandler(textBoxValue, this.Counter_Paste); } textBoxValue.TextChanged += this.NoteOrCounter_TextChanged; Grid.SetRow(textBoxValue, gridRowIndex); Grid.SetColumn(textBoxValue, GridColumnValue); this.QuickPasteGridRows.Children.Add(textBoxValue); } else if (quickPasteItem.ControlType == Constant.Control.FixedChoice) { // Choices use choiceboxes ControlRow controlRow = this.fileDatabase.GetControlFromTemplateTable(quickPasteItem.DataLabel); ComboBox comboBoxValue = new ComboBox() { Height = ValuesHeight, Width = ValuesWidth, // Create the dropdown menu ItemsSource = controlRow.GetChoicesForQuickPasteMenu(), SelectedItem = quickPasteItem.Value, IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; Grid.SetRow(comboBoxValue, gridRowIndex); Grid.SetColumn(comboBoxValue, GridColumnValue); this.QuickPasteGridRows.Children.Add(comboBoxValue); comboBoxValue.SelectionChanged += this.FixedChoice_SelectionChanged; } else if (quickPasteItem.ControlType == Constant.Control.Flag) { // Flags present checkable checkboxes CheckBox flagCheckBox = new CheckBox() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, IsChecked = !string.Equals(quickPasteItem.Value, Constant.BooleanValue.False, StringComparison.OrdinalIgnoreCase), IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; flagCheckBox.Checked += this.Flag_CheckedOrUnchecked; flagCheckBox.Unchecked += this.Flag_CheckedOrUnchecked; Grid.SetRow(flagCheckBox, gridRowIndex); Grid.SetColumn(flagCheckBox, GridColumnValue); this.QuickPasteGridRows.Children.Add(flagCheckBox); } else { // We should never get here throw new NotSupportedException(String.Format("Unhandled control type in QuickPasteEditor '{0}'.", quickPasteItem.ControlType)); } this.Note.Visibility = this.QuickPasteEntry.IsAtLeastOneItemPastable() ? Visibility.Collapsed : Visibility.Visible; }
public static void Import(string filePath, TemplateDatabase templateDatabase, out List <string> conversionErrors) { ThrowIf.IsNullArgument(templateDatabase, nameof(templateDatabase)); conversionErrors = new List <string>(); // Collect all the data labels as we come across them, as we have to ensure that a new data label doesn't have the same name as an existing one List <string> dataLabels = new List <string>(); // Load the XML document (the code template file) // Follows CA3075 pattern for loading XmlDocument xmlDoc = new XmlDocument() { XmlResolver = null }; System.IO.StringReader sreader = new System.IO.StringReader(File.ReadAllText(filePath)); XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null }); xmlDoc.Load(reader); // merge standard controls which existed in code templates // MarkForDeletion and Relative path weren't available in code templates // NOTE THAT WE NEED TO UPDATE THIS TO NEWER DELETEFLAG XmlNodeList selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.FilePath); // Convert the File type CodeTemplateImporter.UpdateStandardControl(selectedNodes, templateDatabase, Constant.DatabaseColumn.File, ref conversionErrors, ref dataLabels); selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.FolderPath); // Convert the Folder type CodeTemplateImporter.UpdateStandardControl(selectedNodes, templateDatabase, Constant.DatabaseColumn.Folder, ref conversionErrors, ref dataLabels); selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.DatePath); // Convert the Date type CodeTemplateImporter.UpdateStandardControl(selectedNodes, templateDatabase, Constant.DatabaseColumn.Date, ref conversionErrors, ref dataLabels); selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.TimePath); // Convert the Time type CodeTemplateImporter.UpdateStandardControl(selectedNodes, templateDatabase, Constant.DatabaseColumn.Time, ref conversionErrors, ref dataLabels); selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.ImageQualityPath); // Convert the Image Quality type CodeTemplateImporter.UpdateStandardControl(selectedNodes, templateDatabase, Constant.DatabaseColumn.ImageQuality, ref conversionErrors, ref dataLabels); // no flag controls to import // import notes selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.NotePath); for (int index = 0; index < selectedNodes.Count; index++) { ControlRow note = templateDatabase.AddUserDefinedControl(Constant.Control.Note); CodeTemplateImporter.UpdateControl(selectedNodes[index], templateDatabase, Constant.Control.Note, note, ref conversionErrors, ref dataLabels); } // import choices selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.FixedChoicePath); for (int index = 0; index < selectedNodes.Count; index++) { ControlRow choice = templateDatabase.AddUserDefinedControl(Constant.Control.FixedChoice); CodeTemplateImporter.UpdateControl(selectedNodes[index], templateDatabase, Constant.Control.FixedChoice, choice, ref conversionErrors, ref dataLabels); } // import counters selectedNodes = xmlDoc.SelectNodes(Constant.ImageXml.CounterPath); for (int index = 0; index < selectedNodes.Count; index++) { ControlRow counter = templateDatabase.AddUserDefinedControl(Constant.Control.Counter); CodeTemplateImporter.UpdateControl(selectedNodes[index], templateDatabase, Constant.Control.Counter, counter, ref conversionErrors, ref dataLabels); } if (reader != null) { reader.Dispose(); } }