private void cmdCreate_Click(object sender, System.EventArgs e) { if (this.txtCategory.Text.Trim() == "") { MessageBox.Show(this, "Please enter a category to assign to this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (this.txtTitle.Text.Trim() == "") { MessageBox.Show(this, "Please enter a title to assign to this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (this.txtCode.Text.Trim() == "") { MessageBox.Show(this, "Please enter some code for this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Create the snippet object CSnippetter.CodeEntry entry = new TSDev.CSnippetter.CodeEntry(txtTitle.Text, txtDescr.Text, txtCode.Text, txtCategory.Text); // Create the keywords txtKeywords.Text = txtKeywords.Text.Replace(",", ""); foreach (string keyword in txtKeywords.Text.Split(' ')) { entry.CodeKeywords.Add(keyword); } // Insert the snippet into the collection frmMain.stc_Snippets.CodeSnippets.Add(entry); // Refresh the main treeview //g.Main.SnippetterUC.RefreshTree(); // Close this window and dispose it this.DialogResult = DialogResult.OK; this.Close(); this.txtCode.Dispose(); this.Dispose(); }
private void mnuSnippetImport_Click(object sender, System.EventArgs e) { string id = frmMain.ShowPrompt("Import Snippet", "Please enter the ID of the snippet you wish to import.", "Enter snippet ID:"); if (id == "") return; // Construct a web server request WebClient client = new WebClient(); // Populate the querystrings client.QueryString.Add("op", "fetch"); client.QueryString.Add("id", id); // Execute the request string code = System.Text.ASCIIEncoding.ASCII.GetString(client.DownloadData("http://www.torquedev.com/network/snippetter.php")); // Check if we're successful if (client.ResponseHeaders["X-Snippet-Success"] == null || client.ResponseHeaders["X-Snippet-Success"] == "False") { MessageBox.Show(this, "Failed to retrieve snippet. Snippet does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Create the new snippet CSnippetter.CodeEntry entry = new TSDev.CSnippetter.CodeEntry(); // Populate the fields entry.CodeCategory = client.ResponseHeaders["X-Snippet-Category"]; entry.CodeTitle = client.ResponseHeaders["X-Snippet-Title"]; entry.CodeDescr = client.ResponseHeaders["X-Snippet-Description"]; string keywords = client.ResponseHeaders["X-Snippet-Keywords"]; // Process keywords foreach(string keyword in keywords.Trim().Split(' ')) entry.CodeKeywords.Add(keyword); // Write the codeblock entry.CodeContents = code; // Update the URL and date entry.CodeURL = "http://www.torquedev.com/network/snippetter.php?op=showcode&id=" + id; entry.CodeExpires = DateTime.Now.Ticks + (new TimeSpan(30, 0, 0, 0, 0)).Ticks; // Spawn a snippetter edit window to make any changes frmSnippetNew fSnippetNew = new frmSnippetNew(entry, true, false); fSnippetNew.ShowInTaskbar = false; DialogResult result = fSnippetNew.ShowDialog(); // If they cancelled, then don't add this to the collection if (result == DialogResult.Cancel) return; // Add it to the collection frmMain.stc_Snippets.CodeSnippets.Add(entry); // Refresh the list RefreshTree(); }
private void mnuSnippetImport_Click(object sender, System.EventArgs e) { string id = frmMain.ShowPrompt("Import Snippet", "Please enter the ID of the snippet you wish to import.", "Enter snippet ID:"); if (id == "") { return; } // Construct a web server request WebClient client = new WebClient(); // Populate the querystrings client.QueryString.Add("op", "fetch"); client.QueryString.Add("id", id); // Execute the request string code = System.Text.ASCIIEncoding.ASCII.GetString(client.DownloadData("http://www.torquedev.com/network/snippetter.php")); // Check if we're successful if (client.ResponseHeaders["X-Snippet-Success"] == null || client.ResponseHeaders["X-Snippet-Success"] == "False") { MessageBox.Show(this, "Failed to retrieve snippet. Snippet does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Create the new snippet CSnippetter.CodeEntry entry = new TSDev.CSnippetter.CodeEntry(); // Populate the fields entry.CodeCategory = client.ResponseHeaders["X-Snippet-Category"]; entry.CodeTitle = client.ResponseHeaders["X-Snippet-Title"]; entry.CodeDescr = client.ResponseHeaders["X-Snippet-Description"]; string keywords = client.ResponseHeaders["X-Snippet-Keywords"]; // Process keywords foreach (string keyword in keywords.Trim().Split(' ')) { entry.CodeKeywords.Add(keyword); } // Write the codeblock entry.CodeContents = code; // Update the URL and date entry.CodeURL = "http://www.torquedev.com/network/snippetter.php?op=showcode&id=" + id; entry.CodeExpires = DateTime.Now.Ticks + (new TimeSpan(30, 0, 0, 0, 0)).Ticks; // Spawn a snippetter edit window to make any changes frmSnippetNew fSnippetNew = new frmSnippetNew(entry, true, false); fSnippetNew.ShowInTaskbar = false; DialogResult result = fSnippetNew.ShowDialog(); // If they cancelled, then don't add this to the collection if (result == DialogResult.Cancel) { return; } // Add it to the collection frmMain.stc_Snippets.CodeSnippets.Add(entry); // Refresh the list RefreshTree(); }
private void cmdCreate_Click(object sender, System.EventArgs e) { if (this.txtCategory.Text.Trim() == "") { MessageBox.Show(this, "Please enter a category to assign to this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (this.txtTitle.Text.Trim() == "") { MessageBox.Show(this, "Please enter a title to assign to this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else if (this.txtCode.Text.Trim() == "") { MessageBox.Show(this, "Please enter some code for this snippet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Create the snippet object CSnippetter.CodeEntry entry = new TSDev.CSnippetter.CodeEntry(txtTitle.Text, txtDescr.Text, txtCode.Text, txtCategory.Text); // Create the keywords txtKeywords.Text = txtKeywords.Text.Replace(",", ""); foreach(string keyword in txtKeywords.Text.Split(' ')) { entry.CodeKeywords.Add(keyword); } // Insert the snippet into the collection frmMain.stc_Snippets.CodeSnippets.Add(entry); // Refresh the main treeview //g.Main.SnippetterUC.RefreshTree(); // Close this window and dispose it this.DialogResult = DialogResult.OK; this.Close(); this.txtCode.Dispose(); this.Dispose(); }