예제 #1
0
 private bool validateDocument(DocumentTab item)
 {
     try
     {
         if (item.title.Trim() != string.Empty)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #2
0
        private void initTabUIforNewTab()
        {
            try
            {
                DeSelectAllLabels();

                Label label = new Label();
                label.Text      = "Document Title";
                label.TextAlign = ContentAlignment.MiddleCenter;
                label.BackColor = Color.Transparent;
                label.ForeColor = Color.White;
                label.AutoSize  = false;
                label.Width     = 140;
                label.Height    = 35;
                label.Cursor    = Cursors.Arrow;
                label.Image     = Image.FromFile(Application.StartupPath + @"\Images\focused.png");
                label.Tag       = userControlID;
                userControlID++;

                flowLayoutPanel.Controls.Add(label);
                label.RightToLeft = RightToLeft.No;

                DocumentTab dTab = new DocumentTab();
                txtTopic.Text    = txtDocument.Text = string.Empty;
                dTab.content     = txtDocument.Rtf;
                dTab.textContent = txtDocument.Text;
                dTab.title       = txtTopic.Text.Trim();

                hashTableTabCollection.Add(label.Tag, dTab);

                label.ContextMenuStrip = contextMenuTabPage;

                label.Controls.Add(initDeleteButtonForTabHeaders(label));
                label.Click  += new EventHandler(label_Click);
                selectedLabel = label;
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #3
0
        public void autoSaveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                autoSaveTimer.Stop();

                SaveSelectedTabState();

                DocumentTab dTab = (DocumentTab)hashTableTabCollection[selectedLabel.Tag];
                txtDocument.Rtf               = dTab.content;
                txtTopic.Text                 = dTab.title;
                txtDocument.BackColor         = dTab.backgroundColor;
                txtDocument.Font              = dTab.font;
                txtDocument.ForeColor         = dTab.textColor;
                toolStripMenuItemWrap.Checked = dTab.wordWrap;
                txtDocument.ZoomFactor        = dTab.ZoomFactor;
                zoomBar.Value                 = Convert.ToInt32(dTab.ZoomFactor);

                deleteLeftOverTabs();
                SaveSelectedTabState();

                if (DriveSettings.isLocalSaveOn)
                {
                    SaveToLocalDrive();
                }

                if (DriveSettings.isRemoteSaveOn)
                {
                    saveToCloud();
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                autoSaveTimer.Start();
            }
        }
예제 #4
0
        private void saveToCloud()
        {
            this.Cursor = Cursors.WaitCursor;
            this.Text  += " - Uploading to google drive - Please wait...";
            System.Collections.Hashtable localTable = new System.Collections.Hashtable();

            try
            {
                SaveSelectedTabState();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                List <int> listOfKeys = hashTableTabCollection.Keys.Cast <int>().ToList();

                for (int counter = 0; counter < listOfKeys.Count; counter++)
                {
                    int         key   = (int)listOfKeys[counter];
                    DocumentTab value = (DocumentTab)hashTableTabCollection[key];
                    Google.Apis.Drive.v2.Data.File currentJobFile = null;
                    System.IO.MemoryStream         stream;
                    stream = new System.IO.MemoryStream(Encoding.Default.GetBytes(value.content));

                    if (value.currentJobFile != null)
                    {
                        if (value.title.Trim() != string.Empty)
                        {
                            currentJobFile = DriveCommand.updateFile(value.currentJobFile.Id, value.title.Trim(), stream, value.currentJobFile.OriginalFilename, true);
                        }
                        else
                        {
                            currentJobFile = DriveCommand.updateFile(value.currentJobFile.Id, value.currentJobFile.Title, stream, value.currentJobFile.OriginalFilename, true);
                        }
                    }
                    else
                    {
                        if (validateDocument(value))
                        {
                            DriveCommand.createFile(value.title.Trim(), stream, out currentJobFile);

                            localTable.Add(key, currentJobFile);
                        }
                        else
                        {
                            string TopicName = value.textContent.Trim();

                            if (TopicName.Length > 10)
                            {
                                TopicName = TopicName.Substring(0, 10);
                                DriveCommand.createFile(TopicName, stream, out currentJobFile);

                                localTable.Add(key, currentJobFile);
                            }
                            else
                            {
                                MessageBox.Show("Please enter 10 or more characters to save the document when title is not provided.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }

                foreach (int key in localTable.Keys)
                {
                    if (hashTableTabCollection.ContainsKey(key))
                    {
                        DocumentTab dTab = (DocumentTab)hashTableTabCollection[key];
                        dTab.currentJobFile         = (Google.Apis.Drive.v2.Data.File)localTable[key];
                        hashTableTabCollection[key] = dTab;
                    }
                }
            }
            catch (Exception)
            {
            }

            #region Single File Code
            //try
            //{
            //    System.IO.MemoryStream stream;
            //    stream = new System.IO.MemoryStream(Encoding.Default.GetBytes(txtDocument.Rtf));


            //    if (DriveCommand.currentJobFile != null)
            //    {
            //        if (txtTopic.Text.Trim() != string.Empty)
            //            DriveCommand.updateFile(DriveCommand.currentJobFile.Id, txtTopic.Text.Trim(), stream, DriveCommand.currentJobFile.OriginalFilename, true);
            //        else
            //            DriveCommand.updateFile(DriveCommand.currentJobFile.Id, DriveCommand.currentJobFile.Title, stream, DriveCommand.currentJobFile.OriginalFilename, true);
            //    }
            //    else
            //    {
            //        if (validateDocument())
            //            DriveCommand.createFile(txtTopic.Text.Trim(), stream);
            //        else
            //        {
            //            string TopicName = txtDocument.Text.TrimStart();

            //            if (TopicName.Length > 10)
            //            {
            //                TopicName = TopicName.Substring(0, 10);
            //                DriveCommand.createFile(TopicName, stream);
            //            }
            //            else
            //            {
            //                MessageBox.Show("Please enter 10 or more characters to save the document when title is not provided.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //            }
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //}
            #endregion

            this.Text   = this.Text.Replace(" - Uploading to google drive - Please wait...", string.Empty);
            this.Cursor = Cursors.Arrow;
        }
예제 #5
0
        private void closeSelectedTab()
        {
            try
            {
                if (flowLayoutPanel.Controls.Count == 1)
                {
                    txtDocument.Clear();
                    txtTopic.Text                 = string.Empty;
                    txtDocument.BackColor         = Color.White;
                    txtDocument.ForeColor         = Color.Black;
                    toolStripMenuItemWrap.Checked = false;
                    txtDocument.ZoomFactor        = 1;
                    zoomBar.Value                 = Convert.ToInt32(txtDocument.ZoomFactor);

                    DocumentTab dTab_ = (DocumentTab)hashTableTabCollection[Convert.ToInt32(selectedLabel.Tag)];
                    dTab_.textContent     = txtDocument.Text;
                    dTab_.title           = txtTopic.Text;
                    dTab_.content         = txtDocument.Rtf;
                    dTab_.backgroundColor = txtDocument.BackColor;
                    dTab_.textColor       = txtDocument.ForeColor;
                    dTab_.wordWrap        = false;
                    dTab_.ZoomFactor      = txtDocument.ZoomFactor;
                    dTab_.currentJobFile  = null;

                    hashTableTabCollection[Convert.ToInt32(selectedLabel.Tag)] = dTab_;

                    return;
                }

                DeSelectAllLabels();

                int counter;
                int selectedTabIndex = -1;
                for (counter = 0; counter < flowLayoutPanel.Controls.Count; counter++)
                {
                    if (flowLayoutPanel.Controls[counter] == selectedLabel)
                    {
                        hashTableTabCollection.Remove(Convert.ToInt32(selectedLabel.Tag));

                        if (counter < flowLayoutPanel.Controls.Count - 1)
                        {
                            selectedTabIndex = Convert.ToInt32(flowLayoutPanel.Controls[counter + 1].Tag);

                            ((Label)flowLayoutPanel.Controls[counter + 1]).Image = Image.FromFile(Application.StartupPath + @"\Images\focused.png");

                            //flowLayoutPanel.Controls[counter + 1].BackColor = Color.White;
                            //flowLayoutPanel.Controls[counter + 1].ForeColor = Color.DimGray;
                        }
                        else if (counter == flowLayoutPanel.Controls.Count - 1)
                        {
                            selectedTabIndex = Convert.ToInt32(flowLayoutPanel.Controls[counter - 1].Tag);

                            ((Label)flowLayoutPanel.Controls[counter - 1]).Image = Image.FromFile(Application.StartupPath + @"\Images\focused.png");
                            //flowLayoutPanel.Controls[counter - 1].BackColor = Color.White;
                            //flowLayoutPanel.Controls[counter - 1].ForeColor = Color.DimGray;
                        }
                        break;
                    }
                }

                if (selectedTabIndex != -1)
                {
                    DocumentTab dTab = (DocumentTab)hashTableTabCollection[selectedTabIndex];
                    txtDocument.Rtf               = dTab.content;
                    txtTopic.Text                 = dTab.title;
                    txtDocument.BackColor         = dTab.backgroundColor;
                    txtDocument.Font              = dTab.font;
                    txtDocument.ForeColor         = dTab.textColor;
                    toolStripMenuItemWrap.Checked = dTab.wordWrap;
                    txtDocument.ZoomFactor        = dTab.ZoomFactor;
                    zoomBar.Value                 = Convert.ToInt32(dTab.ZoomFactor);

                    flowLayoutPanel.Controls.Remove(selectedLabel);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                deleteLeftOverTabs();
            }
        }