private void PopulateCustomActionsDropDown() { customActionsToolStripMenuItem.DropDownItems.Clear(); if (File.Exists(ScriptEngine.CustomActionsJsonPath)) { custActions = CustomActionsJson.LoadFromJson(ScriptEngine.CustomActionsJsonPath); foreach (var action in custActions.Actions) { var item = customActionsToolStripMenuItem.DropDownItems.Add(action.Name); item.ToolTipText = action.Tooltip; item.AutoToolTip = true; item.Tag = action; item.Click += (s, e) => { var clickAction = CurrentCustomAction = (CustomActionJson)(s as ToolStripItem).Tag; txtAdvanced.Text = clickAction.Execute; }; } } if (custActions == null || custActions.Actions.Length == 0) { var item = customActionsToolStripMenuItem.DropDownItems.Add("(No custom actions)"); item.Enabled = false; } }
private static void InitPlugins(IList <Assembly> plugins) { Plugins = plugins; _pluginNamespaces = plugins.SelectMany(p => p.GetExportedTypes()).Select(t => new AssemblyNamespace { Assembly = t.Assembly, Namespace = t.Namespace }).Distinct().ToList(); try { if (!File.Exists(WrapperDllPath)) { (new FileInfo(WrapperDllPath)).Directory.Create(); OutputWrapperDll(); } else { // Check if WrapperDll is of same version as the TabularEditor.exe and same Compatibility Level. If not, output a new one: var wrapperVersion = FileVersionInfo.GetVersionInfo(WrapperDllPath); var currentVersion = Assembly.GetAssembly(typeof(TabularModelHandler)).GetName().Version; if (wrapperVersion.FileVersion != currentVersion.ToString()) { OutputWrapperDll(); } } if (File.Exists(CustomActionsJsonPath)) { Console.WriteLine("Loading custom actions from: " + CustomActionsJsonPath); var actions = CustomActionsJson.LoadFromJson(CustomActionsJsonPath); actions.SaveToJson(@"C:\TE\testactions.json"); CompileCustomActions(actions); } else { ScriptEngineStatus = "File not found: " + CustomActionsJsonPath; } } catch (Exception ex) { Debug.WriteLine(ex.Message); ScriptEngineStatus = "Error: " + ex.Message; } }
private static void InitCustomActions() { try { if (File.Exists(CustomActionsJsonPath)) { Console.WriteLine("Loading custom actions from: " + CustomActionsJsonPath); var actions = CustomActionsJson.LoadFromJson(CustomActionsJsonPath); CompileCustomActions(actions); } else { ScriptEngineStatus = "File not found: " + CustomActionsJsonPath; } } catch (Exception ex) { Debug.WriteLine(ex.Message); ScriptEngineStatus = "Error: " + ex.Message; } }
private void PopulateCustomActionsDropDown() { customActionsToolStripMenuItem.DropDownItems.Clear(); if (File.Exists(ScriptEngine.CustomActionsJsonPath)) { custActions = CustomActionsJson.LoadFromJson(ScriptEngine.CustomActionsJsonPath); foreach (var act in custActions.Actions) { customActionsToolStripMenuItem.DropDownItems.Add(act.Name, null, (s, e) => { CurrentCustomAction = act.Name; txtAdvanced.Text = act.Execute; }); } } if (custActions == null || custActions.Actions.Length == 0) { var item = customActionsToolStripMenuItem.DropDownItems.Add("(No custom actions)"); item.Enabled = false; } }
public FormMain() { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); InitializeComponent(); dlgOpenFile.Filter = "Tabular Model Files|*.bim;database.json|Power BI Files|*.pbit|All files|*.*"; dlgSaveFile.Filter = "Tabular Model Files|*.bim|Power BI Files|*.pbit|All files|*.*"; // For some reason, Visual Studio sometimes removes this from the FormMain.Designer.cs, making the // colors of the lines look ugly: propertyGrid1.LineColor = System.Drawing.SystemColors.InactiveBorder; // Assign our own custom Designer, to make sure we can handle property changes on multiple objects simultaneously: propertyGrid1.Site = new DesignerHost(); // "Select Namespace" button should only be visible if we have loaded any plug-ins: toolStripButton3.Visible = ScriptEngine.PluginNamespaces.Count > 0; SetupUIController(); txtFilter.Control.SetCueBanner("Filter"); ///// Populate custom actions and samples ///// // TODO: Do this somewhere else if (File.Exists(ScriptEngine.CustomActionsJsonPath)) { custActions = CustomActionsJson.LoadFromJson(ScriptEngine.CustomActionsJsonPath); foreach (var act in custActions.Actions) { customActionsToolStripMenuItem.DropDownItems.Add(act.Name, null, (s, e) => { CurrentCustomAction = act.Name; txtAdvanced.Text = act.Execute; }); } } if (custActions == null || custActions.Actions.Length == 0) { var item = customActionsToolStripMenuItem.DropDownItems.Add("(No custom actions)"); item.Enabled = false; } var tutorial = (samplesMenu.DropDownItems.Add("Tutorials") as ToolStripMenuItem).DropDownItems; var translations = (samplesMenu.DropDownItems.Add("Translations") as ToolStripMenuItem).DropDownItems; tutorial.Add("Loop through all selected columns", null, (s, e) => { txtAdvanced.InsertText( @"foreach(var column in Selected.Columns) { // column.DisplayFolder = ""Test""; }"); }); tutorial.Add("Loop through all selected tables", null, (s, e) => { txtAdvanced.InsertText( @"foreach(var table in Selected.Tables) { // table.IsHidden = false; }"); }); tutorial.Add("Loop through columns on all selected tables", null, (s, e) => { txtAdvanced.InsertText( @"foreach(var column in Selected.Tables.SelectMany(t => t.Columns)) { // column.DisplayFolder = ""test""; }"); }); tutorial.Add("Loop through columns on all tables conditionally", null, (s, e) => { txtAdvanced.InsertText( @"foreach(var column in Model.Tables.SelectMany(t => t.Columns)) { if(column.Name.EndsWith(""Key"")) { // column.IsHidden = true; } }"); }); translations.Add("Copy display folder to active translation", null, (s, e) => { txtAdvanced.InsertText( @"Selected.Measures.ForEach(item => item.TranslatedDisplayFolders[Selected.Culture] = item.DisplayFolder); Selected.Columns.ForEach(item => item.TranslatedDisplayFolders[Selected.Culture] = item.DisplayFolder); Selected.Hierarchies.ForEach(item => item.TranslatedDisplayFolders[Selected.Culture] = item.DisplayFolder);"); }); translations.Add("Copy display folder to all translations", null, (s, e) => { txtAdvanced.InsertText( @"Selected.Measures.ForEach(item => item.TranslatedDisplayFolders.SetAll(item.DisplayFolder)); Selected.Columns.ForEach(item => item.TranslatedDisplayFolders.SetAll(item.DisplayFolder)); Selected.Hierarchies.ForEach(item => item.TranslatedDisplayFolders.SetAll(item.DisplayFolder));"); }); }