protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.ListView> e) { base.OnElementChanged(e); if (e.OldElement != null) { // Unsubscribe } if (e.NewElement != null) { //Control.Source = new NativeiOSListViewSource(e.NewElement as UIListView); uiListView = e.NewElement as UIListView; uiTableView = Control; //Control.Delegate = new ListViewDelegate(); //Control.AllowsSelection = false; uiTableView.AllowsMultipleSelection = true; //uiTableView.Source. //Control.Source = new NativeiOSListViewSource(e.NewElement as UIListView); var longPressGesture = new UILongPressGestureRecognizer(LongPressMethod); AddGestureRecognizer(longPressGesture); } }
public override void OnInspectorGUI() { //base.OnInspectorGUI(); serializedObject.Update(); UIListView listView = target as UIListView; listView.direction = (UIListView.Direction)EditorGUILayout.EnumPopup("Direction", listView.direction); SerializedProperty sp = serializedObject.FindProperty("ItemPrefab"); if (sp != null) { EditorGUILayout.PropertyField(sp, new GUIContent("Item Template")); } if (listView.direction == UIListView.Direction.Vertical) { listView.colOrRowCount = EditorGUILayout.IntField("Column Count", listView.colOrRowCount); } else { listView.colOrRowCount = EditorGUILayout.IntField("Row Count", listView.colOrRowCount); } serializedObject.ApplyModifiedProperties(); }
private void tsmiNewScriptFile_Click(object sender, EventArgs e) { try { string newName = ""; var newNameForm = new frmInputBox("Enter the name of the new file without extension", "New File"); newNameForm.txtInput.Text = tvProject.SelectedNode.Name; newNameForm.ShowDialog(); if (newNameForm.DialogResult == DialogResult.OK) { newName = newNameForm.txtInput.Text; } else if (newNameForm.DialogResult == DialogResult.Cancel) { return; } if (newName.EndsWith(".json")) { throw new Exception("Invalid file name"); } string selectedNodePath = tvProject.SelectedNode.Tag.ToString(); string newFilePath = Path.Combine(selectedNodePath, newName + ".json"); UIListView newScriptActions = NewLstScriptActions(); List <ScriptVariable> newScripVariables = new List <ScriptVariable>(); List <ScriptElement> newScriptElements = new List <ScriptElement>(); var helloWorldCommand = new ShowMessageCommand(); helloWorldCommand.v_Message = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); if (!File.Exists(newFilePath)) { Script.SerializeScript(newScriptActions.Items, newScripVariables, newScriptElements, newFilePath); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenFile(newFilePath); } else { int count = 1; string newerFilePath = newFilePath; while (File.Exists(newerFilePath)) { string newDirectoryPath = Path.GetDirectoryName(newFilePath); string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFilePath); newerFilePath = Path.Combine(newDirectoryPath, $"{newFileNameWithoutExtension} ({count}).json"); count += 1; } Script.SerializeScript(newScriptActions.Items, newScripVariables, newScriptElements, newerFilePath); NewNode(tvProject.SelectedNode, newerFilePath, "file"); OpenFile(newerFilePath); } } catch (Exception ex) { Notify("An Error Occured: " + ex.Message, Color.Red); } }
private void Mc_Click(object sender, EventArgs e) { UIListView.SuspendLayout(); selected = GetParentMusicControl((Control)sender).Element; ChangeDescription(selected); Invoke((MethodInvoker) delegate { }); UIListView.ResumeLayout(false); }
protected override void InitUI(UIWidget layout) { UIListView listView = GetTarget <UIListView>(); UIEnumFieldWidget movementType = new UIEnumFieldWidget("MovementType", listView.movementType); movementType.OnValueChanged = (Object value) => { listView.movementType = (ScrollRect.MovementType)value; UpdateElasticity(layout, movementType); }; layout.Add(movementType); UpdateElasticity(layout, movementType); //////////////////////////////////////////////////////////// UIBooleanFieldWidget inertia = new UIBooleanFieldWidget("Inertia", listView.inertia); inertia.OnValueChanged = (Object value) => { listView.inertia = (bool)value; UpdateDecelerationRate(layout, inertia); }; layout.Add(inertia); UpdateDecelerationRate(layout, inertia); //////////////////////////////////////////////////////////// UIFloatFieldWidget scrollSensitivity = new UIFloatFieldWidget("ScrollSensitivity", listView.scrollSensitivity); scrollSensitivity.OnValueChanged = (Object value) => { listView.scrollSensitivity = (float)value; }; layout.Add(scrollSensitivity); //////////////////////////////////////////////////////////// UIEnumFieldWidget direction = new UIEnumFieldWidget("Direction", listView.Direction); direction.OnValueChanged = (Object value) => { listView.Direction = (ScrollDirection)value; }; layout.Add(direction); GUIButton btn = new GUIButton(); btn.Text = "Format"; btn.TriggerHandler = (Widget w) => { listView.FormatScrollView(); }; layout.Add(btn); }
override protected void DrawInspectorGUI() { UIListView tTarget = target as UIListView; EditorGUILayout.Separator(); // 少し区切りスペース //------------------------------------------------------------------- // スクロールバーの有無 DrawScrollbar(tTarget); // アイテムの追加と削除 DrawItem(tTarget); }
public void CreateOpenBotsProject(string mainScriptName, string mainScriptPath) { //create OpenBots specific project UIListView mainScriptActions = NewLstScriptActions(mainScriptName); List <ScriptVariable> mainScriptVariables = new List <ScriptVariable>(); List <ScriptArgument> mainScriptArguments = new List <ScriptArgument>(); List <ScriptElement> mainScriptElements = new List <ScriptElement>(); Dictionary <string, List <AssemblyReference> > mainImportedNamespaces = new Dictionary <string, List <AssemblyReference> >(ScriptDefaultNamespaces.DefaultNamespaces); try { dynamic helloWorldCommand = TypeMethods.CreateTypeInstance(AContainer, "ShowMessageCommand"); helloWorldCommand.v_Message = "\"Hello World\""; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); } catch (Exception) { var brokenHelloWorldCommand = new BrokenCodeCommentCommand(); brokenHelloWorldCommand.v_Comment = "Hello World"; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(brokenHelloWorldCommand)); } //begin saving as main.xml ClearSelectedListViewItems(); try { //serialize main script EngineContext engineContext = new EngineContext { Variables = mainScriptVariables, Arguments = mainScriptArguments, Elements = mainScriptElements, ImportedNamespaces = mainImportedNamespaces, FilePath = mainScriptPath, Container = AContainer }; var mainScript = Script.SerializeScript(mainScriptActions.Items, engineContext); _mainFileName = ScriptProject.Main; OpenOpenBotsFile(mainScriptPath); } catch (Exception ex) { Notify("An Error Occurred: " + ex.Message, Color.Red); } }
//Methods protected override void OnElementChanged(ElementChangedEventArgs <FListView> e) { base.OnElementChanged(e); if (e.NewElement != null) { // Configure the native control and subscribe to event handlers uiListView = Element as UIListView; nativeListView = Control as NListView; viewModel = uiListView.BindingContext as NotificationsViewModel; nativeListView.ItemLongClick += nativeListView_OnItemLongClick; nativeListView.ChoiceMode = ChoiceMode.Multiple; nativeListView.ItemsCanFocus = false; //nativeListView.ItemClick += NativeListView_ItemClick; //nativeListView.SetMultiChoiceModeListener(new MultiChoiceModeListener()); } }
private UIListView NewLstScriptActions(string title = "newLstScriptActions") { UIListView newLstScriptActions = new UIListView(); newLstScriptActions.AllowDrop = true; newLstScriptActions.BackColor = Color.WhiteSmoke; newLstScriptActions.BorderStyle = BorderStyle.None; newLstScriptActions.Columns.AddRange(new ColumnHeader[] { new ColumnHeader(), new ColumnHeader { Width = 20 }, new ColumnHeader { Text = "Script Commands", Width = -2 } }); newLstScriptActions.Dock = DockStyle.Fill; newLstScriptActions.Font = new Font("Segoe UI", 11, FontStyle.Bold, GraphicsUnit.Point, 0); newLstScriptActions.FullRowSelect = true; newLstScriptActions.HeaderStyle = ColumnHeaderStyle.None; newLstScriptActions.HideSelection = false; newLstScriptActions.Location = new Point(3, 3); newLstScriptActions.Margin = new Padding(6); newLstScriptActions.Name = title; newLstScriptActions.OwnerDraw = true; newLstScriptActions.Size = new Size(1063, 411); newLstScriptActions.TabIndex = 6; newLstScriptActions.UseCompatibleStateImageBehavior = false; newLstScriptActions.View = View.Details; newLstScriptActions.DrawSubItem += new DrawListViewSubItemEventHandler(lstScriptActions_DrawSubItem); newLstScriptActions.ItemDrag += new ItemDragEventHandler(lstScriptActions_ItemDrag); newLstScriptActions.SelectedIndexChanged += new EventHandler(lstScriptActions_SelectedIndexChanged); newLstScriptActions.DragDrop += new DragEventHandler(lstScriptActions_DragDrop); newLstScriptActions.DragEnter += new DragEventHandler(lstScriptActions_DragEnter); newLstScriptActions.DoubleClick += new EventHandler(lstScriptActions_DoubleClick); newLstScriptActions.KeyDown += new KeyEventHandler(lstScriptActions_KeyDown); newLstScriptActions.MouseClick += new MouseEventHandler(lstScriptActions_MouseClick); newLstScriptActions.MouseMove += new MouseEventHandler(lstScriptActions_MouseMove); newLstScriptActions.Tag = new ScriptActionTag(); newLstScriptActions.ShowItemToolTips = true; return(newLstScriptActions); }
private void UpdateElasticity(Layout layout, Widget w) { UIListView listView = GetTarget <UIListView>(); if (listView.movementType == ScrollRect.MovementType.Elastic) { if (elasticity == null) { elasticity = new UIFloatFieldWidget(" Elasticity", listView.elasticity); elasticity.OnValueChanged = (Object value) => { listView.elasticity = (float)value; }; } layout.InsertAfter(w, elasticity); } else { layout.Remove(elasticity); } }
private void UpdateDecelerationRate(Layout layout, Widget w) { UIListView listView = GetTarget <UIListView>(); if (listView.inertia) { if (decelerationRate == null) { decelerationRate = new UIFloatFieldWidget(" DecelerationRate", listView.decelerationRate); decelerationRate.OnValueChanged = (Object value) => { listView.decelerationRate = (float)value; }; } layout.InsertAfter(w, decelerationRate); } else { layout.Remove(decelerationRate); } }
private void tsmiNewScriptFile_Click(object sender, EventArgs e) { try { string selectedNodePath = tvProject.SelectedNode.Tag.ToString(); string newFilePath = Path.Combine(selectedNodePath, "New Script.json"); UIListView newScriptActions = NewLstScriptActions(); List <ScriptVariable> newScripVariables = new List <ScriptVariable>(); List <ScriptElement> newScriptElements = new List <ScriptElement>(); var helloWorldCommand = new ShowMessageCommand(); helloWorldCommand.v_Message = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); if (!File.Exists(newFilePath)) { Script.SerializeScript(newScriptActions.Items, newScripVariables, newScriptElements, newFilePath, _scriptProject.ProjectName); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenFile(newFilePath); } else { int count = 1; string newerFilePath = newFilePath; while (File.Exists(newerFilePath)) { string newDirectoryPath = Path.GetDirectoryName(newFilePath); string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFilePath); newerFilePath = Path.Combine(newDirectoryPath, $"{newFileNameWithoutExtension} ({count}).json"); count += 1; } Script.SerializeScript(newScriptActions.Items, newScripVariables, newScriptElements, newerFilePath, _scriptProject.ProjectName); NewNode(tvProject.SelectedNode, newerFilePath, "file"); OpenFile(newerFilePath); } } catch (Exception ex) { Notify("An Error Occured: " + ex.Message); } }
private static void AddListView(string tType) { GameObject tGameObject = Selection.activeGameObject; if (tGameObject == null) { return; } if (WillLosePrefab(tGameObject) == false) { return; } Undo.RecordObject(tGameObject, "Add a child UI ListView"); // アンドウバッファに登録 string tName = GetName <UIListView>(); if (string.IsNullOrEmpty(tType) == false) { tName = tName + "(" + tType + ")"; } GameObject tChild = new GameObject(tName, typeof(RectTransform)); Transform tTransform = tChild.transform; tTransform.SetParent(tGameObject.transform, false); tTransform.localPosition = Vector3.zero; tTransform.localRotation = Quaternion.identity; tTransform.localScale = Vector3.one; UIListView tScrollView = tChild.AddComponent <UIListView>(); tScrollView.SetDefault(tType); Selection.activeGameObject = tChild; UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); }
private void FillSearchListBoxesThreadSafe(IEnumerable <IElement> elements) { //UIListView.SuspendLayout(); foreach (Element e in elements) { if (e is Playlist) { for (int i = 0; i < UIListView.Controls.Count; i++) { if (((MusicControl)UIListView.Controls[i]).Element.MID == (e as Playlist).MID) { ((MusicControl)UIListView.Controls[i]).MergePlaylist(e as Playlist); return; } } } var mc = new MusicControl().UpdateControl(e); GetAllClickEvent(mc); UIListView.Controls.Add(mc); } UIListView.Refresh(); //UIListView.ResumeLayout(false); }
public void AddProject() { tvProject.Nodes.Clear(); var projectBuilder = new frmProjectBuilder(); projectBuilder.ShowDialog(); //Close taskt if add project form is closed at startup if (projectBuilder.DialogResult == DialogResult.Cancel && _scriptProject == null) { Application.Exit(); return; } //Create new taskt project else if (projectBuilder.CreateProject == true) { DialogResult result = CheckForUnsavedScripts(); if (result == DialogResult.Cancel) { return; } uiScriptTabControl.TabPages.Clear(); _scriptProjectPath = projectBuilder.NewProjectPath; string mainScriptPath = Path.Combine(_scriptProjectPath, "Main.json"); string mainScriptName = Path.GetFileNameWithoutExtension(mainScriptPath); UIListView mainScriptActions = NewLstScriptActions(mainScriptName); List <ScriptVariable> mainScriptVariables = new List <ScriptVariable>(); List <ScriptElement> mainScriptElements = new List <ScriptElement>(); ShowMessageCommand helloWorldCommand = new ShowMessageCommand(); helloWorldCommand.v_Message = "Hello World"; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); //Begin saving as main.xml ClearSelectedListViewItems(); try { //Serialize main script var mainScript = Script.SerializeScript(mainScriptActions.Items, mainScriptVariables, mainScriptElements, mainScriptPath, projectBuilder.NewProjectName); //Create new project Project proj = new Project(projectBuilder.NewProjectName); _mainFileName = proj.Main; //Save new project proj.SaveProject(mainScriptPath, mainScript, _mainFileName); //Open new project _scriptProject = Project.OpenProject(mainScriptPath); //Open main script OpenFile(mainScriptPath); ScriptFilePath = mainScriptPath; //Show success dialog Notify("Project has been created successfully!"); } catch (Exception ex) { Notify("An Error Occured: " + ex.Message); } } //Open existing taskt project else if (projectBuilder.OpenProject == true) { DialogResult result = CheckForUnsavedScripts(); if (result == DialogResult.Cancel) { return; } try { //Open project _scriptProject = Project.OpenProject(projectBuilder.ExistingMainPath); _mainFileName = _scriptProject.Main; if (Path.GetFileName(projectBuilder.ExistingMainPath) != _mainFileName) { throw new Exception("Attempted to open project from a script that isn't Main"); } _scriptProjectPath = Path.GetDirectoryName(projectBuilder.ExistingMainPath); uiScriptTabControl.TabPages.Clear(); //Open Main OpenFile(projectBuilder.ExistingMainPath); //show success dialog Notify("Project has been opened successfully!"); } catch (Exception ex) { //show fail dialog Notify("An Error Occured: " + ex.Message); //Try adding project again AddProject(); return; } } DirectoryInfo projectDirectoryInfo = new DirectoryInfo(_scriptProjectPath); TreeNode projectNode = new TreeNode(projectDirectoryInfo.Name); projectNode.Text = projectDirectoryInfo.Name; projectNode.Tag = projectDirectoryInfo.FullName; projectNode.Nodes.Add("Empty"); projectNode.ContextMenuStrip = cmsProjectMainFolderActions; tvProject.Nodes.Add(projectNode); projectNode.Expand(); }
public NativeiOSListViewSource(UIListView view) { tableItems = view.ItemsSource; listView = view; }
// Item 関係 protected void DrawItem(UIListView tTarget) { if (tTarget._scrollRect == null || tTarget._scrollRect.content == null) { return; } EditorGUILayout.Separator(); // 少し区切りスペース // GUILayout.Label( "Type " + tTarget.buildType, GUILayout.Width( 120f ) ) ; EditorGUIUtility.labelWidth = 100f; EditorGUIUtility.fieldWidth = 40f; // テンプレート UIView tContentItem = EditorGUILayout.ObjectField("Item(Template)", tTarget.item, typeof(UIView), true) as UIView; if (tContentItem != tTarget.item) { Undo.RecordObject(tTarget, "UIListView Item(Template) : Change"); // アンドウバッファに登録 tTarget.item = tContentItem; EditorUtility.SetDirty(tTarget); } EditorGUIUtility.labelWidth = 116f; EditorGUIUtility.fieldWidth = 40f; //------------------------------------------------ GUILayout.BeginHorizontal(); // 横並び開始 { int tWorkingItemCount = EditorGUILayout.IntField("Working Item Count", tTarget.workingItemCount); if (tWorkingItemCount != tTarget.workingItemCount) { Undo.RecordObject(tTarget, "UIListView : Working Item Count Change"); // アンドウバッファに登録 tTarget.workingItemCount = tWorkingItemCount; EditorUtility.SetDirty(tTarget); } } GUILayout.EndHorizontal(); // 横並び終了 float tWorkingMargin = EditorGUILayout.FloatField("Working Margin", tTarget.workingMargin); if (tWorkingMargin != tTarget.workingMargin) { Undo.RecordObject(tTarget, "UIListView : Working Margin Change"); // アンドウバッファに登録 tTarget.workingMargin = tWorkingMargin; EditorUtility.SetDirty(tTarget); } GUILayout.BeginHorizontal(); // 横並び { bool tInfinity = EditorGUILayout.Toggle(tTarget.infinity, GUILayout.Width(16f)); if (tInfinity != tTarget.infinity) { Undo.RecordObject(tTarget, "UIListView : Infinity Change"); // アンドウバッファに登録 tTarget.infinity = tInfinity; EditorUtility.SetDirty(tTarget); } GUILayout.Label("Infinity", GUILayout.Width(80f)); if (tTarget.infinity == false) { // GUILayout.Label( "Max", GUILayout.Width( 40f ) ) ; EditorGUIUtility.labelWidth = 80f; EditorGUIUtility.fieldWidth = 40f; int tItemCount = EditorGUILayout.IntField("Item Count", tTarget.itemCount); if (tItemCount != tTarget.itemCount) { Undo.RecordObject(tTarget, "UIListView : Item Count Change"); // アンドウバッファに登録 tTarget.itemCount = tItemCount; EditorUtility.SetDirty(tTarget); // if( Application.isPlaying == false ) // { // UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty( UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene() ) ; // } } EditorGUIUtility.labelWidth = 116f; EditorGUIUtility.fieldWidth = 40f; } } GUILayout.EndHorizontal(); // 横並び終了 GUILayout.BeginHorizontal(); // 横並び { bool tSnap = EditorGUILayout.Toggle(tTarget.snap, GUILayout.Width(16f)); if (tSnap != tTarget.snap) { Undo.RecordObject(tTarget, "UIListView : Snap Change"); // アンドウバッファに登録 tTarget.snap = tSnap; EditorUtility.SetDirty(tTarget); } GUILayout.Label("Snap", GUILayout.Width(80f)); if (tTarget.snap == true) { EditorGUIUtility.labelWidth = 80f; EditorGUIUtility.fieldWidth = 40f; float tSnapThreshold = EditorGUILayout.FloatField("Threshold", tTarget.snapThreshold); if (tSnapThreshold != tTarget.snapThreshold) { Undo.RecordObject(tTarget, "UIListView : Snap Threshold Change"); // アンドウバッファに登録 tTarget.snapThreshold = tSnapThreshold; EditorUtility.SetDirty(tTarget); } EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 40f; float tSnapTime = EditorGUILayout.FloatField("Time", tTarget.snapTime); if (tSnapTime != tTarget.snapTime) { Undo.RecordObject(tTarget, "UIListView : Snap Time Change"); // アンドウバッファに登録 tTarget.snapTime = tSnapTime; EditorUtility.SetDirty(tTarget); } EditorGUIUtility.labelWidth = 116f; EditorGUIUtility.fieldWidth = 40f; } } GUILayout.EndHorizontal(); // 横並び終了 if (tTarget.snap == true) { UIListView.SnapAnchor tSnapPosition = (UIListView.SnapAnchor)EditorGUILayout.EnumPopup("Snap Anchor", tTarget.snapAnchor); if (tSnapPosition != tTarget.snapAnchor) { Undo.RecordObject(tTarget, "UIListView : Snap Anchor Change"); // アンドウバッファに登録 tTarget.snapAnchor = tSnapPosition; EditorUtility.SetDirty(tTarget); } } // アイテムの更新が必要な時に呼び出されるイベント // デリゲートの設定状況 SerializedObject tSO = new SerializedObject(tTarget); SerializedProperty tSP = tSO.FindProperty("onUpdateItem"); if (tSP != null) { EditorGUILayout.PropertyField(tSP); } tSO.ApplyModifiedProperties(); }
private void tsmiNewScriptFile_Click(object sender, EventArgs e) { try { string newName = ""; var newNameForm = new frmInputBox("Enter the name of the new file WITH extension", "New File"); switch (ScriptProject.ProjectType) { case ProjectType.OpenBots: newNameForm.txtInput.Text = ".obscript"; break; case ProjectType.Python: newNameForm.txtInput.Text = ".py"; break; case ProjectType.TagUI: newNameForm.txtInput.Text = ".tag"; break; case ProjectType.CSScript: newNameForm.txtInput.Text = ".cs"; break; } newNameForm.ShowDialog(); if (newNameForm.DialogResult == DialogResult.OK) { newName = newNameForm.txtInput.Text; newNameForm.Dispose(); } else if (newNameForm.DialogResult == DialogResult.Cancel) { newNameForm.Dispose(); return; } if (!Path.HasExtension(newName)) { throw new FileFormatException($"No extension provided for '{newName}'"); } string selectedNodePath = tvProject.SelectedNode.Tag.ToString(); string newFilePath = Path.Combine(selectedNodePath, newName); string extension = Path.GetExtension(newFilePath); if (File.Exists(newFilePath)) { int count = 1; string newerFilePath = newFilePath; while (File.Exists(newerFilePath)) { string newDirectoryPath = Path.GetDirectoryName(newFilePath); string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFilePath); newerFilePath = Path.Combine(newDirectoryPath, $"{newFileNameWithoutExtension} ({count}){extension}"); count += 1; } newFilePath = newerFilePath; } switch (extension.ToLower()) { case ".obscript": UIListView newScriptActions = NewLstScriptActions(); List <ScriptVariable> newScriptVariables = new List <ScriptVariable>(); List <ScriptArgument> newScriptArguments = new List <ScriptArgument>(); List <ScriptElement> newScriptElements = new List <ScriptElement>(); try { dynamic helloWorldCommand = TypeMethods.CreateTypeInstance(AContainer, "ShowMessageCommand"); helloWorldCommand.v_Message = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); } catch (Exception) { var brokenHelloWorldCommand = new BrokenCodeCommentCommand(); brokenHelloWorldCommand.v_Comment = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(brokenHelloWorldCommand)); } EngineContext engineContext = new EngineContext { Variables = newScriptVariables, Arguments = newScriptArguments, Elements = newScriptElements, FilePath = newFilePath, Container = AContainer }; Script.SerializeScript(newScriptActions.Items, engineContext); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenOpenBotsFile(newFilePath); break; case ".py": File.WriteAllText(newFilePath, _helloWorldTextPython); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.Python); break; case ".tag": File.WriteAllText(newFilePath, _helloWorldTextTagUI); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.TagUI); break; case ".cs": File.WriteAllText(newFilePath, _helloWorldTextCSScript); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.CSScript); break; default: File.Create(newFilePath).Close(); NewNode(tvProject.SelectedNode, newFilePath, "file"); return; } } catch (Exception ex) { Notify("An Error Occured: " + ex.Message, Color.Red); } }
public void AddProject() { tvProject.Nodes.Clear(); var projectBuilder = new frmProjectBuilder(); projectBuilder.ShowDialog(); //Close OpenBots if add project form is closed at startup if (projectBuilder.DialogResult == DialogResult.Cancel && ScriptProject == null) { Application.Exit(); return; } //Create new OpenBots project else if (projectBuilder.CreateProject == true) { DialogResult result = CheckForUnsavedScripts(); if (result == DialogResult.Cancel) { return; } uiScriptTabControl.TabPages.Clear(); ScriptProjectPath = projectBuilder.NewProjectPath; string configPath = Path.Combine(ScriptProjectPath, "project.config"); string mainScriptPath = Path.Combine(ScriptProjectPath, "Main.json"); string mainScriptName = Path.GetFileNameWithoutExtension(mainScriptPath); UIListView mainScriptActions = NewLstScriptActions(mainScriptName); List <ScriptVariable> mainScriptVariables = new List <ScriptVariable>(); List <ScriptElement> mainScriptElements = new List <ScriptElement>(); ShowMessageCommand helloWorldCommand = new ShowMessageCommand(); helloWorldCommand.v_Message = "Hello World"; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); //Begin saving as main.xml ClearSelectedListViewItems(); try { //Serialize main script var mainScript = Script.SerializeScript(mainScriptActions.Items, mainScriptVariables, mainScriptElements, mainScriptPath); //Create new project ScriptProject = new Project(projectBuilder.NewProjectName); _mainFileName = ScriptProject.Main; //create config file File.WriteAllText(configPath, JsonConvert.SerializeObject(ScriptProject)); OpenFile(mainScriptPath); ScriptFilePath = mainScriptPath; //Show success dialog Notify("Project has been created successfully!", Color.White); } catch (Exception ex) { Notify("An Error Occured: " + ex.Message, Color.Red); } } //Open existing OpenBots project else if (projectBuilder.OpenProject == true) { DialogResult result = CheckForUnsavedScripts(); if (result == DialogResult.Cancel) { return; } try { //Open project ScriptProject = Project.OpenProject(projectBuilder.ExistingConfigPath); _mainFileName = ScriptProject.Main; string mainFilePath = Directory.GetFiles(projectBuilder.ExistingProjectPath, _mainFileName, SearchOption.AllDirectories).FirstOrDefault(); if (mainFilePath == null) { throw new Exception("Main script not found"); } ScriptProjectPath = projectBuilder.ExistingProjectPath; uiScriptTabControl.TabPages.Clear(); //Open Main OpenFile(mainFilePath); //show success dialog Notify("Project has been opened successfully!", Color.White); } catch (Exception ex) { //show fail dialog Notify("An Error Occured: " + ex.Message, Color.Red); //Try adding project again AddProject(); return; } } DirectoryInfo projectDirectoryInfo = new DirectoryInfo(ScriptProjectPath); TreeNode projectNode = new TreeNode(projectDirectoryInfo.Name); projectNode.Text = projectDirectoryInfo.Name; projectNode.Tag = projectDirectoryInfo.FullName; projectNode.Nodes.Add("Empty"); projectNode.ContextMenuStrip = cmsProjectMainFolderActions; tvProject.Nodes.Add(projectNode); projectNode.Expand(); }
public frmScriptBuilder() { _selectedTabScriptActions = NewLstScriptActions(); InitializeComponent(); }