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; }
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; } }
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); }
internal static bool OpenFileFromDropbox(Form1 form1, Form form, String fileName, String directoryName) { XtraTabControl pagesTabControl = form1.pagesTabControl; ToolStripStatusLabel toolStripStatusLabel = form1.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form1.toolStripProgressBar; try { Application.DoEvents(); toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = true; toolStripProgressBar.PerformStep(); bool fileExists; String content = DropboxManager.GetFileFromDropbox(DropboxManager.GetDirectory(form1, directoryName), fileName, out fileExists); toolStripProgressBar.PerformStep(); if (!fileExists) { WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("openingFileNotExists", className), fileName, directoryName)); return(false); } if (String.IsNullOrEmpty(content)) { WindowManager.ShowInfoBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("openingFileEmpty", className), fileName)); return(false); } toolStripProgressBar.PerformStep(); form1.LastDropboxFolder = directoryName; if (!String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text)) { form1.TabIdentity = TabManager.AddNewPage(form1, form1.TabIdentity); } ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text = content; toolStripStatusLabel.Text = String.Format("{0} \"{1}\" {2}", LanguageUtil.GetCurrentLanguageString("File", className), fileName, LanguageUtil.GetCurrentLanguageString("OpenedFromDropbox", className)); toolStripProgressBar.PerformStep(); } catch (Exception exception) { WindowManager.ShowErrorBox(form, exception.Message, exception); return(false); } finally { toolStripProgressBar.Visible = false; } return(true); }
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); }
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; }
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); } } }
internal static int OpenFile(Form1 form, int tabIdentity, String[] specificFileNames, bool showMessages, bool saveNewRecentFile, out List <String> errors) { CustomXtraTabControl pagesTabControl = form.pagesTabControl; ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar; OpenFileDialog openFileDialog = form.openFileDialog; bool isWindowsHostsFile = false; int localTabIdentity = tabIdentity; errors = new List <String>(); openFileDialog.InitialDirectory = FileUtil.GetInitialFolder(form); openFileDialog.Multiselect = true; SetFileDialogFilter(openFileDialog); TrayManager.RestoreFormIfIsInTray(form); try { String[] fileNames; if (specificFileNames == null || specificFileNames.Length <= 0) { if (openFileDialog.ShowDialog() != DialogResult.OK) { return(tabIdentity); } fileNames = openFileDialog.FileNames; } else { fileNames = specificFileNames; } //Verify if file is a DtPad session if (fileNames.Length == 1 && fileNames[0].EndsWith(".dps")) { SessionManager.OpenSession(form, fileNames[0]); return(form.TabIdentity); } Application.DoEvents(); toolStripProgressBar.Value = 0; foreach (String fileName in fileNames) { //Verify if file is Windows hosts file if (fileName.Contains(@"drivers\etc\hosts")) { if (!SystemUtil.IsUserAdministrator()) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("UserNotAdmin", className)); } isWindowsHostsFile = true; } if (!showMessages) { if (!File.Exists(fileName)) { errors.Add(String.Format(LanguageUtil.GetCurrentLanguageString("NoMessageFileNotExists", className), fileName)); continue; } if (FileUtil.IsFileInUse(fileName)) { errors.Add(String.Format(LanguageUtil.GetCurrentLanguageString("NoMessageFileInUse", className), fileName)); continue; } if (FileUtil.IsFileTooLargeForDtPad(fileName)) { errors.Add(String.Format(LanguageUtil.GetCurrentLanguageString("NoMessageFileTooHeavy", className), fileName)); continue; } } else if (!File.Exists(fileName)) { WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("FileNotExisting", className), fileName)); continue; } else if (FileUtil.IsFileInUse(fileName)) { WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("FileInUse", className), fileName)); continue; } if (FileUtil.IsFileTooLargeForDtPad(fileName)) { WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("FileTooHeavy", className), fileName)); continue; } //Cycle and check if the file is already open, in which case I select its tab and continue with the next one XtraTabPage tabPage; if (FileUtil.IsFileAlreadyOpen(form, fileName, out tabPage)) { pagesTabControl.SelectedTabPage = tabPage; toolStripProgressBar.PerformStep(); toolStripProgressBar.PerformStep(); toolStripProgressBar.PerformStep(); toolStripProgressBar.PerformStep(); toolStripProgressBar.Visible = false; continue; } //Verify if file is an archive try { ZipFile file = null; bool isZipFile; try { file = new ZipFile(fileName); isZipFile = file.TestArchive(false, TestStrategy.FindFirstError, form.Zip_Errors); } finally { if (file != null) { file.Close(); } } if (isZipFile) { WindowManager.ShowZipExtract(form, fileName); continue; } } catch (ZipException) { } toolStripProgressBar.Visible = true; toolStripProgressBar.PerformStep(); String fileContents; Encoding fileEncoding; bool anonymousFile = false; //Verify if file is a PDF if (fileName.EndsWith(".pdf")) { bool success; fileContents = PdfUtil.ExtractText(fileName, out success); if (!success) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("InvalidPdf", className)); return(tabIdentity); } fileEncoding = EncodingUtil.GetDefaultEncoding(); anonymousFile = true; } else { fileContents = FileUtil.ReadToEndWithEncoding(fileName, out fileEncoding); } bool favouriteFile = FavouriteManager.IsFileFavourite(fileName); if (!favouriteFile && saveNewRecentFile) { ConfigUtil.UpdateParameter("LastUserFolder", Path.GetDirectoryName(fileName)); FileListManager.SetNewRecentFile(form, fileName); } toolStripProgressBar.PerformStep(); CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); if (!String.IsNullOrEmpty(pageTextBox.Text) || !String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage))) { localTabIdentity = TabManager.AddNewPage(form, localTabIdentity); } toolStripProgressBar.PerformStep(); //Row number check WindowManager.CheckLineNumbersForTextLenght(form, fileContents); FileInfo fileInfo = new FileInfo(fileName); pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); //Verify if file is a tweet file if (fileName.EndsWith(".tweet") && !ColumnRulerManager.IsPanelOpen(form)) { ColumnRulerManager.TogglePanel(form); } pageTextBox.Text = fileContents.Replace(Environment.NewLine, ConstantUtil.newLine); pageTextBox.CustomOriginal = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text.GetHashCode().ToString(); pageTextBox.CustomEncoding = fileEncoding.CodePage.ToString(); if (!anonymousFile) { String fileNameWithoutPath = Path.GetFileName(fileName); pageTextBox.CustomModified = false; ProgramUtil.SetFilenameTabPage(pagesTabControl.SelectedTabPage, fileName); pagesTabControl.SelectedTabPage.ImageIndex = fileInfo.IsReadOnly ? 2 : 0; pagesTabControl.SelectedTabPage.Text = fileNameWithoutPath; pagesTabControl.SelectedTabPage.Tooltip = fileName; pagesTabControl.SelectedTabPage.TooltipTitle = fileNameWithoutPath; form.Text = String.Format("DtPad - {0}", fileNameWithoutPath); TabManager.ToggleTabFileTools(form, true); } else { pageTextBox.CustomModified = true; } toolStripStatusLabel.Text = String.Format("{0} \"{1}\" {2}", LanguageUtil.GetCurrentLanguageString("File", className), Path.GetFileName(fileName), LanguageUtil.GetCurrentLanguageString("Opened", className)); toolStripProgressBar.PerformStep(); tabIdentity = localTabIdentity; if (!String.IsNullOrEmpty(fileInfo.Extension) && ConfigUtil.GetStringParameter("AutoFormatFiles").Contains(fileInfo.Extension)) { FormatManager.FormatXml(form); } if (ConfigUtil.GetBoolParameter("AutoOpenHostsConfigurator") && isWindowsHostsFile) { pagesTabControl.SelectedTabPage.Appearance.Header.ForeColor = ConfigUtil.GetColorParameter("ColorHostsConfigurator"); CustomFilesManager.OpenHostsSectionPanel(form); isWindowsHostsFile = false; } } } catch (Exception exception) { TabManager.ToggleTabFileTools(form, false); toolStripProgressBar.Visible = false; toolStripProgressBar.Value = 0; if (showMessages) { WindowManager.ShowErrorBox(form, exception.Message, exception); } } finally { toolStripProgressBar.Visible = false; toolStripProgressBar.Value = 0; } return(tabIdentity); }