private static void NoteModeOff(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; ToolStripMenuItem closeToolStripMenuItem3 = form.closeToolStripMenuItem3; if (ConfigUtil.GetBoolParameter("NoteModeTabs")) { pagesTabControl.CustomHeaderButtons.AddRange(new[] { new CustomHeaderButton(ButtonPredefines.Ellipsis) }); } menuStrip.Visible = true; toolStrip.Visible = !ConfigUtil.GetBoolParameter("ToolbarInvisible"); pagesTabControl.ShowTabHeader = DefaultBoolean.True; pagesTabControl.ContextMenuStrip = form.pageContextMenuStrip; verticalSplitContainer.Panel1.Padding = new Padding(3, 0, 3, 0); sessionToolStrip.Visible = closeToolStripMenuItem3.Enabled; searchReplacePanel.Visible = !ConfigUtil.GetBoolParameter("SearchReplacePanelDisabled"); statusStrip.Visible = !ConfigUtil.GetBoolParameter("StatusBarInvisible"); zoomPictureBox.Visible = true; zoomTrackBarControl.Visible = true; form.TopMost = !ConfigUtil.GetBoolParameter("StayOnTopDisabled"); form.FormBorderStyle = FormBorderStyle.Sizable; #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]); customLineNumbers.Visible = ConfigUtil.GetBoolParameter("LineNumbersVisible"); pageTextBox.WordWrap = !ConfigUtil.GetBoolParameter("WordWrapDisabled"); } if (CustomFilesManager.IsAnnotationPanelOpen(form)) { CustomFilesManager.ResumeAnnotationPanel(form); } form.WindowState = ConfigUtil.GetStringParameter("WindowState") == "Maximized" ? FormWindowState.Maximized : FormWindowState.Normal; form.Size = new Size(ConfigUtil.GetIntParameter("WindowSizeX"), ConfigUtil.GetIntParameter("WindowSizeY")); verticalSplitContainer.Panel2Collapsed = ConfigUtil.GetBoolParameter("InternalExplorerInvisible"); }
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 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 bool SaveFile(bool saveNewRecentFile, Form1 form, bool forceSaveAs, bool forceBackup, bool savingAll = false) { XtraTabControl pagesTabControl = form.pagesTabControl; ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel; ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar; SaveFileDialog saveFileDialog = form.saveFileDialog; try { String fileName; if (String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)) || forceSaveAs) { saveFileDialog.InitialDirectory = FileUtil.GetInitialFolder(form); SetFileDialogFilter(saveFileDialog); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.End); //Useful to save all execution DialogResult saveNewResult = saveFileDialog.ShowDialog(); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.Begin); //Useful to save all execution if (saveNewResult != DialogResult.OK) { toolStripProgressBar.Visible = false; return(false); } fileName = saveFileDialog.FileName; } else { fileName = ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage); } //Check that fileName is not already opened into another tab foreach (XtraTabPage tabPage in pagesTabControl.TabPages) { if (tabPage == pagesTabControl.SelectedTabPage || ProgramUtil.GetFilenameTabPage(tabPage) != fileName) { continue; } pagesTabControl.SelectedTabPage = tabPage; TabsUpdate(pagesTabControl, savingAll, UpdatePhase.End); //Useful to save all execution WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("FileAlreadyOpen", className)); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.Begin); //Useful to save all execution return(false); } bool favouriteFile = FavouriteManager.IsFileFavourite(fileName); Application.DoEvents(); toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = true; toolStripProgressBar.PerformStep(); if (!favouriteFile) { ConfigUtil.UpdateParameter("LastUserFolder", Path.GetDirectoryName(fileName)); } FileInfo fileInfo = new FileInfo(fileName); if (fileInfo.IsReadOnly && fileInfo.Exists) { toolStripProgressBar.Visible = false; TabsUpdate(pagesTabControl, savingAll, UpdatePhase.End); //Useful to save all execution WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("SavingReadonly", className)); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.Begin); //Useful to save all execution return(SaveFile(form, true)); } bool backupConfigActive = ConfigUtil.GetBoolParameter("BackupEnabled"); if ((!String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)) && !forceSaveAs) && (forceBackup || backupConfigActive)) { TabsUpdate(pagesTabControl, savingAll, UpdatePhase.End); //Useful to save all execution bool saved = BackupFileOnSaving(form, fileName); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.Begin); //Useful to save all execution if (saved == false) { toolStripProgressBar.Visible = false; return(false); } } toolStripProgressBar.PerformStep(); if (SaveFileCoreWithEncoding(form, fileName, savingAll) == false) { toolStripProgressBar.Visible = false; return(false); } if (!favouriteFile && saveNewRecentFile) { FileListManager.SetNewRecentFile(form, fileName); } if (CustomFilesManager.IsHostsSectionPanelOpen(form)) { CustomFilesManager.GetSections(form, false); } toolStripProgressBar.PerformStep(); CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); ProgramUtil.SetFilenameTabPage(pagesTabControl.SelectedTabPage, fileName); pagesTabControl.SelectedTabPage.ImageIndex = 0; pagesTabControl.SelectedTabPage.Text = Path.GetFileName(fileName); pageTextBox.CustomModified = false; pageTextBox.CustomOriginal = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text.GetHashCode().ToString(); form.Text = String.Format("DtPad - {0}", Path.GetFileName(fileName)); toolStripStatusLabel.Text = String.Format("{0} \"{1}\" {2}", LanguageUtil.GetCurrentLanguageString("File", className), Path.GetFileName(fileName), LanguageUtil.GetCurrentLanguageString("Saved", className)); TabManager.ToggleTabFileTools(form, true); toolStripProgressBar.PerformStep(); toolStripProgressBar.Visible = false; } catch (Exception exception) { TabManager.ToggleTabFileTools(form, false); toolStripProgressBar.Visible = false; TabsUpdate(pagesTabControl, savingAll, UpdatePhase.End); //Useful to save all execution WindowManager.ShowErrorBox(form, exception.Message, exception); TabsUpdate(pagesTabControl, savingAll, UpdatePhase.Begin); //Useful to save all execution return(false); } return(true); }
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); } }
private static void OpenPanel(Form1 form, XtraTabPage tabPage) { CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(tabPage); CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(tabPage); bool wasHostsSectionOpen = false; if (CustomFilesManager.IsHostsSectionPanelOpen(form)) { wasHostsSectionOpen = true; CustomFilesManager.ToggleHostsSectionPanel(form, true); } String annotationText = String.Empty; if (CustomFilesManager.IsAnnotationPanelOpen(form)) { annotationText = CustomFilesManager.GetAnnotationPanelText(form); CustomFilesManager.ToggleAnnotationPanel(form, true); } int left = 0; if (ConfigUtil.GetBoolParameter("LineNumbersVisible")) { left = customLineNumbers.Width; } //Panel RichTextBox columnRulerTextBox = new RichTextBox { Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left, BackColor = pageTextBox.BackColor, BorderStyle = BorderStyle.None, Font = pageTextBox.Font, //ForeColor = pageTextBox.ForeColor, ForeColor = SystemColors.AppWorkspace, Height = Convert.ToInt32(pageTextBox.Font.GetHeight() * 2 + 5), //35 Left = left, Multiline = true, Name = "columnRulerTextBox", ReadOnly = true, ScrollBars = RichTextBoxScrollBars.None, ShortcutsEnabled = false, Text = ConstantUtil.columnsHeader, Width = pageTextBox.Width + 1, WordWrap = false }; CustomPanel columnRulerPanel = new CustomPanel { Dock = DockStyle.Top, Height = columnRulerTextBox.Height + 1, Name = "columnRulerPanel", Width = tabPage.Width, HorizontalLine = true, MarginLeftHorizontalLine = tabPage.Width - columnRulerTextBox.Width - 5 }; columnRulerPanel.Controls.Add(columnRulerTextBox); tabPage.Controls.Add(columnRulerPanel); if (wasHostsSectionOpen) { CustomFilesManager.ToggleHostsSectionPanel(form, true); } if (!String.IsNullOrEmpty(annotationText)) { CustomFilesManager.ToggleAnnotationPanel(form); CustomFilesManager.SetAnnotationPanelText(form, annotationText); } pageTextBox.Focus(); }