private static bool IsContentAlreadyClipboarded(Form form, String newContent)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile));

                XmlNodeList contentList = xmldoc.GetElementsByTagName("content");

                //foreach (XmlNode content in contentList)
                //{
                //    if (content.InnerText == newContent)
                //    {
                //        return true;
                //    }
                //}
                if (contentList.Cast <XmlNode>().Any(content => content.InnerText == newContent))
                {
                    return(true);
                }
            }
            catch (XmlException exception)
            {
                WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className), exception);
                FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent);
            }

            return(false);
        }
Exemple #2
0
        private static void ManageError(Form1 form, Exception exception)
        {
            WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorCreating", className), exception);

            form.TabIdentity = FileManager.OpenFile(form, form.TabIdentity, new[] { ConstantUtil.noFile });
            FileListManager.SaveFileList(ConstantUtil.noFile, ConstantUtil.defaultNoteFileContent);
        }
        internal static void GetClipboardList(Form1 form, bool forceLoad)
        {
            ListBox        clipboardListBox   = form.clipboardPanel.clipboardListBox;
            XtraTabControl verticalTabControl = form.verticalTabControl;
            XtraTabPage    clipboardTabPage   = form.clipboardTabPage;

            if ((verticalTabControl.SelectedTabPage != clipboardTabPage) || (!forceLoad && clipboardListBox.Items.Count > 0))
            {
                return;
            }

            ClearClipboardList(form);

            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile));

                XmlNodeList clipList = xmldoc.GetElementsByTagName("clip");

                foreach (XmlNode clip in clipList)
                {
                    clipboardListBox.Items.Add(clip.ChildNodes[1].InnerText); //short
                }
            }
            catch (XmlException exception)
            {
                WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className), exception);
                FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent);
            }
        }
Exemple #4
0
        internal static ToolObjectList GetToolObjectListFromToFile(Form form)
        {
            try
            {
                ToolObjectList toolObjectList = new ToolObjectList();

                String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.toFile));

                String[] separator           = { Environment.NewLine };
                String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                foreach (String extensionString in splittedFileContent)
                {
                    separator[0] = "|";
                    String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.None);

                    ToolObject toolObject = new ToolObject(splittedExtensionContent[0], splittedExtensionContent[1], splittedExtensionContent[2], Convert.ToInt32(splittedExtensionContent[3]));
                    toolObjectList.Add(toolObject);
                }

                return(toolObjectList);
            }
            catch (Exception)
            {
                WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className));
                FileListManager.SaveFileList(ConstantUtil.toFile, String.Empty);

                return(GetToolObjectListFromToFile(form));
            }
        }
Exemple #5
0
        internal static void DeleteFavourite(Favourites form, Form1 form1)
        {
            ListBox favouritesListBox = form.favouritesListBox;

            int selectedIndex = favouritesListBox.SelectedIndex;

            FileListManager.DeleteExistingFavouriteFile(form1, selectedIndex);

            favouritesListBox.Items.Clear();
            form.InitializeForm(true);

            if (favouritesListBox.Items.Count <= 0)
            {
                return;
            }

            if (selectedIndex < favouritesListBox.Items.Count)
            {
                favouritesListBox.SelectedIndex = selectedIndex;
            }
            else
            {
                favouritesListBox.SelectedIndex = selectedIndex - 1;
            }
        }
        private static String GetContent(int number)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile));

                XmlNodeList clipList = xmldoc.GetElementsByTagName("clip");

                foreach (XmlNode clip in clipList)
                {
                    if (clip.ChildNodes[0].InnerText == number.ToString())
                    {
                        return(clip.ChildNodes[2].InnerText);
                    }
                }
            }
            catch (XmlException exception)
            {
                WindowManager.ShowErrorBox(null, LanguageUtil.GetCurrentLanguageString("ErrorReading", className), exception);
                FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent);
            }

            return(String.Empty);
        }
Exemple #7
0
        internal static TemplateObjectList LoadTemplatesList(Templates form)
        {
            TreeView templateTreeView   = form.templateTreeView;
            TextBox  descriptionTextBox = form.descriptionTextBox;
            TextBox  textTextBox        = form.textTextBox;
            Button   removeButton       = form.removeButton;

            TemplateObjectList templateObjectList = new TemplateObjectList();

            String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.tmFile));

            String[] separator           = { Environment.NewLine };
            String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            if (splittedFileContent.Length > 0)
            {
                templateTreeView.BeginUpdate();
            }

            foreach (String templateString in splittedFileContent) //HTML@|-<html></html>
            {
                separator[0] = "@|-";
                String[] splittedExtensionContent = templateString.Split(separator, StringSplitOptions.None);

                if (splittedExtensionContent.Length != 2)
                {
                    WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className));
                    FileListManager.SaveFileList(ConstantUtil.tmFile, String.Empty);
                    return(LoadTemplatesList(form));
                }

                templateTreeView.Nodes.Add(splittedExtensionContent[0]); //HTML

                TemplateObject templateObject = new TemplateObject(splittedExtensionContent[0], splittedExtensionContent[1]);
                templateObjectList.Add(templateObject);
            }

            if (splittedFileContent.Length > 0)
            {
                templateTreeView.EndUpdate();
            }

            templateTreeView.Focus();

            if (templateTreeView.Nodes.Count > 0)
            {
                templateTreeView.SelectedNode = templateTreeView.Nodes[0];
            }
            else
            {
                descriptionTextBox.Enabled = false;
                textTextBox.Enabled        = false;
                removeButton.Enabled       = false;
            }

            return(templateObjectList);
        }
Exemple #8
0
        private static bool ReplaceAllInOneFile(Form1 form, bool searchInAllFiles)
        {
            CustomRichTextBox    textBox                       = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            FileListManager.SetNewSearchHistory(form, searchTextBox.Text);

            String textWhereToSearch;
            String textToSearch;

            GetTextCaseNormalization(form, out textWhereToSearch, out textToSearch);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, textBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int counter = SearchReplaceUtil.SearchCountOccurency(form, false, true);
                textBox.SelectAll();

                if (caseCheckBox.Checked)
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.Ordinal);
                }
                else
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.OrdinalIgnoreCase);
                }

                TextManager.RefreshUndoRedoExternal(form);
                textBox.Select(0, 0);

                toolStripStatusLabel.Text = String.Format("{0} {1}", counter, LanguageUtil.GetCurrentLanguageString("Replaced", className, counter));

                return(true);
            }
            if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(false);
        }
        private static ExtensionObjectList LoadExtensionsListPrivate(Extensions form, bool suppressMessageBox)
        {
            TreeView extensionTreeView = form.extensionTreeView;

            ExtensionObjectList extensionObjectList = new ExtensionObjectList();

            String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.exFile));

            String[] separator           = { Environment.NewLine };
            String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            if (splittedFileContent.Length > 0)
            {
                extensionTreeView.BeginUpdate();
            }

            foreach (String extensionString in splittedFileContent)
            {
                separator[0] = "|";
                String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                if (splittedExtensionContent.Length != 3)
                {
                    if (!suppressMessageBox)
                    {
                        WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Reading", className));
                    }
                    FileListManager.SaveFileList(ConstantUtil.exFile, ConstantUtil.defaultExtensionFileContent);
                    return(LoadExtensionsList(form));
                }

                extensionTreeView.Nodes.Add(splittedExtensionContent[0]); //Text document

                ExtensionObject extensionObject = new ExtensionObject(splittedExtensionContent[0], splittedExtensionContent[1], Convert.ToBoolean(splittedExtensionContent[2]));
                extensionObjectList.Add(extensionObject);
            }

            if (splittedFileContent.Length > 0)
            {
                extensionTreeView.EndUpdate();
            }

            extensionTreeView.Focus();
            extensionTreeView.SelectedNode = extensionTreeView.Nodes[0];

            return(extensionObjectList);
        }
Exemple #10
0
        internal static void CheckSearchReplacePanel(Form1 form, bool makeVisible, bool refreshConfig)
        {
            ToolStripButton showSearchPanelToolStripButton = form.showSearchPanelToolStripButton;
            //ToolStripMenuItem showSearchPanelToolStripMenuItem = form.showSearchPanelToolStripMenuItem;
            Panel             searchReplacePanel = form.searchReplacePanel;
            TextBox           searchTextBox      = form.searchPanel.searchTextBox;
            ToolStripButton   highlightsResultsToolStripButton = form.searchPanel.highlightsResultsToolStripButton;
            CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);

            highlightsResultsToolStripButton.Checked = ConfigUtil.GetBoolParameter("SearchHighlightsResults");
            searchReplacePanel.Visible             = makeVisible;
            showSearchPanelToolStripButton.Checked = makeVisible;
            //showSearchPanelToolStripMenuItem.Checked = makeVisible;
            UpdateConfigParameter("SearchReplacePanelDisabled", (!makeVisible).ToString(), refreshConfig);

            switch (ConfigUtil.GetIntParameter("SearchReturn"))
            {
            case 0:
                form.searchPanel.searchTextBox.ReturnActionType  = CustomTextBox.ReturnAction.StartSearch;
                form.searchPanel.replaceTextBox.ReturnActionType = CustomTextBox.ReturnAction.StartReplace;
                break;

            case 1:
                form.searchPanel.searchTextBox.ReturnActionType  = CustomTextBox.ReturnAction.InsertCR;
                form.searchPanel.replaceTextBox.ReturnActionType = CustomTextBox.ReturnAction.InsertCR;
                break;
            }

            pageTextBox.Refresh();

            if (!makeVisible) // && !form.IsOpening)
            {
                //if (refreshConfig)
                //{
                //    StringUtil.ClearHighlightsResults(form);
                //}

                pageTextBox.Focus();
                return;
            }

            FileListManager.LoadSearchHistory(form);
            searchTextBox.Focus();
            searchTextBox.SelectAll();
        }
Exemple #11
0
        private static void GetTextCaseNormalization(Form1 form, out String textWhereToSearch, out String textToSearch)
        {
            RichTextBox textBox       = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);
            CheckBox    caseCheckBox  = form.searchPanel.caseCheckBox;
            TextBox     searchTextBox = form.searchPanel.searchTextBox;

            textWhereToSearch = textBox.Text;
            textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);
            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (caseCheckBox.Checked)
            {
                return;
            }

            textWhereToSearch = textWhereToSearch.ToLower();
            textToSearch      = textToSearch.ToLower();
        }
Exemple #12
0
        internal static void AddNewFavouriteSession(Favourites form, Form1 form1)
        {
            ListBox favouritesListBox = form.favouritesListBox;

            String filter   = LanguageUtil.GetCurrentLanguageString("FileDialog", className);
            String fileName = FileUtil.GetFileNameAndPath(form1, filter, 0, "*.dps");

            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }

            FileListManager.SetNewFavouriteFile(form1, ConstantUtil.sessionPrefix + fileName);

            favouritesListBox.Items.Clear();
            form.InitializeForm(true);
            favouritesListBox.SelectedIndex = favouritesListBox.Items.Count - 1;
        }
Exemple #13
0
        internal static void RenameFile(Form1 form, String newName)
        {
            XtraTabControl       pagesTabControl      = form.pagesTabControl;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

            String fileName = ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage);

            if (String.IsNullOrEmpty(fileName) || Path.GetFileName(fileName) == newName)
            {
                return;
            }
            FileInfo fileInfo = new FileInfo(fileName);

            if (fileInfo.IsReadOnly)
            {
                if (WindowManager.ShowQuestionCancelBox(form, LanguageUtil.GetCurrentLanguageString("RemoveReadonlyToRename", className)) == DialogResult.Yes)
                {
                    ToggleReadonly(form);
                }
                else
                {
                    return;
                }
            }

            String newFileName = Path.Combine(Path.GetDirectoryName(fileName), newName);

            ProgramUtil.SetFilenameTabPage(pagesTabControl.SelectedTabPage, newFileName);
            pagesTabControl.SelectedTabPage.Text = newName;
            form.Text = String.Format("DtPad - {0}", newName);

            if (File.Exists(fileName))
            {
                File.Move(fileName, newFileName);
            }
            else
            {
                SaveFile(form, false);
            }

            SessionManager.FileRenamed(form, fileName, newFileName);
            FileListManager.SetNewRecentFile(form, newFileName);
            toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("FileRenamed", className), fileName, newName);
        }
Exemple #14
0
        internal static bool SaveTemplatesIntoFile(Form form, TemplateObjectList templateObjectList)
        {
            String fileContent = String.Empty;

            foreach (TemplateObject templateObject in templateObjectList)
            {
                if (String.IsNullOrEmpty(templateObject.Text))
                {
                    WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Unvalorized", className));
                    return(false);
                }

                fileContent += String.Format("{0}@|-{1}{2}", templateObject.Description, templateObject.Text, Environment.NewLine);
            }

            FileListManager.SaveFileList(ConstantUtil.tmFile, fileContent);

            return(true);
        }
Exemple #15
0
        internal static bool SaveToolsIntoFile(Form form, ToolObjectList toolObjectList)
        {
            String fileContent = String.Empty;

            foreach (ToolObject toolObject in toolObjectList)
            {
                if (String.IsNullOrEmpty(toolObject.CommandLine))
                {
                    WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Unvalorized", className));
                    return(false);
                }

                fileContent += String.Format("{0}|{1}|{2}|{3}{4}", toolObject.Description, toolObject.CommandLine, toolObject.WorkingFolder, toolObject.Run, Environment.NewLine);
            }

            FileListManager.SaveFileList(ConstantUtil.toFile, fileContent);

            return(true);
        }
Exemple #16
0
        private static void SearchCount(Form1 form, bool searchInAllFiles)
        {
            TextBox searchTextBox = form.searchPanel.searchTextBox;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return;
            }

            String textToSearch = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            int occurency = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles);

            WindowManager.ShowInfoBox(form, String.Format("{0} {1}!", occurency, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurency)));
            toolStripStatusLabel.Text = String.Format("{0} {1}", occurency, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurency));
        }
Exemple #17
0
        internal static void AddNewFavourite(Favourites form, Form1 form1)
        {
            ListBox favouritesListBox = form.favouritesListBox;

            int    defaultExtension;
            String defaultExtensionShortString;
            String filter   = ExtensionManager.GetFileDialogFilter(out defaultExtension, out defaultExtensionShortString);
            String fileName = FileUtil.GetFileNameAndPath(form1, filter, defaultExtension, defaultExtensionShortString);

            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }

            FileListManager.SetNewFavouriteFile(form1, fileName);

            favouritesListBox.Items.Clear();
            form.InitializeForm(true);
            favouritesListBox.SelectedIndex = favouritesListBox.Items.Count - 1;
        }
        private static bool SaveExtensionsIntoFilePrivate(Form form, ExtensionObjectList extensionObjectList, bool suppressMessageBox)
        {
            String fileContent = String.Empty;

            foreach (ExtensionObject extensionObject in extensionObjectList)
            {
                if (String.IsNullOrEmpty(extensionObject.Extension) || String.IsNullOrEmpty(extensionObject.Description))
                {
                    if (!suppressMessageBox)
                    {
                        WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Unvalorized", className));
                    }
                    return(false);
                }

                fileContent += String.Format("{0}|{1}|{2}{3}", extensionObject.Description, extensionObject.Extension, extensionObject.DefaultExtension, Environment.NewLine);
            }

            FileListManager.SaveFileList(ConstantUtil.exFile, fileContent);

            return(true);
        }
Exemple #19
0
        internal static void MoveFavourite(Favourites form, Form1 form1, ObjectListUtil.Movement move)
        {
            ListBox favouritesListBox = form.favouritesListBox;
            Object  selectedItem      = favouritesListBox.SelectedItem;
            int     selectedItemIndex = favouritesListBox.SelectedIndex;

            favouritesListBox.Items.RemoveAt(selectedItemIndex);

            switch (move)
            {
            case ObjectListUtil.Movement.Up:
                favouritesListBox.Items.Insert(selectedItemIndex - 1, selectedItem);
                break;

            case ObjectListUtil.Movement.Down:
                favouritesListBox.Items.Insert(selectedItemIndex + 1, selectedItem);
                break;
            }

            favouritesListBox.SelectedItem = selectedItem;
            FileListManager.CreateFileFromListBox(form);
            FileListManager.LoadFavouriteFiles(form1, true);
        }
Exemple #20
0
        internal static void RefreshOwner(Options form, bool closeOptionsAfterSave, Font previousFont, Font font, Color previousFontColor, Color fontColor, Color previousBackgroundColor, Color backgroundColor, bool previousHighlightURL, String previousLanguage, bool previousJumpListActivated)
        {
            Form1 form1 = (Form1)form.Owner;

            XtraTabControl    pagesTabControl             = form1.pagesTabControl;
            CheckBox          caseCheckBox                = form1.searchPanel.caseCheckBox;
            CheckBox          loopCheckBox                = form1.searchPanel.loopCheckBox;
            ToolStrip         sessionToolStrip            = form1.sessionToolStrip;
            ToolStripMenuItem useDefaultToolStripMenuItem = form1.useDefaultToolStripMenuItem;

            CheckBox          showSearchPanelCheckBox    = form.showSearchPanelCheckBox;
            CheckBox          wordWrapCheckBox           = form.wordWrapCheckBox;
            CheckBox          stayOnTopCheckBox          = form.stayOnTopCheckBox;
            CheckBox          toolbarCheckBox            = form.toolbarCheckBox;
            CheckBox          statusBarCheckBox          = form.statusBarCheckBox;
            CheckBox          minimizeOnTrayIconCheckBox = form.minimizeOnTrayIconCheckBox;
            CheckBox          caseSensitiveCheckBox      = form.caseSensitiveCheckBox;
            CheckBox          loopAtEOFCheckBox          = form.loopAtEOFCheckBox;
            CheckBox          urlsCheckBox                      = form.urlsCheckBox;
            ImageComboBoxEdit languageComboBox                  = form.languageComboBox;
            CheckBox          internalExplorerCheckBox          = form.internalExplorerCheckBox;
            ComboBox          tabCloseButtonOnComboBox          = form.tabCloseButtonOnComboBox;
            ComboBox          tabPositionComboBox               = form.tabPositionComboBox;
            ComboBox          tabOrientationComboBox            = form.tabOrientationComboBox;
            CheckBox          tabMultilineCheckBox              = form.tabMultilineCheckBox;
            CheckBox          useExistingCheckBox               = form.useExistingCheckBox;
            ComboBox          defaultComboBox                   = form.defaultComboBox;
            CheckBox          lineNumbersCheckBox               = form.lineNumbersCheckBox;
            CheckBox          keepInitialSpacesOnReturnCheckBox = form.keepInitialSpacesOnReturnCheckBox;
            CheckBox          keepBulletListOnReturnCheckBox    = form.keepBulletListOnReturnCheckBox;
            CheckBox          jumpListCheckBox                  = form.jumpListCheckBox;

            WindowManager.CheckSearchReplacePanel(form1, showSearchPanelCheckBox.Checked, true); //form1.searchPanel.Visible
            WindowManager.CheckWordWrap(form1, !wordWrapCheckBox.Checked, false);

            if (form1.WindowMode == CustomForm.WindowModeEnum.Fullscreen)
            {
                WindowManager.CheckStayOnTop(form1, !stayOnTopCheckBox.Checked, false);
            }
            WindowManager.CheckToolbar(form1, !toolbarCheckBox.Checked, true, false);
            WindowManager.CheckStatusBar(form1, !statusBarCheckBox.Checked, true, false);
            WindowManager.CheckTrayIcon(form1, !minimizeOnTrayIconCheckBox.Checked, false);
            WindowManager.CheckSearchCaseSensitive(caseSensitiveCheckBox.Checked, caseCheckBox, false);
            WindowManager.CheckSearchLoop(loopAtEOFCheckBox.Checked, loopCheckBox, false);
            WindowManager.CheckInternalExplorer(form1, internalExplorerCheckBox.Checked, false);
            WindowManager.CheckDefaultEncoding(form1, useExistingCheckBox.Checked, false);
            WindowManager.CheckEncoding(form1, defaultComboBox.SelectedIndex, false);
            WindowManager.CheckLineNumbers(form1, lineNumbersCheckBox.Checked, false);
            FileListManager.RefreshRecentFiles(form1);
            FileListManager.RefreshSearchHistory(form1);

            if ((previousJumpListActivated != jumpListCheckBox.Checked) && !jumpListCheckBox.Checked)
            {
                SystemUtil.ClearWindowsJumpList(form1);
            }
            else if ((previousJumpListActivated != jumpListCheckBox.Checked) && jumpListCheckBox.Checked)
            {
                SystemUtil.SetWindowsJumpList(form1);
            }

            //If session is open and don't use default aspect, it will do nothing
            if (!sessionToolStrip.Visible || (sessionToolStrip.Visible && useDefaultToolStripMenuItem.Checked))
            {
                CheckTabCloseButton(form1, tabCloseButtonOnComboBox.SelectedIndex);
                CheckTabPosition(form1, tabPositionComboBox.SelectedIndex);
                CheckTabOrientation(form1, tabOrientationComboBox.SelectedIndex);
            }

            CheckTabMultiline(form1, tabMultilineCheckBox.Checked);
            form1.KeepInitialSpacesOnReturn = keepInitialSpacesOnReturnCheckBox.Checked;
            form1.KeepBulletListOnReturn    = keepBulletListOnReturnCheckBox.Checked;

            if (!previousFont.Equals(font) || previousFontColor != fontColor || previousBackgroundColor != backgroundColor || previousHighlightURL != urlsCheckBox.Checked)
            {
                foreach (XtraTabPage tabPage in pagesTabControl.TabPages)
                {
                    CustomRichTextBox pageTextBox       = ProgramUtil.GetPageTextBox(tabPage);
                    CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(tabPage);

                    pageTextBox.Font            = font;
                    customLineNumbers.Font      = font;
                    pageTextBox.ForeColor       = fontColor;
                    pageTextBox.BackColor       = backgroundColor;
                    customLineNumbers.BackColor = backgroundColor;
                    pageTextBox.DetectUrls      = urlsCheckBox.Checked;
                }

                form1.SetMainFont(font);
                form1.TextFontColor       = fontColor;
                form1.TextBackgroundColor = backgroundColor;
            }

            LookFeelUtil.SetForm1LookAndFeel(form1);
            //if (!closeOptionsAfterSave)
            //{
            //    LookFeelUtil.SetOptionsLookAndFeel(form);
            //}

            if (previousLanguage == languageComboBox.SelectedItem.ToString())
            {
                return;
            }

            ConfigUtil.UpdateParameter("RecreateJumpList", true.ToString());
            if (!closeOptionsAfterSave)
            {
                form.SetLanguage();
            }
            form1.SetLanguage(true);
        }
Exemple #21
0
        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);
        }
 internal static void ClearClipboardFile(Form1 form)
 {
     ClearClipboardList(form);
     FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent);
 }
        internal static void AddContent(Form1 form)
        {
            ListBox clipboardListBox = form.clipboardPanel.clipboardListBox;
            String  content;

            try
            {
                if (!Clipboard.ContainsText())
                {
                    return;
                }

                content = Clipboard.GetText();
            }
            catch (ExternalException exception)
            {
                WindowManager.ShowErrorBox(form, exception.Message, exception);
                return;
            }

            String shortContent = content.Replace(ConstantUtil.newLine, " ");

            shortContent = shortContent.Replace(Environment.NewLine, " ");
            shortContent = StringUtil.CheckStringLengthEnd(shortContent, maxCharCount);
            //shortContent.Replace("<", "&lt;");
            //shortContent.Replace(">", "&gt;");

            if (IsContentAlreadyClipboarded(form, content))
            {
                return;
            }

            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile));

                XmlElement newClip = xmldoc.CreateElement("clip");

                XmlElement numberNode = xmldoc.CreateElement("number");
                numberNode.InnerText = clipboardListBox.Items.Count.ToString();
                newClip.AppendChild(numberNode);

                XmlElement      shortNode      = xmldoc.CreateElement("short");
                XmlCDataSection shortNodeCData = xmldoc.CreateCDataSection(shortContent);
                shortNode.InnerText = String.Empty;
                shortNode.AppendChild(shortNodeCData);

                XmlElement contentNode      = xmldoc.CreateElement("content");
                XmlText    contentNodeCData = xmldoc.CreateTextNode(content); //XmlCDataSection contentNodeCData = xmldoc.CreateCDataSection(content);
                contentNode.InnerText = String.Empty;
                contentNode.AppendChild(contentNodeCData);

                newClip.AppendChild(shortNode);
                newClip.AppendChild(contentNode);

                if (xmldoc.DocumentElement != null)
                {
                    xmldoc.DocumentElement.InsertAfter(newClip, xmldoc.DocumentElement.LastChild);
                    xmldoc.Save(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.clFile));

                    clipboardListBox.Items.Add(shortContent);
                }
                else
                {
                    throw new XmlException();
                }
            }
            catch (XmlException exception)
            {
                WindowManager.ShowErrorBox(form, LanguageUtil.GetCurrentLanguageString("ErrorCreation", className), exception);
                FileListManager.SaveFileList(ConstantUtil.clFile, ConstantUtil.defaultClipboardFileContent);
            }
        }
Exemple #24
0
        private static bool SearchFirst(Form1 form, bool searchInAllFiles, String specificTextToSearch = null)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text) && String.IsNullOrEmpty(specificTextToSearch))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = !String.IsNullOrEmpty(specificTextToSearch) ? specificTextToSearch : searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int positionSearchedText = -1;
            //int selectionLength = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    positionSearchedText = textWhereToSearch.IndexOf(textToSearch);
            //    selectionLength = textToSearch.Length;
            //}
            //else
            //{
            //    Regex regex = new Regex(textToSearch);
            //    Match regexMatch = regex.Match(textWhereToSearch, 0);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles, false, specificTextToSearch);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(valueFounded);
        }
Exemple #25
0
        private static bool SearchPrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int selectionLength = -1;
            //int positionSearchedText = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    selectionLength = textToSearch.Length;
            //    positionSearchedText = subString.LastIndexOf(textToSearch);
            //}
            //else
            //{
            //    Match regexMatch = Regex.Match(subString, textToSearch, RegexOptions.RightToLeft);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        return(SearchLast(form, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        return(SearchLast(form, false));
                    }
                }
            }

            return(valueFounded);
        }
Exemple #26
0
        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);
        }
Exemple #27
0
        private static String WriteSessionXML(Form1 form, String fileName)
        {
            XtraTabControl          pagesTabControl                 = form.pagesTabControl;
            ToolStripDropDownButton sessionImageToolStripButton     = form.sessionImageToolStripButton;
            ToolStripMenuItem       useDefaultToolStripMenuItem     = form.useDefaultToolStripMenuItem;
            ToolStripMenuItem       closeButtonToolStripMenuItem    = form.closeButtonToolStripMenuItem;
            ToolStripMenuItem       tabPositionToolStripMenuItem    = form.tabPositionToolStripMenuItem;
            ToolStripMenuItem       tabOrientationToolStripMenuItem = form.tabOrientationToolStripMenuItem;

            sessionImageToolStripButton.DropDownItems.Clear();
            String newSessionName = Path.GetFileNameWithoutExtension(fileName);

            FileListManager.SaveFileList(fileName, ConstantUtil.defaultSessionFileContent);
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(fileName);

            if (xmldoc.DocumentElement == null)
            {
                throw new XmlException(String.Format(LanguageUtil.GetCurrentLanguageString("XmlDocError", className), Path.GetFileName(fileName)));
            }

            xmldoc.DocumentElement.SetAttribute("name", newSessionName);
            xmldoc.DocumentElement.SetAttribute("aspect", useDefaultToolStripMenuItem.Checked ? "default" : "custom");
            xmldoc.DocumentElement.SetAttribute("button", GetDropDownIndexChecked(closeButtonToolStripMenuItem).ToString());
            xmldoc.DocumentElement.SetAttribute("position", GetDropDownIndexChecked(tabPositionToolStripMenuItem).ToString());
            xmldoc.DocumentElement.SetAttribute("orientation", GetDropDownIndexChecked(tabOrientationToolStripMenuItem).ToString());

            sessionImageToolStripButton.DropDownItems.Add(fileName);
            sessionImageToolStripButton.DropDownItems[0].Image  = ToolbarResource.diagram;
            sessionImageToolStripButton.DropDownItems[0].Click += form.sessionPropertiesToolStripMenuItem_Click;
            sessionImageToolStripButton.DropDownItems.Add(new ToolStripSeparator());

            foreach (XtraTabPage tabControl in pagesTabControl.TabPages)
            {
                String fileNameTab = ProgramUtil.GetFilenameTabPage(tabControl);

                if (String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(tabControl).Text) && String.IsNullOrEmpty(fileNameTab))
                {
                    continue;
                }

                XmlElement newFile = xmldoc.CreateElement("file");

                String relativePath = FileUtil.EvaluateRelativePath(Path.GetDirectoryName(fileName), Path.GetDirectoryName(fileNameTab));
                newFile.SetAttribute("path", relativePath);
                newFile.SetAttribute("name", Path.GetFileName(fileNameTab));
                newFile.SetAttribute("tabcolor", TabManager.GetTabColor(tabControl).ToKnownColor().ToString()); //newFile.SetAttribute("tabcolor", tabControl.Appearance.Header.ForeColor.ToKnownColor().ToString());
                if (pagesTabControl.SelectedTabPage == tabControl)
                {
                    newFile.SetAttribute("open", true.ToString());
                }

                if (xmldoc.DocumentElement == null)
                {
                    throw new XmlException(String.Format(LanguageUtil.GetCurrentLanguageString("XmlDocError", className), Path.GetFileName(fileName)));
                }

                xmldoc.DocumentElement.AppendChild(newFile);
                sessionImageToolStripButton.DropDownItems.Add(fileNameTab);
                sessionImageToolStripButton.DropDownItems[sessionImageToolStripButton.DropDownItems.Count - 1].Click += form.sessionImageToolStripButton_Click;
            }

            xmldoc.Save(fileName);
            //WindowManager.ShowInfoBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("SaveSuccesfull", className), newSessionName));

            return(newSessionName);
        }
Exemple #28
0
        internal static ToolObjectList LoadToolsList(Tools form)
        {
            TreeView toolTreeView         = form.toolTreeView;
            TextBox  descriptionTextBox   = form.descriptionTextBox;
            TextBox  commandLineTextBox   = form.commandLineTextBox;
            TextBox  workingFolderTextBox = form.workingFolderTextBox;
            ComboBox runComboBox          = form.runComboBox;
            Button   removeButton         = form.removeButton;

            ToolObjectList toolObjectList = new ToolObjectList();

            String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.toFile));

            String[] separator           = { Environment.NewLine };
            String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            if (splittedFileContent.Length > 0)
            {
                toolTreeView.BeginUpdate();
            }

            foreach (String toolString in splittedFileContent)
            {
                separator[0] = "|";
                String[] splittedExtensionContent = toolString.Split(separator, StringSplitOptions.None);

                if (splittedExtensionContent.Length != 4)
                {
                    WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className));
                    FileListManager.SaveFileList(ConstantUtil.toFile, String.Empty);
                    return(LoadToolsList(form));
                }

                toolTreeView.Nodes.Add(splittedExtensionContent[0]); //DtPad

                ToolObject toolObject = new ToolObject(splittedExtensionContent[0], splittedExtensionContent[1], splittedExtensionContent[2], Convert.ToInt32(splittedExtensionContent[3]));
                toolObjectList.Add(toolObject);
            }

            if (splittedFileContent.Length > 0)
            {
                toolTreeView.EndUpdate();
            }

            toolTreeView.Focus();

            if (toolTreeView.Nodes.Count > 0)
            {
                toolTreeView.SelectedNode = toolTreeView.Nodes[0];
            }
            else
            {
                descriptionTextBox.Enabled   = false;
                commandLineTextBox.Enabled   = false;
                workingFolderTextBox.Enabled = false;
                runComboBox.Enabled          = false;
                runComboBox.SelectedIndex    = 0;
                removeButton.Enabled         = false;
            }

            return(toolObjectList);
        }
Exemple #29
0
        private static bool ReplacePrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl               = form.pagesTabControl;
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            CustomRichTextBox    pageTextBox                   = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                toolStripStatusLabel.Text = String.Format("1 {0}", LanguageUtil.GetCurrentLanguageString("Replaced", className, 1));
                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.SelectedText = replaceTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);
                TextManager.RefreshUndoRedoExternal(form);

                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }
                }
            }

            return(valueFounded);
        }
Exemple #30
0
        internal static void OpenSession(Form1 form, String fileName = null)
        {
            CustomXtraTabControl pagesTabControl              = form.pagesTabControl;
            ToolStrip            sessionToolStrip             = form.sessionToolStrip;
            ToolStripButton      sessionToolStripButton       = form.sessionToolStripButton;
            ToolStripMenuItem    closeToolStripMenuItem3      = form.closeToolStripMenuItem3;
            ToolStripMenuItem    saveToolStripMenuItem2       = form.saveToolStripMenuItem2;
            ToolStripMenuItem    exportAsZipToolStripMenuItem = form.exportAsZipToolStripMenuItem;
            ToolStripStatusLabel toolStripStatusLabel         = form.toolStripStatusLabel;
            OpenFileDialog       openFileDialog       = form.openFileDialog;
            ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar;
            //SplitContainer verticalSplitContainer = form.verticalSplitContainer;
            ToolStripMenuItem renameSessionToolStripMenuItem     = form.renameSessionToolStripMenuItem;
            ToolStripMenuItem favouriteSessionToolStripMenuItem  = form.favouriteSessionToolStripMenuItem;
            ToolStripMenuItem listFilesToolStripMenuItem         = form.listFilesToolStripMenuItem;
            ToolStripMenuItem aspectToolStripMenuItem            = form.aspectToolStripMenuItem;
            ToolStripMenuItem useDefaultToolStripMenuItem        = form.useDefaultToolStripMenuItem;
            ToolStripMenuItem closeButtonToolStripMenuItem       = form.closeButtonToolStripMenuItem;
            ToolStripMenuItem tabPositionToolStripMenuItem       = form.tabPositionToolStripMenuItem;
            ToolStripMenuItem tabOrientationToolStripMenuItem    = form.tabOrientationToolStripMenuItem;
            ToolStripMenuItem sessionPropertiesToolStripMenuItem = form.sessionPropertiesToolStripMenuItem;

            try
            {
                bool isASessionOpened = IsASessionOpened(form);
                if (isASessionOpened && WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("AlreadyOpen", className)) != DialogResult.Yes)
                {
                    return;
                }
                if (isASessionOpened)
                {
                    CloseSession(form);
                }

                if (String.IsNullOrEmpty(fileName))
                {
                    openFileDialog.InitialDirectory = FileUtil.GetInitialFolder(form);
                    openFileDialog.Multiselect      = false;
                    openFileDialog.Filter           = LanguageUtil.GetCurrentLanguageString("FileDialog", className);
                    openFileDialog.FilterIndex      = 0;
                    openFileDialog.FileName         = "*.dps";

                    if (openFileDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    fileName = openFileDialog.FileName;
                }

                if (!File.Exists(fileName))
                {
                    WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("FileNotExisting", className), fileName));
                    return;
                }
                if (FileUtil.IsFileInUse(fileName))
                {
                    WindowManager.ShowAlertBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("FileInUse", className), fileName));
                    return;
                }
                if (pagesTabControl.TabPages.Count > 1 && TabManager.AreAllTabsEmpty(form))
                {
                    if (!TabManager.CloseAllPages(form))
                    {
                        return;
                    }
                }

                bool   loadTotallyFailed;
                String sessionName = ReadSessionXML(form, fileName, out loadTotallyFailed);
                toolStripProgressBar.Visible = false;

                if (loadTotallyFailed)
                {
                    return;
                }

                sessionToolStrip.Visible                   = true;
                sessionToolStripButton.Text                = sessionName;
                closeToolStripMenuItem3.Enabled            = true;
                saveToolStripMenuItem2.Enabled             = true;
                exportAsZipToolStripMenuItem.Enabled       = true;
                renameSessionToolStripMenuItem.Enabled     = true;
                favouriteSessionToolStripMenuItem.Enabled  = true;
                listFilesToolStripMenuItem.Enabled         = true;
                aspectToolStripMenuItem.Enabled            = true;
                useDefaultToolStripMenuItem.Enabled        = true;
                sessionPropertiesToolStripMenuItem.Enabled = true;

                if (!useDefaultToolStripMenuItem.Checked)
                {
                    closeButtonToolStripMenuItem.Enabled    = true;
                    tabPositionToolStripMenuItem.Enabled    = true;
                    tabOrientationToolStripMenuItem.Enabled = true;

                    OptionManager.CheckTabCloseButton(form, GetDropDownIndexChecked(closeButtonToolStripMenuItem));
                    OptionManager.CheckTabPosition(form, GetDropDownIndexChecked(tabPositionToolStripMenuItem));
                    OptionManager.CheckTabOrientation(form, GetDropDownIndexChecked(tabOrientationToolStripMenuItem));
                }
                else
                {
                    closeButtonToolStripMenuItem.Enabled    = false;
                    tabPositionToolStripMenuItem.Enabled    = false;
                    tabOrientationToolStripMenuItem.Enabled = false;
                }

                ConfigUtil.UpdateParameter("LastUserFolder", Path.GetDirectoryName(fileName));
                FileListManager.SetNewRecentSession(form, fileName);

                //verticalSplitContainer.Panel1.Padding = new Padding(0);
                toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("Opened", className), sessionToolStripButton.Text);
            }
            catch (Exception exception)
            {
                OptionManager.CheckTabCloseButton(form, ConfigUtil.GetIntParameter("TabCloseButtonMode"));
                OptionManager.CheckTabPosition(form, ConfigUtil.GetIntParameter("TabPosition"));
                OptionManager.CheckTabOrientation(form, ConfigUtil.GetIntParameter("TabOrientation"));

                WindowManager.ShowErrorBox(form, exception.Message, exception);
            }
        }