private void mnuSnippetCopy_Click(object sender, System.EventArgs e) { if (this.tvSnippets.SelectedNode == null) { return; } if (this.tvSnippets.SelectedNode.Tag == null) { return; } // Grab the instance of the snippet we want CSnippetter.CodeEntry code = (CSnippetter.CodeEntry) this.tvSnippets.SelectedNode.Tag; // Do we need to fetch it? if (!(code.CodeURL == "" || DateTime.Now.Ticks >= code.CodeExpires)) { // No. Paste the current URL onto the clipboard Clipboard.SetDataObject(code.CodeURL, true); return; } // Construct a new web request to fetch (and post) the code WebClient client = new WebClient(); System.Collections.Specialized.NameValueCollection postdata = new System.Collections.Specialized.NameValueCollection(); // Write the querystring client.QueryString.Add("op", "upload_snippet"); postdata.Add("code", code.CodeContents); postdata.Add("name", code.CodeTitle); postdata.Add("descr", code.CodeDescr); postdata.Add("category", code.CodeCategory); postdata.Add("keywords", CSnippetter.ParseKeywords(code.CodeKeywords)); // Send the request to the server string url = ""; try { url = System.Text.ASCIIEncoding.ASCII.GetString(client.UploadValues("http://www.torquedev.com/network/snippetter.php", "POST", postdata)); } catch { MessageBox.Show(this, "Failed to connect to Snippetter server. You must be connected to the internet to perform this action. Please check your connection and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (url == "") { MessageBox.Show(this, "Failed to retrieve URL. Upload failed for some reason.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Copy the URL to the object and set the expiration code.CodeURL = url; code.CodeExpires = DateTime.Now.Ticks + (new TimeSpan(30, 0, 0, 0, 0)).Ticks; // Copy the URL to the clipboard Clipboard.SetDataObject(url, true); }
public static void Save(CSnippetter snippet, string filename) { XmlSerializer xml = new XmlSerializer(typeof(CSnippetter)); FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None); xml.Serialize(file, snippet); file.Close(); }
public frmSnippetNew(CSnippetter.CodeEntry ExistingEntry, bool imported, bool viewonly) { // Constructor for editing existing snippets InitializeComponent(); this.isEditing = true; this.code_e = ExistingEntry; this.cmdCreate.Text = "Edit"; // Bind the event handler for the edit event this.cmdCreate.Click += new EventHandler(cmdEdit_Click); // Turn the keywords into a readable listing string keywords = ""; foreach(string keyword in ExistingEntry.CodeKeywords) keywords += keyword + " "; // Populate the fields this.txtCategory.Text = ExistingEntry.CodeCategory; this.txtCode.Document.Text = ExistingEntry.CodeContents; this.txtDescr.Text = ExistingEntry.CodeDescr; this.txtKeywords.Text = keywords.Trim(); this.txtTitle.Text = ExistingEntry.CodeTitle; // Check if we're only viewing if (viewonly) { this.txtCategory.ReadOnly = true; this.txtCode.Document.ReadOnly = true; this.txtDescr.ReadOnly = true; this.txtKeywords.ReadOnly = true; this.txtTitle.ReadOnly = true; this.cmdCreate.Visible = false; this.cmdCancel.Text = "Close"; this.Text = "Snippet Imported"; } else { this.Text = "Edit Snippet"; } if (imported) { this.Text = "Import Snippet"; this.cmdCreate.Text = "Import"; } }
public static CSnippetter Load(string filename) { if (!File.Exists(filename)) return new CSnippetter(); XmlSerializer xml = new XmlSerializer(typeof(CSnippetter)); FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None); CSnippetter newsnip = null; try { newsnip = (CSnippetter)xml.Deserialize(file); } catch { newsnip = new CSnippetter(); } file.Close(); return newsnip; }
public static CSnippetter Load(string filename) { if (!File.Exists(filename)) { return(new CSnippetter()); } XmlSerializer xml = new XmlSerializer(typeof(CSnippetter)); FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None); CSnippetter newsnip = null; try { newsnip = (CSnippetter)xml.Deserialize(file); } catch { newsnip = new CSnippetter(); } file.Close(); return(newsnip); }
public void RefreshTree(CSnippetter.CodeEntryCollection codecoll) { // Clear the nodes and set the update flag so we don't redraw the control all the time. this.tvSnippets.Nodes.Clear(); this.tvSnippets.BeginUpdate(); // Loop through all the code snippets and gather a list of categories ArrayList cats = new ArrayList(); foreach(CSnippetter.CodeEntry entry in codecoll) { if (!cats.Contains(entry.CodeCategory)) cats.Add(entry.CodeCategory); } // Add the categories to the snippetter foreach(string entry in cats) { TreeNode node = new TreeNode(entry, 0, 0); this.tvSnippets.Nodes.Add(node); } // Run a second pass on all the code snippets and add them to the select // categories foreach(CSnippetter.CodeEntry entry in codecoll) { TreeNode parent = GetCategory(entry.CodeCategory); if (parent == null) // This should never happen continue; TreeNode node = new TreeNode(entry.CodeTitle, 6, 6); node.Tag = entry; parent.Nodes.Add(node); } // Allow updates to the treeview and expand all nodes this.tvSnippets.ExpandAll(); this.tvSnippets.EndUpdate(); // Sort the TV this.tvSnippets.Sorted = true; }