Esempio n. 1
0
        internal static void DeleteFile(Form1 form)
        {
            XtraTabControl       pagesTabControl      = form.pagesTabControl;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

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

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

            if (WindowManager.ShowQuestionCancelBox(form, String.Format(LanguageUtil.GetCurrentLanguageString("SureDeleteFile", className), fileName)) != DialogResult.Yes)
            {
                return;
            }

            FileInfo fileInfo = new FileInfo(fileName);

            if (fileInfo.IsReadOnly)
            {
                ToggleReadonly(form);
            }

            FileSystem.DeleteFile(fileName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); //File.Delete(fileName);
            toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("FileDeleted", className), fileName);

            TabManager.ClosePage(form, false);
        }
Esempio n. 2
0
        internal void InitializeForm()
        {
            InitializeComponent();
            LookFeelUtil.SetLookAndFeel(contentContextMenuStrip);
            SetLanguage();

            Form1 form = (Form1)Owner;

            String            filename    = ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage);
            CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);
            String            xmlString   = pageTextBox.Text;

            //XmlUrlResolver resolver = new XmlUrlResolver();
            //resolver.Credentials = CredentialCache.DefaultCredentials;
            XmlDocument       xmldoc   = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings
            {
                IgnoreWhitespace = true,
                //XmlResolver = resolver,
                IgnoreComments = true,
                DtdProcessing  = DtdProcessing.Parse                                 //ProhibitDtd = false
            };
            StringReader reader = new StringReader(xmlString);
            XmlReader    render = !String.IsNullOrEmpty(filename) ? XmlReader.Create(reader, settings, filename) : XmlReader.Create(reader, settings);

            try
            {
                xmldoc.Load(render);
            }
            catch (Exception exception)
            {
                String error = String.Format(LanguageUtil.GetCurrentLanguageString("Error", Name), exception.Message);
                WindowManager.ShowAlertBox(form, error);

                reader.Dispose();
                render.Close();
                return;
            }

            reader.Dispose();
            render.Close();

            GridBuilder   builder  = new GridBuilder();
            GridCellGroup xmlgroup = new GridCellGroup {
                Flags = GroupFlags.Overlapped | GroupFlags.Expanded
            };

            builder.ParseNodes(xmlgroup, null, xmldoc.ChildNodes);
            root = new GridCellGroup();
            root.Table.SetBounds(1, 2);
            root.Table[0, 0] = new GridHeadLabel {
                Text = "XML"
            };
            root.Table[0, 1] = xmlgroup;
            xmlGridView.Cell = root;

            xmlGridView.Font      = pageTextBox.Font;
            xmlGridView.ForeColor = pageTextBox.ForeColor;
            xmlGridView.BackColor = pageTextBox.BackColor;
        }
Esempio n. 3
0
        internal static bool IsCurrentTabInUse(Form1 form)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            return(!String.IsNullOrEmpty(pageTextBox.Text) || !String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)));
        }
Esempio n. 4
0
        internal static void WriteZipFile(String filename, IEnumerable <XtraTabPage> tabPages, String keepFoldersStartDir = "", IEnumerable <String> otherFiles = null)
        {
            ZipFile zipFile = ZipFile.Create(filename);

            zipFile.BeginUpdate();

            if (otherFiles != null)
            {
                foreach (String file in otherFiles)
                {
                    zipFile.Add(file, Path.GetFileName(file));
                }
            }

            foreach (XtraTabPage tabPage in tabPages)
            {
                String fileName  = ProgramUtil.GetFilenameTabPage(tabPage);
                String entryName = Path.GetFileName(ProgramUtil.GetFilenameTabPage(tabPage));

                if (keepFoldersStartDir != String.Empty)
                {
                    entryName = fileName.Substring(keepFoldersStartDir.Length + 1);
                }

                zipFile.Add(fileName, entryName);
            }

            zipFile.CommitUpdate();
            zipFile.Close();
        }
Esempio n. 5
0
        private void SetFileDialogFilter()
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            int    defaultExtension;
            String defaultExtensionShortString;
            String extensions = ExtensionManager.GetFileDialogFilter(out defaultExtension, out defaultExtensionShortString);

            String[] extensionsSplit = extensions.Split(new[] { '|' });

            int i = 0;

            while (i < extensionsSplit.Length)
            {
                saveAsComboBox.Items.Add(extensionsSplit[i]);
                i = i + 2;
            }

            if (defaultExtension != -1 && defaultExtension < saveAsComboBox.Items.Count)
            {
                saveAsComboBox.SelectedIndex = defaultExtension;
            }
            fileNameTextBox.Text = defaultExtensionShortString;

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

            if (windowType == WindowType.Save && !String.IsNullOrEmpty(fileNameTab))
            {
                fileNameTextBox.Text = Path.GetFileName(fileNameTab);
            }
        }
Esempio n. 6
0
        internal static void ShowFileInBrowser(Form1 form)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            if (String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Text))
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoContent", className));
                return;
            }

            String fileAndPathName;

            if (!String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)) && !ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).CustomModified)
            {
                fileAndPathName = ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage);
            }
            else
            {
                String fileName = String.Format("{0}.html", Guid.NewGuid());
                String pathName = Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.internetCacheDirectoryName);

                if (!Directory.Exists(pathName))
                {
                    Directory.CreateDirectory(pathName);
                }

                fileAndPathName = Path.Combine(pathName, fileName);
                if (FileManager.SaveFileCoreWithEncoding(form, fileAndPathName) == false)
                {
                    return;
                }
            }

            OtherManager.StartProcessBrowser(form, fileAndPathName);
        }
Esempio n. 7
0
        internal static void CopyFileName(Form1 form)
        {
            String fileName = Path.GetFileName(ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage));

            if (!String.IsNullOrEmpty(fileName))
            {
                Clipboard.SetDataObject(fileName, true, ConstantUtil.clipboardRetryTimes, ConstantUtil.clipboardRetryDelay);
            }
        }
Esempio n. 8
0
        internal static void OpenFileFolder(Form1 form)
        {
            String           fileName         = ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage);
            ProcessStartInfo processStartInfo = new ProcessStartInfo("explorer.exe")
            {
                Arguments = String.Format("/select, {0}", fileName)
            };

            OtherManager.StartProcessInfo(form, processStartInfo);
        }
Esempio n. 9
0
        internal static void TabSelection(Form1 form)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage).Select();
            form.Text = String.Format("DtPad - {0}", pagesTabControl.SelectedTabPage.Text);

            bool enabled = !String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage));

            ToggleTabFileTools(form, enabled);
            ReadInsertMode(form);
        }
Esempio n. 10
0
        internal static bool Validate(Form1 form, bool showMessages, ValidationType type, Encoding encoding, out String error)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            error = String.Empty;

            Encoding fileEncoding = encoding ?? TabUtil.GetTabTextEncoding(pagesTabControl.SelectedTabPage);
            String   text         = pageTextBox.Text; //FormatManager.EncodeHTMLTagsForXMLValidation(pageTextBox.Text);

            byte[]       byteArray     = fileEncoding.GetBytes(text);
            MemoryStream contentStream = new MemoryStream(byteArray);

            XmlReaderSettings settings = new XmlReaderSettings
            {
                ValidationType = type,
                IgnoreComments = true,
                DtdProcessing  = DtdProcessing.Parse                                 //ProhibitDtd = false
            };

            String    filename = ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage);
            XmlReader reader   = !String.IsNullOrEmpty(filename) ? XmlReader.Create(contentStream, settings, filename) : XmlReader.Create(contentStream, settings);

            try
            {
                while (reader.Read())
                {
                }
            }
            catch (Exception exception)
            {
                error = String.Format(LanguageUtil.GetCurrentLanguageString("Error", className), exception.Message);
                if (showMessages)
                {
                    WindowManager.ShowAlertBox(form, error);
                }
                return(false);
            }
            finally
            {
                contentStream.Dispose();
                reader.Close();
            }

            if (showMessages)
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("Success", className));
            }
            return(true);
        }
Esempio n. 11
0
        internal static void SelectTabByOpenedFileName(Form1 form, String fileName)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            foreach (XtraTabPage tabPage in pagesTabControl.TabPages)
            {
                if (ProgramUtil.GetFilenameTabPage(tabPage) != fileName)
                {
                    continue;
                }

                pagesTabControl.SelectedTabPage = tabPage;
                return;
            }
        }
Esempio n. 12
0
        internal static void ReloadFile(Form1 form, int tabIdentity)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            if (pagesTabControl.SelectedTabPage.Text.StartsWith("*"))
            {
                if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("Reload", className)) != DialogResult.Yes)
                {
                    return;
                }
            }

            String[] filenames = new[] { ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage) };
            TabManager.ResetTab(form);
            OpenFile(form, tabIdentity, filenames);
        }
Esempio n. 13
0
        internal static void OpenFileFolderPrompt(Form1 form)
        {
            String fileName     = ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage);
            String workingDrive = Path.GetPathRoot(Path.GetDirectoryName(fileName));

            if (String.IsNullOrEmpty(workingDrive))
            {
                workingDrive = @"C:\";
            }

            ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe")
            {
                WorkingDirectory = workingDrive,
                Arguments        = String.Format("/k \"cd {0}", Path.GetDirectoryName(fileName))
            };

            OtherManager.StartProcessInfo(form, processStartInfo);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        internal static void ToggleReadonly(Form1 form)
        {
            XtraTabControl       pagesTabControl      = form.pagesTabControl;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

            String   fileName = ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage);
            FileInfo fileInfo = new FileInfo(fileName);

            if (fileInfo.IsReadOnly && fileInfo.Exists)
            {
                File.SetAttributes(fileName, FileAttributes.Normal);
                toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("ReadonlyNo", className), Path.GetFileName(fileName));
            }
            else if (!fileInfo.IsReadOnly && fileInfo.Exists)
            {
                File.SetAttributes(fileName, FileAttributes.ReadOnly);
                toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("ReadonlyYes", className), Path.GetFileName(fileName));
            }
            else
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoFileToReadonly", className));
            }

            switch (pagesTabControl.SelectedTabPage.ImageIndex)
            {
            case 0:
                pagesTabControl.SelectedTabPage.ImageIndex = 2;
                break;

            case 1:
                pagesTabControl.SelectedTabPage.ImageIndex = 3;
                break;

            case 2:
                pagesTabControl.SelectedTabPage.ImageIndex = 0;
                break;

            case 3:
                pagesTabControl.SelectedTabPage.ImageIndex = 1;
                break;
            }
        }
Esempio n. 16
0
        internal static void ResetTab(Form1 form)
        {
            XtraTabControl    pagesTabControl   = form.pagesTabControl;
            CustomRichTextBox pageTextBox       = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(pagesTabControl.SelectedTabPage);

            if (ColumnRulerManager.IsPanelOpen(form))
            {
                ColumnRulerManager.TogglePanel(form);
            }

            String newTabTitle = LanguageUtil.GetCurrentLanguageString("tabPage1", form.Name);

            SetTabColor(pagesTabControl.SelectedTabPage, Color.Black); //pagesTabControl.SelectedTabPage.Appearance.Header.ForeColor = Color.Black;
            pagesTabControl.SelectedTabPage.Appearance.Header.Reset();
            pageTextBox.Text = String.Empty;
            pagesTabControl.SelectedTabPage.ImageIndex = 0;
            pagesTabControl.SelectedTabPage.Text       = newTabTitle;
            pagesTabControl.SelectedTabPage.Tooltip    = newTabTitle;
            form.Text = String.Format("DtPad - {0}", newTabTitle);
            ProgramUtil.SetFilenameTabPage(pagesTabControl.SelectedTabPage, String.Empty);
            pageTextBox.CustomZoom           = 100;
            pageTextBox.CustomModified       = false;
            pageTextBox.CustomOriginal       = String.Empty.GetHashCode().ToString();
            pageTextBox.CustomEncoding       = String.Empty;
            pageTextBox.CustomEncodingForced = false;
            customLineNumbers.Width          = customLineNumbers.MinimumSize.Width;
            ZoomSelect(form, 100);
            pageTextBox.ClearUndo();

            TextManager.RefreshUndoRedoExternal(form);

            if (String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)))
            {
                ToggleTabFileTools(form, false);
            }
            OtherManager.FocusOnEditor(form);
        }
Esempio n. 17
0
        internal static void CloseSession(Form1 form)
        {
            ToolStrip sessionToolStrip = form.sessionToolStrip;
            ToolStripDropDownButton sessionImageToolStripButton  = form.sessionImageToolStripButton;
            ToolStripButton         sessionToolStripButton       = form.sessionToolStripButton;
            ToolStripMenuItem       closeToolStripMenuItem3      = form.closeToolStripMenuItem3;
            ToolStripMenuItem       saveToolStripMenuItem2       = form.saveToolStripMenuItem2;
            ToolStripMenuItem       exportAsZipToolStripMenuItem = form.exportAsZipToolStripMenuItem;
            ToolStripStatusLabel    toolStripStatusLabel         = form.toolStripStatusLabel;
            //SplitContainer verticalSplitContainer = form.verticalSplitContainer;
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            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;

            if (CheckSessionOnClosing(form, true) == DialogResult.Cancel)
            {
                return;
            }

            for (int i = startPositionToReadSessionFiles; i < sessionImageToolStripButton.DropDownItems.Count; i++)
            {
                foreach (XtraTabPage tabPage in pagesTabControl.TabPages)
                {
                    if (ProgramUtil.GetFilenameTabPage(tabPage) != sessionImageToolStripButton.DropDownItems[i].Text)
                    {
                        continue;
                    }

                    pagesTabControl.SelectedTabPage = tabPage;
                    TabManager.ClosePage(form);
                    break;
                }
            }

            sessionImageToolStripButton.DropDownItems.Clear();
            sessionToolStrip.Visible                   = false;
            closeToolStripMenuItem3.Enabled            = false;
            saveToolStripMenuItem2.Enabled             = false;
            exportAsZipToolStripMenuItem.Enabled       = false;
            renameSessionToolStripMenuItem.Enabled     = false;
            favouriteSessionToolStripMenuItem.Enabled  = false;
            listFilesToolStripMenuItem.Enabled         = false;
            aspectToolStripMenuItem.Enabled            = false;
            sessionPropertiesToolStripMenuItem.Enabled = false;

            if (!useDefaultToolStripMenuItem.Checked)
            {
                OptionManager.CheckTabCloseButton(form, ConfigUtil.GetIntParameter("TabCloseButtonMode"));
                OptionManager.CheckTabPosition(form, ConfigUtil.GetIntParameter("TabPosition"));
                OptionManager.CheckTabOrientation(form, ConfigUtil.GetIntParameter("TabOrientation"));
            }

            useDefaultToolStripMenuItem.Enabled     = false;
            closeButtonToolStripMenuItem.Enabled    = false;
            tabPositionToolStripMenuItem.Enabled    = false;
            tabOrientationToolStripMenuItem.Enabled = false;

            //verticalSplitContainer.Panel1.Padding = new Padding(3, 0, 0, 0);
            toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("Closed", className), sessionToolStripButton.Text);
        }
Esempio n. 18
0
        private static String ReadSessionXML(Form1 form, String fileName, out bool loadTotallyFailed)
        {
            CustomXtraTabControl    pagesTabControl                 = form.pagesTabControl;
            ToolStripDropDownButton sessionImageToolStripButton     = form.sessionImageToolStripButton;
            ToolStripMenuItem       useDefaultToolStripMenuItem     = form.useDefaultToolStripMenuItem;
            ToolStripMenuItem       closeButtonToolStripMenuItem    = form.closeButtonToolStripMenuItem;
            ToolStripMenuItem       tabPositionToolStripMenuItem    = form.tabPositionToolStripMenuItem;
            ToolStripMenuItem       tabOrientationToolStripMenuItem = form.tabOrientationToolStripMenuItem;

            loadTotallyFailed = false;
            int selectedTab  = 0;
            int existingTabs = 0;

            if (pagesTabControl.TabPages.Count > 1 || !String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(pagesTabControl.TabPages[0]).Text) || !String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.TabPages[0])))
            {
                existingTabs = pagesTabControl.TabPages.Count;
            }

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

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(fileName);

            XmlNodeList nodeFileList = xmldoc.GetElementsByTagName("file");

            if (nodeFileList.Count == 0)
            {
                throw new SessionException(LanguageUtil.GetCurrentLanguageString("Empty", className));
            }

            String[]     fileNames = new String[nodeFileList.Count];
            KnownColor[] tabColors = new KnownColor[nodeFileList.Count];
            for (int i = 0; i < nodeFileList.Count; i++)
            {
                XmlNode nodeFile = nodeFileList[i];

                String path = nodeFile.Attributes["path"].Value;
                path = FileUtil.EvaluateAbsolutePath(Path.GetDirectoryName(fileName), path);

                fileNames[i] = Path.Combine(path, nodeFile.Attributes["name"].Value);
                sessionImageToolStripButton.DropDownItems.Add(fileNames[i]);
                sessionImageToolStripButton.DropDownItems[sessionImageToolStripButton.DropDownItems.Count - 1].Click += form.sessionImageToolStripButton_Click;

                if (!File.Exists(fileNames[i]))
                {
                    sessionImageToolStripButton.DropDownItems[sessionImageToolStripButton.DropDownItems.Count - 1].Enabled = false;
                }

                try
                {
                    if (Convert.ToBoolean(nodeFile.Attributes["open"].Value))
                    {
                        selectedTab = i;
                    }
                }
                catch (Exception)
                {
                }

                try
                {
                    tabColors[i] = (KnownColor)Enum.Parse(typeof(KnownColor), nodeFile.Attributes["tabcolor"].Value, true);
                }
                catch (Exception)
                {
                    tabColors[i] = KnownColor.Black;
                }
            }

            List <String> errors;

            form.TabIdentity = FileManager.OpenFile(form, form.TabIdentity, fileNames, false, false, out errors);

            if (errors.Count == 0)
            {
                pagesTabControl.SelectedTabPageIndex = selectedTab;

                for (int j = 0; j < pagesTabControl.TabPages.Count - existingTabs; j++)
                {
                    TabManager.SetTabColor(pagesTabControl.TabPages[j + existingTabs], Color.FromKnownColor(tabColors[j])); //pagesTabControl.TabPages[j].Appearance.Header.ForeColor = Color.FromKnownColor(tabColors[j]);
                }
            }
            else
            {
                String errorMessage = LanguageUtil.GetCurrentLanguageString("openingErrors", className) + Environment.NewLine;
                for (int i = 0; i < errors.Count; i++)
                {
                    if (i == errors.Count - 1)
                    {
                        errorMessage += errors[i];
                        continue;
                    }

                    errorMessage += errors[i] + Environment.NewLine;
                }

                WindowManager.ShowContent(form, errorMessage);

                if (errors.Count == fileNames.Length)
                {
                    loadTotallyFailed = true;
                }
            }

            if (xmldoc.GetElementsByTagName("session")[0].Attributes["aspect"].Value == "default")
            {
                useDefaultToolStripMenuItem.Checked = true;
            }
            else
            {
                useDefaultToolStripMenuItem.Checked = false;

                CheckDropDownIndex(closeButtonToolStripMenuItem, Convert.ToInt32(xmldoc.GetElementsByTagName("session")[0].Attributes["button"].Value));
                CheckDropDownIndex(tabPositionToolStripMenuItem, Convert.ToInt32(xmldoc.GetElementsByTagName("session")[0].Attributes["position"].Value));
                CheckDropDownIndex(tabOrientationToolStripMenuItem, Convert.ToInt32(xmldoc.GetElementsByTagName("session")[0].Attributes["orientation"].Value));
            }

            return(xmldoc.GetElementsByTagName("session")[0].Attributes["name"].Value);
        }
Esempio n. 19
0
        internal static bool AreAllTabsEmptyAndWithoutFiles(Form1 form)
        {
            CustomXtraTabControl pagesTabControl = form.pagesTabControl;

            foreach (XtraTabPage tabPage in pagesTabControl.TabPages)
            {
                if (!String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(tabPage).Text) || !String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(tabPage)))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 20
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);
        }
Esempio n. 21
0
        internal static bool SaveAllFilesAsZip(Form1 form)
        {
            SaveFileDialog       saveFileDialog       = form.saveFileDialog;
            CustomXtraTabControl pagesTabControl      = form.pagesTabControl;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;
            ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar;

            if (TabManager.AreAllTabsEmptyAndWithoutFiles(form))
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoContent", className));
                return(false);
            }

            //Save all files before to proceed
            foreach (XtraTabPage tabPage in pagesTabControl.TabPages)
            {
                if (!String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(tabPage)) && !tabPage.Text.StartsWith("*"))
                {
                    continue;
                }

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

                if (!FileManager.SaveAllFiles(form))
                {
                    WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("FilesNotSaved", className));
                    return(false);
                }

                break;
            }

            toolStripProgressBar.Value   = 0;
            toolStripProgressBar.Visible = true;
            toolStripProgressBar.PerformStep();

            //Save file dialog
            saveFileDialog.InitialDirectory = FileUtil.GetInitialFolder(form);
            saveFileDialog.Filter           = LanguageUtil.GetCurrentLanguageString("FileDialog", className);
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.FileName         = "*.zip";

            try
            {
                if (saveFileDialog.ShowDialog() != DialogResult.OK)
                {
                    toolStripProgressBar.Visible = false;
                    return(false);
                }

                toolStripProgressBar.PerformStep();
                String fileName = saveFileDialog.FileName;
                if (!fileName.EndsWith(".zip"))
                {
                    fileName += ".zip";
                }

                toolStripProgressBar.PerformStep();
                WriteZipFile(fileName, pagesTabControl.TabPages);

                toolStripProgressBar.PerformStep();
                toolStripStatusLabel.Text = String.Format(LanguageUtil.GetCurrentLanguageString("Saved", className), fileName);
            }
            catch (Exception exception)
            {
                WindowManager.ShowErrorBox(form, exception.Message, exception);
                return(false);
            }
            finally
            {
                toolStripProgressBar.Visible = false;
            }

            return(true);
        }
Esempio n. 22
0
 internal static void CopyFullPath(Form1 form)
 {
     Clipboard.SetDataObject(ProgramUtil.GetFilenameTabPage(form.pagesTabControl.SelectedTabPage), true, ConstantUtil.clipboardRetryTimes, ConstantUtil.clipboardRetryDelay);
 }
Esempio n. 23
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);
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        private static bool ClosePage(Form1 form, bool showMessages, bool moreTabs, out bool closeAll)
        {
            XtraTabControl pagesTabControl = form.pagesTabControl;

            closeAll = false;

            if (showMessages && TabUtil.IsTabPageModified(pagesTabControl.SelectedTabPage))
            {
                if (moreTabs)
                {
                    DialogResult dialogResult = WindowManager.ShowQuestionCancelNoAllBox(form, LanguageUtil.GetCurrentLanguageString("SaveUntitled", className));

                    if ((dialogResult == DialogResult.Cancel) || (dialogResult == DialogResult.Yes && !FileManager.SaveFile(form, false)))
                    {
                        return(false);
                    }
                    if (dialogResult == DialogResult.Retry)
                    {
                        closeAll = true;
                    }
                }
                else
                {
                    DialogResult dialogResult = WindowManager.ShowQuestionCancelBox(form, LanguageUtil.GetCurrentLanguageString("SaveUntitled", className));

                    if ((dialogResult == DialogResult.Cancel) || (dialogResult == DialogResult.Yes && !FileManager.SaveFile(form, false)))
                    {
                        return(false);
                    }
                }
            }
            else if (!showMessages)
            {
                closeAll = true;
            }

            CustomPanel sectionsPanel   = ProgramUtil.GetSectionsPanel(pagesTabControl.SelectedTabPage);
            CustomPanel annotationPanel = ProgramUtil.GetAnnotationPanel(pagesTabControl.SelectedTabPage);

            if (sectionsPanel != null)
            {
                pagesTabControl.SelectedTabPage.Controls.Remove(sectionsPanel);
            }
            if (annotationPanel != null)
            {
                pagesTabControl.SelectedTabPage.Controls.Remove(annotationPanel);
            }

            if (pagesTabControl.TabPages.Count > 1)
            {
                String selectedTabName  = pagesTabControl.SelectedTabPage.Name;
                int    selectedTabIndex = pagesTabControl.SelectedTabPageIndex;

                pagesTabControl.TabPages.Remove(pagesTabControl.SelectedTabPage);
                ExplorerManager.RemoveNodeToTabExplorer(form, selectedTabName);

                pagesTabControl.SelectedTabPage = selectedTabIndex < pagesTabControl.TabPages.Count ? pagesTabControl.TabPages[selectedTabIndex] : pagesTabControl.TabPages[pagesTabControl.TabPages.Count - 1];

                if (String.IsNullOrEmpty(ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage)))
                {
                    ToggleTabFileTools(form, false);
                }
                OtherManager.FocusOnEditor(form);
            }
            else
            {
                ResetTab(form);
            }

            return(true);
        }
Esempio n. 26
0
        internal static bool SaveAsPdf(Form1 form)
        {
            XtraTabControl       pagesTabControl      = form.pagesTabControl;
            CustomRichTextBox    pageTextBox          = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            SaveFileDialog       saveFileDialog       = form.saveFileDialog;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;
            ToolStripProgressBar toolStripProgressBar = form.toolStripProgressBar;

            if (String.IsNullOrEmpty(pageTextBox.Text))
            {
                WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("NoTextForPDF", className));
                return(false);
            }

            try
            {
                saveFileDialog.InitialDirectory = FileUtil.GetInitialFolder(form);
                saveFileDialog.Filter           = LanguageUtil.GetCurrentLanguageString("PDFFile", className); //"PDF document (*.pdf)|*.pdf";
                saveFileDialog.FilterIndex      = 0;

                String filenameTabPage = ProgramUtil.GetFilenameTabPage(pagesTabControl.SelectedTabPage);
                if (String.IsNullOrEmpty(filenameTabPage))
                {
                    saveFileDialog.FileName = "*.pdf";
                }
                else if (filenameTabPage.Contains("."))
                {
                    saveFileDialog.FileName = filenameTabPage.Substring(0, filenameTabPage.LastIndexOf('.')) + ".pdf";
                }
                else
                {
                    saveFileDialog.FileName = filenameTabPage + ".pdf";
                }

                if (saveFileDialog.ShowDialog() != DialogResult.OK)
                {
                    toolStripProgressBar.Visible = false;
                    return(false);
                }

                Application.DoEvents();
                toolStripProgressBar.Value   = 0;
                toolStripProgressBar.Visible = true;

                String fileName = saveFileDialog.FileName;
                toolStripProgressBar.PerformStep();

                ConfigUtil.UpdateParameter("LastUserFolder", Path.GetDirectoryName(fileName));
                FileInfo fileInfo = new FileInfo(fileName);
                if (fileInfo.IsReadOnly && fileInfo.Exists)
                {
                    toolStripProgressBar.Visible = false;
                    WindowManager.ShowInfoBox(form, LanguageUtil.GetCurrentLanguageString("SavingReadonly", className));
                    return(SaveAsPdf(form));
                }

                toolStripProgressBar.PerformStep();
                String fileTitle = fileName.Substring(0, fileName.LastIndexOf(".pdf"));

                //Document document = new Document();
                //FileStream fileStream = File.Create(fileName);
                //PdfWriter.GetInstance(document, fileStream);

                //document.Open();
                //document.AddTitle(fileTitle);
                //document.AddCreationDate();
                //document.AddCreator("DtPad " + AssemblyUtil.AssemblyVersion);
                //document.Add(new Paragraph(pageTextBox.Text));

                //if (document.IsOpen())
                //{
                //    document.CloseDocument();
                //}
                //fileStream.Dispose();
                PdfUtil.SaveText(fileName, fileTitle, pageTextBox.Text);

                toolStripProgressBar.PerformStep();
                toolStripStatusLabel.Text = String.Format("{0} \"{1}\" {2}", LanguageUtil.GetCurrentLanguageString("File", className), Path.GetFileName(fileName), LanguageUtil.GetCurrentLanguageString("Saved", className));

                toolStripProgressBar.PerformStep();
                toolStripProgressBar.Visible = false;

                OtherManager.StartProcess(form, fileName);
                saveFileDialog.FileName = "*.txt";
                return(true);
            }
            catch (Exception exception)
            {
                toolStripProgressBar.Visible = false;
                saveFileDialog.FileName      = "*.txt";
                WindowManager.ShowErrorBox(form, exception.Message, exception);
                return(false);
            }
        }
Esempio n. 27
0
        private static bool IsOpenedSessionModified(Form1 form)
        {
            ToolStripDropDownButton sessionImageToolStripButton = form.sessionImageToolStripButton;
            XtraTabControl          pagesTabControl             = form.pagesTabControl;

            //First control: session files are opened?
            for (int i = startPositionToReadSessionFiles; i < sessionImageToolStripButton.DropDownItems.Count; i++)
            {
                XtraTabPage tabPage;
                if (FileUtil.IsFileAlreadyOpen(form, sessionImageToolStripButton.DropDownItems[i].Text, out tabPage))
                {
                    continue;
                }

                return(true);
            }

            //Second control: opened files are saved into session?
            for (int i = 0; i < pagesTabControl.TabPages.Count; i++)
            {
                if (String.IsNullOrEmpty(ProgramUtil.GetPageTextBox(pagesTabControl.TabPages[i]).Text) || IsFileAlreadyInSession(form, ProgramUtil.GetFilenameTabPage(pagesTabControl.TabPages[i])))
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }