Ejemplo n.º 1
0
        internal static void OpenNoteOnEditor(Form1 form)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;
            TreeView       notesTreeView   = form.notePanel.notesTreeView;

            TreeNode selectedNode = notesTreeView.SelectedNode;
            String   content;

            try
            {
                content = GetNoteText(form, selectedNode.Text);
            }
            catch (XmlException exception)
            {
                ManageError(form, exception);
                return;
            }

            if (TabManager.IsCurrentTabInUse(form))
            {
                form.TabIdentity = TabManager.AddNewPage(form, form.TabIdentity);
            }

            //Row number check
            WindowManager.CheckLineNumbersForTextLenght(form, content);

            ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text = content;
        }
Ejemplo n.º 2
0
        internal static void ExportNotes(Form1 form, ExportTypeEnum exportType)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            String content;

            switch (exportType)
            {
            case ExportTypeEnum.Xml:
                if (TabManager.IsCurrentTabInUse(form))
                {
                    form.TabIdentity = TabManager.AddNewPage(form, form.TabIdentity);
                    pageTextBox      = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
                }

                content = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile));

                //Row number check
                WindowManager.CheckLineNumbersForTextLenght(form, content);

                pageTextBox.SelectedText = content;

                TextManager.RefreshUndoRedoExternal(form);
                break;

            case ExportTypeEnum.Txt:
                try
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.noFile));

                    XmlNodeList noteNodeList = xmldoc.GetElementsByTagName("note");

                    foreach (XmlNode noteNode in noteNodeList)
                    {
                        if (TabManager.IsCurrentTabInUse(form))
                        {
                            form.TabIdentity = TabManager.AddNewPage(form, form.TabIdentity);
                            pageTextBox      = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
                        }

                        content = noteNode.ChildNodes[0].InnerText + ConstantUtil.newLine + ConstantUtil.newLine + noteNode.ChildNodes[1].InnerText;

                        //Row number check
                        WindowManager.CheckLineNumbersForTextLenght(form, content);

                        pageTextBox.SelectedText = content;

                        TextManager.RefreshUndoRedoExternal(form);
                    }
                }
                catch (XmlException exception)
                {
                    ManageError(form, exception);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        internal static bool OpenUrlSource(Form1 form, String url)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            if (!url.StartsWith("http://"))
            {
                url = "http://" + url;
            }

            WebClient webClient = null;
            String    urlSource;

            try
            {
                webClient          = ProxyUtil.InitWebClientProxy();
                webClient.Encoding = EncodingUtil.GetDefaultEncoding();
                urlSource          = webClient.DownloadString(url);
            }
            catch (WebException)
            {
                WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorDownloading", className));
                return(false);
            }
            finally
            {
                if (webClient != null)
                {
                    webClient.Dispose();
                }
            }

            if (String.IsNullOrEmpty(urlSource))
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("EmptySource", className));
                return(false);
            }

            if (TabManager.IsCurrentTabInUse(form))
            {
                form.TabIdentity = TabManager.AddNewPage(form, form.TabIdentity);
                pageTextBox      = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            }

            //Row number check
            WindowManager.CheckLineNumbersForTextLenght_External(form, urlSource);

            pageTextBox.SelectedText = urlSource;
            TextManager.RefreshUndoRedoExternal(form);

            return(true);
        }
Ejemplo n.º 4
0
        internal static void GetTemplate(Form1 form, String template)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            template = ElaborateTextToRichTextBox(template);

            if (!TabManager.IsCurrentTabInUse(form))
            {
                pageTextBox.SelectedText = template;
                TextManager.RefreshUndoRedoExternal(form);
                return;
            }

            form.TabIdentity         = TabManager.AddNewPage(form, form.TabIdentity);
            pageTextBox              = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            pageTextBox.SelectedText = template;
            TextManager.RefreshUndoRedoExternal(form);
        }
Ejemplo n.º 5
0
        internal static void ExportList(Form1 form, SearchInFilesPanel panel)
        {
            ListBox           searchInFilesListBox = panel.searchInFilesListBox;
            XtraTabControl    pagesTabControl      = form.pagesTabControl;
            CustomRichTextBox pageTextBox          = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            //String result = String.Empty;
            //foreach (object item in searchInFilesListBox.Items)
            //{
            //    result += GetFileCompletePathName(panel, item.ToString()) + ConstantUtil.newLine;
            //}
            String result = searchInFilesListBox.Items.Cast <object>().Aggregate(String.Empty, (current, item) => current + (GetFileCompletePathName(panel, item.ToString()) + ConstantUtil.newLine));

            if (TabManager.IsCurrentTabInUse(form))
            {
                form.TabIdentity = TabManager.AddNewPage(form, form.TabIdentity);
                pageTextBox      = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            }

            pageTextBox.SelectedText = result;
        }
Ejemplo n.º 6
0
        internal static void ListFolderContentIntoFile(Form1 form, TreeNode parentNode, bool withSizes, String filePattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            ToolStripButton   hiddenToolStripButton = form.filePanel.hiddenToolStripButton;
            XtraTabControl    pagesTabControl       = form.pagesTabControl;
            CustomRichTextBox pageTextBox           = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            long totalSize = 0;

            //bool warningShown = false;

            try
            {
                //Root directory
                DirectoryInfo rootDir;
                Char[]        arr      = { '\\' };
                String[]      nameList = parentNode.FullPath.Split(arr);

                if (nameList.GetValue(0).ToString() == "Desktop")
                {
                    String path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";

                    for (int i = 1; i < nameList.Length; i++)
                    {
                        path = path + nameList[i] + "\\";
                    }

                    rootDir = new DirectoryInfo(path);
                }
                else
                {
                    rootDir = new DirectoryInfo(parentNode.FullPath + "\\");
                }

                String fileList = LanguageUtil.GetCurrentLanguageString("ListDirectoryHeader", className) + " " + rootDir.FullName + ConstantUtil.newLine + ConstantUtil.newLine;

                //Child directories
                DirectoryInfo[] directories = rootDir.GetDirectories(filePattern, searchOption);
                Array.Sort(directories, new Comparison <DirectoryInfo>((d1, d2) => String.Compare(d1.Name, d2.Name))); //return string.Compare(d1.Name, d2.Name);
                foreach (DirectoryInfo directory in directories)
                {
                    if (!hiddenToolStripButton.Checked && directory.Attributes.ToString().Contains("Hidden"))
                    {
                        continue;
                    }

                    //String size = String.Empty;
                    //if (withSizes)
                    //{
                    //    if (!warningShown && WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SureToWait", className)) == DialogResult.No)
                    //    {
                    //        return;
                    //    }

                    //    warningShown = true;
                    //    int filesCount = 0;
                    //    int dirsCount = 0;
                    //    try
                    //    {
                    //        long sizeLong = DirectoryUtil.GetSize(directory, filesCount, dirsCount, out filesCount, out dirsCount);
                    //        totalSize += sizeLong;
                    //        double sizeDouble = (sizeLong / 1024f) / 1024f;

                    //        size = " - " + Math.Round(sizeDouble, 2).ToString(LanguageUtil.GetInfoCulture())
                    //            + " MB, " + filesCount + " " + LanguageUtil.GetCurrentLanguageString("Files", className) + ", " + dirsCount + " " + LanguageUtil.GetCurrentLanguageString("Directories", className);
                    //    }
                    //    catch (UnauthorizedAccessException)
                    //    {
                    //        size = " - " + String.Format(LanguageUtil.GetCurrentLanguageString("AccessDenied", className), directory.FullName);
                    //    }
                    //}

                    fileList += "[dir] " + directory.Name + "\\" + ConstantUtil.newLine; //"[dir] " + directory.Name + "\\" + size + ConstantUtil.newLine
                }

                fileList += ConstantUtil.newLine;

                //Child files
                FileInfo[] files = rootDir.GetFiles(filePattern, searchOption);
                Array.Sort(files, new Comparison <FileInfo>((f1, f2) => String.Compare(f1.Name, f2.Name)));
                foreach (FileInfo file in files)
                {
                    if (!hiddenToolStripButton.Checked && file.Attributes.ToString().Contains("Hidden") || IsFileBlackListed(file.Name))
                    {
                        continue;
                    }

                    String size = String.Empty;
                    if (withSizes)
                    {
                        totalSize += file.Length;
                        double sizeDouble = (file.Length / 1024f) / 1024f;
                        size = " - " + Math.Round(sizeDouble, 2).ToString(LanguageUtil.GetInfoCulture()) + " MB";
                    }

                    switch (searchOption)
                    {
                    case SearchOption.TopDirectoryOnly:
                        fileList = fileList + file.Name + size + ConstantUtil.newLine;
                        break;

                    default:
                        fileList = fileList + file.FullName.Substring(rootDir.FullName.Length) + size + ConstantUtil.newLine;
                        break;
                    }
                }

                if (withSizes)
                {
                    double totalSizeDouble = (totalSize / 1024f) / 1024f;
                    fileList = fileList + ConstantUtil.newLine + LanguageUtil.GetCurrentLanguageString("TotalSize", className) + " " + Math.Round(totalSizeDouble, 2).ToString(LanguageUtil.GetInfoCulture()) + " MB" + ConstantUtil.newLine;
                }

                //Row number check
                WindowManager.CheckLineNumbersForTextLenght(form, String.Format("{0}{1}", pageTextBox.Text, fileList));

                if (!TabManager.IsCurrentTabInUse(form))
                {
                    pageTextBox.SelectedText = fileList;
                    TextManager.RefreshUndoRedoExternal(form);
                }
                else
                {
                    form.TabIdentity         = TabManager.AddNewPage(form, form.TabIdentity);
                    pageTextBox              = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
                    pageTextBox.SelectedText = fileList;
                    TextManager.RefreshUndoRedoExternal(form);
                }
            }
            catch (UnauthorizedAccessException exception)
            {
                WindowManager.ShowErrorBox(form, String.Format("{0}{1}{2}", LanguageUtil.GetCurrentLanguageString("ErrorLoadingDirFiles", className), Environment.NewLine, exception.Message), exception);
            }
            catch (Exception exception)
            {
                if (parentNode == null)
                {
                    WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorLoadingDirFiles", className), exception);
                    return;
                }

                if (parentNode.Tag != null && (parentNode.Tag.ToString() == "CDRom" || parentNode.Tag.ToString() == "Removable"))
                {
                    if (parentNode.Nodes.Count == 0)
                    {
                        parentNode.Nodes.Add(null, LanguageUtil.GetCurrentLanguageString("NoDisk", className), 7, 7);
                    }

                    WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("DeviceNotReady", className));
                }
                else
                {
                    WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorLoadingDirFiles", className), exception);
                }
            }
        }