/// <summary> /// Export a macro /// </summary> private void ExportEvent() { if (DockManager.ActiveDocument == null) { return; } FileDeclaration macro = DockManager.ActiveDocument.Declaration; if (macro == null) { return; } macro.Export(); }
/// <summary> /// Creates a contextmenu for a tree view item file /// </summary> /// <param name="item">The item for which the context menu is being made</param> /// <param name="name">The name of the macro</param> /// <param name="id">The id of the macro</param> /// <returns>File TreeViewItem ContextMenu</returns> private ContextMenu CreateContextMenuMacro(DisplayableTreeViewItem item, string name, FileDeclaration d) { Style ContextMenuStyle = MainWindow.GetInstance().GetResource("MetroContextMenuStyle") as Style; Style MenuItemStyle = MainWindow.GetInstance().GetResource("MetroMenuItemStyle") as Style; Style SeparatorStyle = MainWindow.GetInstance().GetResource("MertoMenuSeparatorStyle") as Style; ContextMenu cm = new ContextMenu(); cm.Resources.MergedDictionaries.Add(MainWindow.GetInstance().GetResources()); cm.Style = ContextMenuStyle; DisplayableTreeViewItem parentitem = item.Parent; if (d == null) { MacroUI.GetInstance().DisplayOkMessage("Could not get the macro (when attempting to create a context menu): " + name, "Macro Error"); return(null); } MenuItem mi_edit = new MenuItem(); mi_edit.Header = "Edit"; mi_edit.Click += delegate(object sender, RoutedEventArgs args) { OpenMacro(d); args.Handled = true; cm.IsOpen = false; }; mi_edit.Style = MenuItemStyle as Style; cm.Items.Add(mi_edit); MenuItem mi_execute = new MenuItem(); mi_execute.Header = "Synchronous Execute"; mi_execute.ToolTip = "Synchronous executions cannot be terminated."; mi_execute.Click += delegate(object sender, RoutedEventArgs args) { ExecuteMacro(d, false); args.Handled = true; cm.IsOpen = false; }; mi_execute.Style = MenuItemStyle as Style; cm.Items.Add(mi_execute); MenuItem mi_executea = new MenuItem(); mi_executea.Header = "Asynchronous Execute"; mi_executea.ToolTip = "Asynchronous executions can be terminated."; mi_executea.Click += delegate(object sender, RoutedEventArgs args) { ExecuteMacro(d, true); args.Handled = true; cm.IsOpen = false; }; mi_executea.Style = MenuItemStyle as Style; cm.Items.Add(mi_executea); Separator sep1 = new Separator(); sep1.Style = SeparatorStyle as Style; cm.Items.Add(sep1); MenuItem mi_export = new MenuItem(); mi_export.Header = "Export"; mi_export.Click += delegate(object sender, RoutedEventArgs args) { d.Export(); args.Handled = true; cm.IsOpen = false; }; mi_export.Style = MenuItemStyle as Style; cm.Items.Add(mi_export); MenuItem mi_del = new MenuItem(); mi_del.Header = "Delete"; mi_del.Click += delegate(object sender, RoutedEventArgs args) { DeleteMacro(item, d); args.Handled = true; cm.IsOpen = false; }; mi_del.Style = MenuItemStyle as Style; cm.Items.Add(mi_del); MenuItem mi_rename = new MenuItem(); mi_rename.Header = "Rename"; mi_rename.Click += delegate(object sender, RoutedEventArgs args) { args.Handled = true; cm.IsOpen = false; string previousname = item.Header; item.KeyUpEvent = delegate(object s, KeyEventArgs a) { if (a.Key == Key.Return) { Focus(); Keyboard.ClearFocus(); } else if (a.Key == Key.Escape) { item.Header = previousname; Focus(); Keyboard.ClearFocus(); } }; item.FocusLostEvent = delegate(object s, RoutedEventArgs a) { if (item.Header == previousname) { item.IsInputting = false; return; } if (String.IsNullOrEmpty(item.Header)) { MacroUI.GetInstance().DisplayOkMessage("Please enter a valid name.", "Invalid Name"); item.IsInputting = true; return; } if (!Path.HasExtension(item.Header)) { item.Header += MacroUI.GetInstance().GetDefaultFileExtension(); } MainWindowViewModel.GetInstance().RenameMacro(d, item.Header); Rename(parentitem, item); item.IsInputting = false; }; item.IsInputting = true; }; mi_rename.Style = MenuItemStyle as Style; cm.Items.Add(mi_rename); Separator sep2 = new Separator(); sep2.Style = SeparatorStyle; cm.Items.Add(sep2); return(cm); }