Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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";
            }
        }
Esempio n. 3
0
        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";
            }
        }
Esempio n. 4
0
        private void tvSnippets_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            if (this.tvSnippets.SelectedNode == null)
            {
                return;
            }

            TreeNode node = this.tvSnippets.SelectedNode;

            if (node.Tag == null)
            {
                this.lblDescr.Text = "Category <b>" + node.Text + "</b>";
            }
            else if (node.Tag is CSnippetter.CodeEntry)
            {
                CSnippetter.CodeEntry entry = (CSnippetter.CodeEntry)node.Tag;
                this.lblDescr.Text = "Snippet <b>" + entry.CodeTitle + "</b><br />" + entry.CodeDescr;
            }
        }