Ejemplo n.º 1
0
        private void SetIndexes()
        {
            for (var i = 0; i < TabControlParent.TabPages.Count; i++)
            {
                foreach (Classes.LogTabPage tabPage in TabControlParent.TabPages)
                {
                    if (i == tabPage.PositionIndex)
                    {
                        Classes.LogTabPage page1 = TabControlParent.TabPages[i] as Classes.LogTabPage;
                        Classes.LogTabPage page2 = tabPage;
                        SwapTabPages(TabControlParent, page1, page2);
                    }
                }

                if ((TabControlParent.TabPages[i] as Classes.LogTabPage).IsFolder)
                {
                    TabControl subTabControl = (TabControlParent.TabPages[i] as Classes.LogTabPage).Controls.Find("SubTabControl", true)[0] as TabControl;
                    for (var k = 0; k < subTabControl.TabPages.Count; k++)
                    {
                        foreach (Classes.LogTabPage tabPage in subTabControl.TabPages)
                        {
                            if (k == tabPage.PositionIndex)
                            {
                                Classes.LogTabPage page1 = subTabControl.TabPages[k] as Classes.LogTabPage;
                                Classes.LogTabPage page2 = tabPage;
                                SwapTabPages(subTabControl, page1, page2);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void TabControl_DragOver(object sender, DragEventArgs e)
        {
            TabControl tabControl = sender as TabControl;

            Classes.LogTabPage hover_Tab = HoverTab(tabControl);
            if (hover_Tab == null)
            {
                e.Effect = DragDropEffects.None;
            }
            else
            {
                if (e.Data.GetDataPresent(typeof(Classes.LogTabPage)))
                {
                    e.Effect = DragDropEffects.Move;
                    Classes.LogTabPage drag_tab = (Classes.LogTabPage)e.Data.GetData(typeof(Classes.LogTabPage));

                    if (hover_Tab == drag_tab)
                    {
                        return;
                    }
                    //TabControl subTabControl = TabControlParent.SelectedTab.Controls.Find("SubTabControl", true)[0] as TabControl;
                    Rectangle TabRect = tabControl.GetTabRect(tabControl.TabPages.IndexOf(hover_Tab));
                    TabRect.Inflate(-3, -3);
                    if (TabRect.Contains(tabControl.PointToClient(new Point(e.X, e.Y))))
                    {
                        SwapTabPages(tabControl, drag_tab, hover_Tab);
                        tabControl.SelectedTab = drag_tab;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void OpenNewFile()
        {
            Classes.LogTabPage SelectedTabPage = GetSelectedTabPage();
            if (SelectedTabPage == null || SelectedTabPage.Name == "")
            {
                openFileDialog.InitialDirectory = @"C:\";
            }
            else
            {
                if (Directory.Exists(Path.GetDirectoryName(Path.GetFullPath(SelectedTabPage.Name))))
                {
                    openFileDialog.InitialDirectory = Path.GetDirectoryName(Path.GetFullPath(SelectedTabPage.Name));
                }
                else
                {
                    openFileDialog.InitialDirectory = @"C:\";
                }
            }

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (TabPage tab in TabControlParent.TabPages)
                {
                    if (openFileDialog.FileName == tab.Name)
                    {
                        TabControlParent.SelectedTab = tab;
                        return;
                    }
                }
                CreateParentTabPageAtIndex(path: openFileDialog.FileName, index: null);
            }
        }
Ejemplo n.º 4
0
        private void SwapTabPages(TabControl tabControl, Classes.LogTabPage tp1, Classes.LogTabPage tp2)
        {
            int Index1 = tabControl.TabPages.IndexOf(tp1);
            int Index2 = tabControl.TabPages.IndexOf(tp2);

            tabControl.TabPages[Index1] = tp2;
            tabControl.TabPages[Index2] = tp1;
            int tp1Temp = tp1.PositionIndex;

            tp1.PositionIndex = tp2.PositionIndex;
            tp2.PositionIndex = tp1Temp;
        }
Ejemplo n.º 5
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveCurrentSession(null);
            if (TabControlParent.TabPages.Count > 0)
            {
                for (var i = 0; i < TabControlParent.TabPages.Count; i++)
                {
                    Classes.LogTabPage logTabPage = TabControlParent.TabPages[i] as Classes.LogTabPage;
                    if (logTabPage.IsFolder)
                    {
                        TabControl subTabControl = (logTabPage.Controls.Find("SubTabControl", true).FirstOrDefault()) as TabControl;
                        for (var ik = 0; ik < subTabControl.TabPages.Count; ik++)
                        {
                            try
                            {
                                (subTabControl.TabPages[ik] as Classes.LogTabPage).Deconstruct();
                            }
                            catch (NullReferenceException err)
                            {
                                Console.WriteLine(err.Message);
                            }
                        }
                    }
                    try
                    {
                        logTabPage.Deconstruct();
                    }
                    catch (NullReferenceException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                }
                TabControlParent.TabPages.Clear();
            }
            DirectoryInfo tempDir = new DirectoryInfo("./Assets/TempFiles/");

            if (tempDir.GetFiles().Any())
            {
                foreach (FileInfo file in tempDir.GetFiles())
                {
                    try
                    {
                        file.Delete();
                    }
                    catch (IOException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void CreateParentTabPageAtIndex(string path, int?index, string parentName = null, string text = null)
        {
            try
            {
                int tabPosition = index ?? CountParentTabs() + 1;
                //Creates a new tab for a new log
                Classes.LogTabPage tab = new Classes.LogTabPage()
                {
                    Text = text ?? Path.GetFileName(path), Name = path, Tag = "File", TailFollowed = true, PositionIndex = tabPosition, ImageIndex = 0
                };

                tab.SetWatcher(path);
                TabControlParent.TabPages.Add(tab);
                TabControlParent.SelectedTab = tab;

                Classes.ListViewNF ListViewText = new Classes.ListViewNF {
                    Parent = tab, Dock = DockStyle.Fill, View = View.Details,
                };

                ListViewText.Columns.Add("Line", 50, HorizontalAlignment.Left);
                ListViewText.Columns.Add("Text", 1000, HorizontalAlignment.Left);
                ListViewText.FullRowSelect    = true;
                ListViewText.ContextMenuStrip = contextMenuStrip1;
                ListViewText.MultiSelect      = true;
                ListViewText.Name             = "ListViewText";//used to find listview later

                //SelectedTabPage = tab;
                TabViewChange(tab);
                tab.InitialLoad();

                FileLengthTB.Text = ListViewText.Items.Count.ToString() + " lines"; //Grabs the Number of lines in a file
                // long FileSizeValue = new FileInfo(path).Length; //Create the long for the file size value
                // FileSizeTB.Text = (FileSizeValue / 1024) + " KB"; //Convert File size from bytes to KB

                if (!String.IsNullOrWhiteSpace(parentName))
                {
                    TabPage    folder            = GetFolderByName(parentName);
                    TabControl subTabPageControl = folder.Controls.Find("SubTabControl", true).FirstOrDefault() as TabControl;
                    subTabPageControl.TabPages.Add(tab);
                }
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
        }
Ejemplo n.º 7
0
        private void SaveCurrentSession(string path)
        {
            XDocument SessionXML = new XDocument(new XElement("Session", new XElement("Files"), new XElement("Folders")));

            for (var i = 0; i < TabControlParent.TabPages.Count; i++)
            {
                Classes.LogTabPage logTabPage = TabControlParent.TabPages[i] as Classes.LogTabPage;
                if (!logTabPage.IsFolder)//File
                {
                    SessionXML.Root.Elements("Files").First().Add(new XElement("File",
                                                                               new XAttribute("Position", i),
                                                                               new XAttribute("Name", logTabPage.Text),
                                                                               new XAttribute("Path", logTabPage.Name),
                                                                               new XAttribute("IsTailFollowed", logTabPage.TailFollowed),
                                                                               new XAttribute("IsFolder", logTabPage.IsFolder)
                                                                               ));
                }
                else //Folder
                {
                    SessionXML.Root.Elements("Folders").First().Add(new XElement("Folder",
                                                                                 new XAttribute("Name", logTabPage.Name.ToString()),
                                                                                 new XAttribute("Position", i),
                                                                                 new XAttribute("IsFolder", logTabPage.IsFolder)
                                                                                 ));
                    TabControl subTabControl = (logTabPage.Controls.Find("SubTabControl", true).FirstOrDefault()) as TabControl;
                    for (var ik = 0; ik < subTabControl.TabPages.Count; ik++)
                    {
                        Classes.LogTabPage subLogTabPage = subTabControl.TabPages[ik] as Classes.LogTabPage;
                        SessionXML.Root.Elements("Folders").First().Elements().Where(f => f.Attribute("Name").Value.ToString() == logTabPage.Name.ToString()).First().Add(new XElement("File",
                                                                                                                                                                                       new XAttribute("Position", ik),
                                                                                                                                                                                       new XAttribute("Name", subLogTabPage.Text.ToString()),
                                                                                                                                                                                       new XAttribute("Path", subLogTabPage.Name.ToString()),
                                                                                                                                                                                       new XAttribute("IsTailFollowed", subLogTabPage.TailFollowed),
                                                                                                                                                                                       new XAttribute("IsFolder", subLogTabPage.IsFolder)
                                                                                                                                                                                       ));
                    }
                }
            }
            if (!Directory.Exists(@"./Assets/Session/"))
            {
                Directory.CreateDirectory(@"./Assets/Session/");
            }
            SessionXML.Save(path ?? "./Assets/Session/Session.xml");
        }
Ejemplo n.º 8
0
 private void TabViewChange(Classes.LogTabPage logTabPage)
 {
     try
     {
         if (logTabPage.TailFollowed)
         {
             followTailCheckBox.Checked = true;
         }
         else
         {
             followTailCheckBox.Checked = false;
             logTabPage.ScrollToIndex();
         }
     }
     catch (NullReferenceException E)
     {
         Console.WriteLine(E.Message);
     }
 }
Ejemplo n.º 9
0
        private void CreateFolder(string name, int?index)
        {
            /************************
            *  Attach subtabcontrol to folder tabs
            ************************/
            ImageList iconList = new ImageList();

            iconList.Images.Add("doc", Image.FromFile(@"./Assets/Icons/document-icon.png"));
            iconList.Images.Add("folder", Image.FromFile(@"./Assets/Icons/folder-icon.png"));
            iconList.Images.Add("x", Image.FromFile(@"./Assets/Icons/x-icon.png"));

            TabControl subTabControl = new Classes.LogTabControl();

            subTabControl.Name                  = "SubTabControl";
            subTabControl.Dock                  = DockStyle.Fill;
            subTabControl.ShowToolTips          = true;
            subTabControl.AllowDrop             = true;
            subTabControl.ImageList             = iconList;
            subTabControl.MouseClick           += new MouseEventHandler(SubTab_Click);
            subTabControl.SelectedIndexChanged += new EventHandler(TabControl_SelectedIndexChanged);
            subTabControl.DragOver             += new DragEventHandler(TabControl_DragOver);
            subTabControl.MouseDown            += new MouseEventHandler(TabControl_MouseDown);
            subTabControl.MouseMove            += new MouseEventHandler(TabControl_MouseMove);


            int tabPosition = index ?? CountParentTabs() + 1;

            Classes.LogTabPage tab = new Classes.LogTabPage()
            {
                Text = name, Name = name, Tag = "Folder", PositionIndex = tabPosition, IsFolder = true, ImageIndex = 1
            };
            tab.Controls.Add(subTabControl);
            TabControlParent.TabPages.Add(tab);
            TabControlParent.SelectedTab = tab;
            //SelectedTabPage = tab;
            TabViewChange(tab);
        }
Ejemplo n.º 10
0
        /******************************
        * Section that allows for Tab renaming
        ******************************/
        private void renameTabToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RenameForm rename = new RenameForm();

            rename.ShowDialog(this);
            Classes.LogTabPage SelectedFolder  = GetSelectedFolder();
            Classes.LogTabPage SelectedTabPage = GetSelectedTabPage();

            if (SelectedFolder != null)
            {
                if (TabControlParent.GetTabRect(TabControlParent.SelectedIndex).Contains(lastClickedPoint))
                {
                    SelectedTabPage = SelectedFolder;
                }
            }
            if (rename.DialogResult == DialogResult.OK)
            {
                if (SelectedTabPage.Tag.ToString() == "Folder" && !CheckForExistingTabName(rename.RenameTextBox.Text))
                {
                    SelectedTabPage.Name = rename.RenameTextBox.Text;
                }
                else if (SelectedTabPage.Tag.ToString() == "Folder" && CheckForExistingTabName(rename.RenameTextBox.Text))
                {
                    MessageBox.Show("Folder Name Already Exists.");
                    rename.Hide();
                    return;
                }

                SelectedTabPage.Text = rename.RenameTextBox.Text;
                SelectedTabPage.Update();
            }
            else
            {
                rename.Hide();
            }
        }
Ejemplo n.º 11
0
        /*************************
         * Handles the Tab menu item selections
         ***************************/
        private void TabContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            Classes.LogTabPage SelectedFolder  = GetSelectedFolder();
            Classes.LogTabPage SelectedTabPage = GetSelectedTabPage();

            if (SelectedFolder != null)
            {
                if (TabControlParent.GetTabRect(TabControlParent.SelectedIndex).Contains(lastClickedPoint))
                {
                    SelectedTabPage = SelectedFolder;
                }
            }

            ToolStripItem clickedItem = e.ClickedItem;

            if (e.ClickedItem.Name == "TabToolStripMenuItem")
            {
                RenameForm rename = new RenameForm();
                rename.ShowDialog(this);

                if (rename.DialogResult == DialogResult.OK)
                {
                    SelectedTabPage.Text = rename.RenameTextBox.Text;
                    SelectedTabPage.Update();
                }
                else
                {
                    rename.Hide();
                }
            }
            else if (e.ClickedItem.Name == "moveToFolderToolStripMenuItem")
            {
                MoveToFolderForm MoveToForm = new MoveToFolderForm();

                string parentFolderName = SelectedTabPage.Parent.Name;
                for (int ix = 0; ix < TabControlParent.TabCount; ++ix)
                {
                    if (TabControlParent.TabPages[ix].Tag.ToString() == "Folder")
                    {
                        MoveToForm.FolderListBox.Items.Add(Text = TabControlParent.TabPages[ix].Text);
                    }
                }
                MoveToForm.ShowDialog(this);
                if (MoveToForm.DialogResult == DialogResult.OK)
                {
                    try
                    {
                        string selection = MoveToForm.FolderListBox.SelectedItem.ToString();
                        if (selection.ToString() == "No Folder")
                        {
                            TabControlParent.TabPages.Add(SelectedTabPage);
                        }
                        TabPage    folder            = GetFolderByName(selection);
                        TabControl subTabPageControl = folder.Controls.Find("SubTabControl", true).FirstOrDefault() as TabControl;
                        subTabPageControl.TabPages.Add(SelectedTabPage);
                    }
                    catch (NullReferenceException) { } //No folder selected do nothing
                }
            }
            else if (e.ClickedItem.Name == "deleteToolStripMenuItem")
            {
                /*if (SelectedTabPage.IsFolder)
                 * {
                 *
                 *  TabControl subTabPageControl = SelectedTabPage.Controls.Find("SubTabControl", true).FirstOrDefault() as TabControl;
                 *
                 * }*/
                Console.WriteLine(SelectedTabPage.Name);
                TabControl tabControl = SelectedTabPage.Parent as TabControl;
                tabControl.TabPages.Remove(SelectedTabPage);
            }
        }
Ejemplo n.º 12
0
        private void LoadSession(string path)
        {
            if (TabControlParent.TabPages.Count > 0)
            {
                for (var i = 0; i < TabControlParent.TabPages.Count; i++)
                {
                    Classes.LogTabPage logTabPage = TabControlParent.TabPages[i] as Classes.LogTabPage;
                    if (logTabPage.IsFolder)
                    {
                        TabControl subTabControl = (logTabPage.Controls.Find("SubTabControl", true).FirstOrDefault()) as TabControl;
                        for (var ik = 0; ik < subTabControl.TabPages.Count; ik++)
                        {
                            try
                            {
                                (subTabControl.TabPages[ik] as Classes.LogTabPage).Deconstruct();
                            }
                            catch (NullReferenceException err)
                            {
                                Console.WriteLine(err.Message);
                            }
                        }
                    }
                    try
                    {
                        logTabPage.Deconstruct();
                    }
                    catch (NullReferenceException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                }
                TabControlParent.TabPages.Clear();
            }
            try
            {
                XDocument LastSession = XDocument.Load(path ?? @"./Assets/Session/Session.xml");
                XElement  files       = LastSession.Root.Elements("Files").First();
                for (var i = 0; i < files.Elements().Count(); i++)
                {
                    XElement element = files.Elements().ToList()[i];
                    int      index   = -1;
                    Int32.TryParse(element.Attribute("Position").Value, out index);
                    CreateParentTabPageAtIndex(element.Attribute("Path").Value, index, text: element.Attribute("Name").Value);
                }

                XElement folders = LastSession.Root.Elements("Folders").First();
                for (var f = 0; f < folders.Elements().Count(); f++)
                {
                    XElement element = folders.Elements().ToList()[f];
                    int      index   = -1;
                    Int32.TryParse(element.Attribute("Position").Value, out index);
                    CreateFolder(element.Attribute("Name").Value, index);

                    for (var fi = 0; fi < folders.Elements().ToList()[f].Elements().Count(); fi++)
                    {
                        int subIndex = -1;
                        Int32.TryParse(folders.Elements().ToList()[f].Elements().ToList()[fi].Attribute("Position").Value, out subIndex);
                        CreateParentTabPageAtIndex(folders.Elements().ToList()[f].Elements().ToList()[fi].Attribute("Path").Value, subIndex, parentName: element.Attribute("Name").Value, text: folders.Elements().ToList()[f].Elements().ToList()[fi].Attribute("Name").Value);
                    }
                }
                SetIndexes();
            }
            catch (IOException err)
            {
                MessageBox.Show(err.Message);
                return;
            }
        }
Ejemplo n.º 13
0
 private void SetTitle(Classes.LogTabPage tab)
 {
     this.Text = "Hail Tail - " + tab.Name;
 }