private static void RelaxModeOn(Form1 form) { XtraTabControl pagesTabControl = form.pagesTabControl; ToolStrip sessionToolStrip = form.sessionToolStrip; ToolStripMenuItem fullscreenToolStripMenuItem = form.fullscreenToolStripMenuItem; pagesTabControl.ContextMenuStrip = null; pagesTabControl.ShowTabHeader = DefaultBoolean.False; fullscreenToolStripMenuItem.Text = LanguageUtil.GetCurrentLanguageString("ExitRelaxMode", className); fullscreenToolStripMenuItem.Visible = true; WindowManager.CheckToolbar(form, true, false, false); WindowManager.CheckStatusBar(form, true, false, false); WindowManager.CheckLineNumbers(form, false, false); WindowManager.CheckWordWrap(form, false, false); WindowManager.CheckInternalExplorer(form, false, false); WindowManager.CheckSearchReplacePanel(form, false, false); sessionToolStrip.Visible = false; form.FormBorderStyle = FormBorderStyle.None; form.TopMost = true; form.WindowState = FormWindowState.Normal; form.Size = new Size(Screen.FromControl(form).Bounds.Width, Screen.FromControl(form).Bounds.Height); form.SetDesktopLocation(0, 0); #if Debug form.TopMost = false; #endif AddRelaxModeMargins(form); if (ColumnRulerManager.IsPanelOpen(pagesTabControl.SelectedTabPage)) { ColumnRulerManager.ClosePanel(pagesTabControl.SelectedTabPage); } if (CustomFilesManager.IsHostsSectionPanelOpen(form)) { CustomFilesManager.ToggleHostsSectionPanel(form); } if (CustomFilesManager.IsAnnotationPanelOpen(form)) { CustomFilesManager.HideAnnotationPanel(form); } }
internal static void ResetTab(Form1 form) { XtraTabControl pagesTabControl = form.pagesTabControl; CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(pagesTabControl.SelectedTabPage); if (ColumnRulerManager.IsPanelOpen(form)) { ColumnRulerManager.TogglePanel(form); } String newTabTitle = LanguageUtil.GetCurrentLanguageString("tabPage1", form.Name); SetTabColor(pagesTabControl.SelectedTabPage, Color.Black); //pagesTabControl.SelectedTabPage.Appearance.Header.ForeColor = Color.Black; pagesTabControl.SelectedTabPage.Appearance.Header.Reset(); pageTextBox.Text = String.Empty; pagesTabControl.SelectedTabPage.ImageIndex = 0; pagesTabControl.SelectedTabPage.Text = newTabTitle; pagesTabControl.SelectedTabPage.Tooltip = newTabTitle; form.Text = String.Format("DtPad - {0}", newTabTitle); ProgramUtil.SetFilenameTabPage(pagesTabControl.SelectedTabPage, String.Empty); pageTextBox.CustomZoom = 100; pageTextBox.CustomModified = false; pageTextBox.CustomOriginal = String.Empty.GetHashCode().ToString(); pageTextBox.CustomEncoding = String.Empty; pageTextBox.CustomEncodingForced = false; customLineNumbers.Width = customLineNumbers.MinimumSize.Width; ZoomSelect(form, 100); pageTextBox.ClearUndo(); TextManager.RefreshUndoRedoExternal(form); if (String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage))) { ToggleTabFileTools(form, false); } OtherManager.FocusOnEditor(form); }
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); }
private static void NoteModeOn(Form1 form) { MenuStrip menuStrip = form.menuStrip; ToolStrip toolStrip = form.toolStrip; XtraTabControl pagesTabControl = form.pagesTabControl; SplitContainer verticalSplitContainer = form.verticalSplitContainer; ToolStrip sessionToolStrip = form.sessionToolStrip; Panel searchReplacePanel = form.searchReplacePanel; StatusStrip statusStrip = form.statusStrip; PictureBox zoomPictureBox = form.zoomPictureBox; ZoomTrackBarControl zoomTrackBarControl = form.zoomTrackBarControl; if (ConfigUtil.GetBoolParameter("NoteModeTabs")) { ContextMenuStrip smallPageContextMenuStrip = new ContextMenuStrip(); for (int i = 0; i < 2; i++) { smallPageContextMenuStrip.Items.Add( ((CustomToolStripMenuItem)form.pageContextMenuStrip.Items[i]).Clone()); } pagesTabControl.ContextMenuStrip = smallPageContextMenuStrip; pagesTabControl.CustomHeaderButtons.Clear(); } else { pagesTabControl.ContextMenuStrip = null; pagesTabControl.ShowTabHeader = DefaultBoolean.False; } menuStrip.Visible = false; toolStrip.Visible = false; verticalSplitContainer.Panel1.Padding = new Padding(0, 0, 0, 0); verticalSplitContainer.Panel2Collapsed = true; sessionToolStrip.Visible = false; searchReplacePanel.Visible = false; statusStrip.Visible = false; zoomPictureBox.Visible = false; zoomTrackBarControl.Visible = false; form.TopMost = true; form.FormBorderStyle = FormBorderStyle.SizableToolWindow; #if Debug form.TopMost = false; #endif for (int i = 0; i < pagesTabControl.TabPages.Count; i++) { CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(pagesTabControl.TabPages[i]); CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.TabPages[i]); if (ColumnRulerManager.IsPanelOpen(pagesTabControl.TabPages[i])) { ColumnRulerManager.ClosePanel(pagesTabControl.TabPages[i]); } customLineNumbers.Visible = false; pageTextBox.WordWrap = true; } form.WindowState = FormWindowState.Normal; form.Size = new Size(ConfigUtil.GetIntParameter("NoteModeSizeX"), ConfigUtil.GetIntParameter("NoteModeSizeY")); if (CustomFilesManager.IsHostsSectionPanelOpen(form)) { form.Width += ConstantUtil.hostsPanelWidth; //ProgramUtil.GetSectionsPanel(pagesTabControl.SelectedTabPage).Width; } if (CustomFilesManager.IsAnnotationPanelOpen(form)) { CustomFilesManager.HideAnnotationPanel(form); } }