public static T showEditor <T>(this API_GitHub_Issues gitHubIssues, T control) where T : Control { if (gitHubIssues.Repository.inValid()) { gitHubIssues.setupRepository("What is the repository you want to see?".askUser()); gitHubIssues.login(); } if (control.height() != 362) { "in API_GitHub_Issues showEditor the height was not 362, which will make some of the controls to show out of place".error(); } var topPanel = control.add_Panel(); topPanel.enabled(false); /// this code was developed as an H2 script var treeView = topPanel.insert_Left <Panel>(200).add_TreeView().sort(); treeView.splitContainer().splitterDistance(300); var actionsPanel = treeView.insert_Above <Panel>(30); var newIssue = treeView.insert_Below <GroupBox>(90).set_Text("New Issue").add_Panel(); Label Id = null; Label User = null; Label SavedMessage = null; Label CommentsLabel = null; Label NewCommentsLabel = null; TextBox Title = null; TextBox Body = null; Button SaveButton = null; Button CloseButton = null; TreeView Comments = null; TextBox NewComment = null; CheckBox EnableCloseButton = null; Dictionary <string, CheckBox> Labels = new Dictionary <string, CheckBox>(); Issue CurrentIssue = null; Action closeIssue = () => { "Closing issue with id: {0}".info(CurrentIssue.Number); gitHubIssues.close(CurrentIssue.Number); CurrentIssue.State = "Closed"; SavedMessage.set_Text("Issue closed"); }; Action saveIssue = () => { var updatedLabels = new List <string>(); foreach (var label in Labels) { if (label.Value.@checked()) { if (CurrentIssue.Labels.Contains(label.Key).isFalse()) { gitHubIssues.add_Label(CurrentIssue.Number, label.Key); } updatedLabels.Add(label.Key); } else if (CurrentIssue.Labels.Contains(label.Key)) { gitHubIssues.remove_Label(CurrentIssue.Number, label.Key); } } CurrentIssue.Labels = updatedLabels.ToArray(); if (CurrentIssue.Title != Title.get_Text() || CurrentIssue.Body != Body.get_Text()) { "values changed so executing an edit".debug(); CurrentIssue.Title = Title.get_Text(); CurrentIssue.Body = Body.get_Text(); gitHubIssues.edit(CurrentIssue); } var newCommentValue = NewComment.get_Text(); if (newCommentValue.valid()) { gitHubIssues.add_Comment(CurrentIssue.Number, newCommentValue); CurrentIssue.Comments++; Comments.add_Node(newCommentValue); NewComment.set_Text(""); } SavedMessage.set_Text("Issue saved").textColor(Color.Green); }; Action enableSaveButton = () => { SaveButton.enabled(true); SavedMessage.set_Text("Unsaved data").textColor(Color.Red); }; Action buildEditor = () => { var editPanel = topPanel.add_GroupBox("Selected Issue").add_Panel(); var left = 75; Id = editPanel.add_Label("id:", 5).append_Label("").left(left); //.font_bold() User = editPanel.add_Label("user:"******"").left(left).bringToFront(); Title = editPanel.add_TextBox(45, "title: ", "").left(left).align_Right(editPanel).bringToFront(); Body = editPanel.add_TextBox(65, "body: ", "").left(left).align_Right(editPanel) .multiLine() .height(65) .scrollBars(); SaveButton = editPanel.add_Button("Save", 280, left, () => saveIssue()) .enabled(false); SavedMessage = SaveButton.append_Label("...").topAdd(5).autoSize(); CloseButton = editPanel.add_Button("Close Issue", 310, left, () => closeIssue()).enabled(false); EnableCloseButton = CloseButton.append_Control <CheckBox>().set_Text("Enable 'Close Issue' button") .autoSize().topAdd(2) .checkedChanged((value) => CloseButton.enabled(value)); CommentsLabel = editPanel.add_Label("comments:", 150); Comments = CommentsLabel.append_Control <TreeView>().fill(false).left(left).align_Right(editPanel); NewCommentsLabel = editPanel.add_Label("new comment:", 250); NewComment = NewCommentsLabel.append_TextBox("").left(left).align_Right(editPanel).bringToFront(); foreach (var label in gitHubIssues.labels().sort()) { var checkBox = editPanel.add_CheckBox(130, left, label); Labels.add(label, checkBox); left += checkBox.width(); checkBox.checkedChanged((value) => enableSaveButton()); checkBox.anchor_BottomLeft(); } Title.onTextChange((text) => enableSaveButton()); Body.onTextChange((text) => enableSaveButton()); NewComment.onTextChange((text) => enableSaveButton()); Body.anchor_All(); EnableCloseButton.anchor_BottomLeft(); CloseButton.anchor_BottomLeft(); SavedMessage.anchor_BottomLeft(); SaveButton.anchor_BottomLeft(); Comments.anchor_BottomLeftRight(); CommentsLabel.anchor_BottomLeftRight(); NewComment.anchor_BottomLeftRight(); NewCommentsLabel.anchor_BottomLeftRight(); }; Action <Issue> showIssue = (issue) => { CurrentIssue = issue; "showing issue: {0}".info(issue.Title); topPanel.enabled(true); Id.set_Text("{0} ({1})".format(issue.Number, issue.State)); Title.set_Text(issue.Title); User.set_Text(issue.User); Body.set_Text(issue.Body.fixCRLF()); foreach (var label in Labels) { label.Value.@checked(issue.Labels.Contains(label.Key)); } Comments.clear(); Comments.enabled(false); if (issue.Comments > 0) { O2Thread.mtaThread( () => { foreach (var comment in gitHubIssues.comments(issue.Number)) { Comments.add_Node(comment.Body); } Comments.enabled(true); }); } SavedMessage.set_Text(""); SaveButton.enabled(false); CloseButton.enabled(false); EnableCloseButton.@checked(false); }; treeView.afterSelect <Issue>( (issue) => { treeView.selected().set_Text(issue.Title); showIssue(issue); }); Action showOpenIssues = () => treeView.showIssues(gitHubIssues.issues_open()); actionsPanel.add_Link("Open Issues", 0, 0, () => showOpenIssues()) .append_Link("Closed Issues", () => treeView.showIssues(gitHubIssues.issues_closed())) .append_Link("Show all data", () => O2Gui.open <Panel>("Open issues Data", 1000, 400).add_TableList().show(gitHubIssues.issues_open())); Action buildNewIssue = () => { var newIssue_Title = newIssue.add_TextBox(0, "title: ", "").left(40); var newIssue_Body = newIssue.add_TextBox(20, "body:", "").left(40); var newIssue_Button = newIssue.add_Button(42, "Create").left(40); newIssue_Button.onClick(() => { var title = newIssue_Title.get_Text(); var body = newIssue_Body.get_Text(); "Creating a new issue with title: {0} and body {1}".info(title, body); gitHubIssues.@new(title, body); showOpenIssues(); newIssue_Title.set_Text(""); newIssue_Body.set_Text(""); }); }; Action buildGui = () => { buildEditor(); buildNewIssue(); showOpenIssues(); }; buildGui(); return(control); }