Ejemplo n.º 1
0
        public NuntiasOptionsPanel(long nuntiasId)
        {
            this.nuntiasId = nuntiasId;
            Nuntias nuntias = SyncAssets.NuntiasSortedList[this.nuntiasId];

            this.parentNuntiasLabel = SyncAssets.ShowedNuntiasLabelSortedList[nuntias.Id];
            this.BackColor          = Color.FromArgb(51, 51, 51);
            this.ForeColor          = Color.FromArgb(220, 220, 220);
            if (nuntias.SenderId == Consumer.LoggedIn.Id)
            {
                this.Name = "own";
            }
            else
            {
                this.Name = "other";
            }

            copyNuntiasTextLabel = new Label();
            deleteNuntiasLabel   = new Label();

            this.Controls.Add(copyNuntiasTextLabel);
            this.Controls.Add(deleteNuntiasLabel);

            copyNuntiasTextLabel.Text        = "";
            copyNuntiasTextLabel.Image       = copyIcon;
            copyNuntiasTextLabel.ImageAlign  = ContentAlignment.MiddleLeft;
            copyNuntiasTextLabel.TextAlign   = ContentAlignment.MiddleRight;
            copyNuntiasTextLabel.Font        = CustomFonts.Smallest;
            copyNuntiasTextLabel.Size        = labelSize;
            copyNuntiasTextLabel.MouseEnter += (s, e) => { copyNuntiasTextLabel.BackColor = Color.FromArgb(128, 128, 128); };
            copyNuntiasTextLabel.MouseLeave += (s, e) => { copyNuntiasTextLabel.BackColor = Color.Transparent; };
            copyNuntiasTextLabel.Click      += (s, e) =>
            {
                if (nuntias.ContentFileId == null || nuntias.ContentFileId.Length == 0)
                {
                    Clipboard.SetText(nuntias.Text);
                }
                else if (nuntias.Text.Length >= 5 && nuntias.Text.Substring(0, 5) == "Image")
                {
                    Clipboard.SetImage(Image.FromFile(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId)));
                }
                else if (nuntias.Text.Length >= 4 && nuntias.Text.Substring(0, 4) == "File")
                {
                    StringCollection paths = new StringCollection();
                    paths.Add(LocalDataFileAccess.GetContentPathFromLocalData(nuntias.ContentFileId));
                    Clipboard.SetFileDropList(paths);
                }
                this.ChangeNuntiasOptionPanelState();
            };
            copyNuntiasTextLabel.Visible = false;

            deleteNuntiasLabel.Text        = "";
            deleteNuntiasLabel.Image       = deleteIcon;
            deleteNuntiasLabel.ImageAlign  = ContentAlignment.MiddleLeft;
            deleteNuntiasLabel.TextAlign   = ContentAlignment.MiddleRight;
            deleteNuntiasLabel.Font        = CustomFonts.Smallest;
            deleteNuntiasLabel.Size        = labelSize;
            deleteNuntiasLabel.MouseEnter += (s, e) => { deleteNuntiasLabel.BackColor = Color.FromArgb(128, 128, 128); };
            deleteNuntiasLabel.MouseLeave += (s, e) => { deleteNuntiasLabel.BackColor = Color.Transparent; };
            deleteNuntiasLabel.Click      += (s, e) =>
            {
                if (nuntias.SenderId == Consumer.LoggedIn.Id && Time.TimeDistanceInSecond(Time.CurrentTime, nuntias.SentTime) <= 300)
                {
                    //server allows deletion of a message that was sent 5 minutes ago or later.
                    DialogResult result = MessageBox.Show("Delete the message from both side?\r\nClick Yes. Else click No.", "Message Deletion", MessageBoxButtons.YesNoCancel);
                    if (result == DialogResult.Yes || result == DialogResult.No)
                    {
                        BackgroundWorker bworker = new BackgroundWorker();
                        bworker.DoWork += (ss, ee) =>
                        {
                            bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, result == DialogResult.Yes);
                            if (success && result == DialogResult.No)
                            {
                                SyncAssets.DeleteNuntiasAssets(this.NuntiasId);
                            }
                        };
                        bworker.RunWorkerAsync();
                        bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); };
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    DialogResult result = MessageBox.Show("Delete the message for you?", "Message Deletion", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        BackgroundWorker bworker = new BackgroundWorker();
                        bworker.DoWork += (ss, ee) =>
                        {
                            bool success = ServerRequest.DeleteNuntias(Consumer.LoggedIn.Id, this.NuntiasId, false);
                            if (success)
                            {
                                SyncAssets.DeleteNuntiasAssets(this.NuntiasId);
                            }
                        };
                        bworker.RunWorkerAsync();
                        bworker.RunWorkerCompleted += (ss, ee) => { bworker.Dispose(); };
                    }
                    else
                    {
                        return;
                    }
                }
                this.ChangeNuntiasOptionPanelState();
            };
            deleteNuntiasLabel.Visible = false;

            this.UpdateOptionPanel();
        }