public frmFind(Control owner, SyntaxEditor editor, FindReplaceOptions options, bool OnlyFiles, string SearchStr) { // // Required for Windows Form Designer support // InitializeComponent(); RehashRecent(); // // Add any constructor code after InitializeComponent call // this.owner = owner; this.editor = editor; this.options = options; // Set the form owner this.Owner = g.Main; // Clear the status //owner.SetStatusMessage("Ready"); // Select the first search type searchTypeDropDownList.SelectedIndex = 0; // Update options findTextBox.Text = options.FindText; matchCaseCheckBox.Checked = options.MatchCase; matchWholeWordCheckBox.Checked = options.MatchWholeWord; searchUpCheckBox.Checked = options.SearchUp; searchHiddenTextCheckBox.Checked = options.SearchHiddenText; searchInSelectionCheckBox.Checked = options.SearchInSelection; searchTypeCheckBox.Checked = (options.SearchType != FindReplaceSearchType.Normal); searchTypeDropDownList.SelectedIndex = (options.SearchType != FindReplaceSearchType.Wildcard ? 0 : 1); this.findTextBox.Text = SearchStr; if (OnlyFiles) { this.optAllFiles.Enabled = false; this.optCurFile.Enabled = false; this.optEntireProject.Checked = true; this.optSelection.Enabled = false; this.markAllButton.Enabled = false; this.Text = "Find in Project"; this.markWithCheckBox.Enabled = false; this.markWithCheckBox.Checked = false; this.searchUpCheckBox.Enabled = false; this.searchHiddenTextCheckBox.Enabled = false; this.bOnlyFiles = OnlyFiles; } }
public static void InsertDocumentAtReplace(string dataDir) { // ExStart:InsertDocumentAtReplace Document mainDoc = new Document(dataDir + "InsertDocument1.doc"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new InsertDocumentAtReplaceHandler(); mainDoc.Range.Replace(new Regex("\\[MY_DOCUMENT\\]"),"" , options); dataDir = dataDir + "InsertDocumentAtReplace_out.doc"; mainDoc.Save(dataDir); // ExEnd:InsertDocumentAtReplace Console.WriteLine("\nDocument inserted successfully at a replace.\nFile saved at " + dataDir); }
// ExStart:ReplaceWithHtml public static void ReplaceWithHtml(string dataDir) { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello <CustomerName>,"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new ReplaceWithHtmlEvaluator(options); doc.Range.Replace(new Regex(@" <CustomerName>,"), String.Empty, options); // Save the modified document. doc.Save(dataDir + "Range.ReplaceWithInsertHtml.doc"); }
public static void Run() { // ExStart:DocumentBuilderInsertTCFieldsAtText Document doc = new Document(); FindReplaceOptions options = new FindReplaceOptions(); // Highlight newly inserted content. options.ApplyFont.HighlightColor = Color.DarkOrange; options.ReplacingCallback = new InsertTCFieldHandler("Chapter 1", "\\l 1"); // Insert a TC field which displays "Chapter 1" just before the text "The Beginning" in the document. doc.Range.Replace(new Regex("The Beginning"), "", options); // ExEnd:DocumentBuilderInsertTCFieldsAtText }
public void ReplaceNumbersAsHex() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Font.Name = "Arial"; builder.Write("There are few numbers that should be converted to HEX and highlighted: 123, 456, 789 and 17379."); FindReplaceOptions options = new FindReplaceOptions(); // Highlight newly inserted content. options.ApplyFont.HighlightColor = Color.DarkOrange; options.ReplacingCallback = new NumberHexer(); int count = doc.Range.Replace(new Regex("[0-9]+"), "", options); }
public void IgnoreFootnote(bool isIgnoreFootnotes) { //ExStart //ExFor:FindReplaceOptions.IgnoreFootnotes //ExSummary:Shows how to ignore footnotes during a find-and-replace operation. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); builder.InsertFootnote(FootnoteType.Footnote, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); builder.InsertParagraph(); builder.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); builder.InsertFootnote(FootnoteType.Endnote, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); // Set the "IgnoreFootnotes" flag to "true" to get the find-and-replace // operation to ignore text inside footnotes. // Set the "IgnoreFootnotes" flag to "false" to get the find-and-replace // operation to also search for text inside footnotes. FindReplaceOptions options = new FindReplaceOptions { IgnoreFootnotes = isIgnoreFootnotes }; doc.Range.Replace("Lorem ipsum", "Replaced Lorem ipsum", options); //ExEnd ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs; foreach (Paragraph para in paragraphs) { Assert.AreEqual("Replaced Lorem ipsum", para.Runs[0].Text); } List <Footnote> footnotes = doc.GetChildNodes(NodeType.Footnote, true).Cast <Footnote>().ToList(); Assert.AreEqual( isIgnoreFootnotes ? "Lorem ipsum dolor sit amet, consectetur adipiscing elit." : "Replaced Lorem ipsum dolor sit amet, consectetur adipiscing elit.", footnotes[0].ToString(SaveFormat.Text).Trim()); Assert.AreEqual( isIgnoreFootnotes ? "Lorem ipsum dolor sit amet, consectetur adipiscing elit." : "Replaced Lorem ipsum dolor sit amet, consectetur adipiscing elit.", footnotes[1].ToString(SaveFormat.Text).Trim()); }
private void ProcessMarkdown() { var docPath = "C:\\temp\\aspose\\"; var fileToLoad = "snippet.md"; var doc = new Document(Path.Combine(docPath, fileToLoad)); var options = new FindReplaceOptions(); //options.ApplyFont.Bold = false; options.ApplyFont.Italic = true; _ = doc.Range.Replace("demonstration", "code demonstration", options); var paragraph0 = CreateParagraph(doc, StyleNames.Heading1); _ = paragraph0.AppendChild(CreateRun(doc, "This is a Heading 1")); var paragraph1 = CreateParagraph(doc); _ = paragraph1.AppendChild(CreateRun(doc, "This is some bold text", true)); var paragraph2 = CreateParagraph(doc, StyleNames.Heading2); _ = paragraph2.AppendChild(CreateRun(doc, "This is a Heading 2")); var paragraph3 = CreateParagraph(doc); _ = paragraph3.AppendChild(CreateRun(doc, "This is some Italic text", false, true)); var paragraph4 = CreateParagraph(doc, StyleNames.Quote); _ = paragraph4.AppendChild(CreateRun(doc, "This is a quote or something profound")); _ = doc.Save(Path.Combine(docPath, "snippetModified.md"), SaveFormat.Markdown); //doc.Protect(ProtectionType.ReadOnly, "password"); //_ = doc.Save(Path.Combine(docPath, "snippetModified.docx"), SaveFormat.Docx); //doc.Print("Foxit Reader PDF Printer"); }
/// <summary> /// Constructor</summary> public SyntaxEditorControl() { // Uncomment the next line and use something like // CodeEditor to open a document and see these results. //PerformAndShowAuditStuff(); var doc = new Document { LineModificationMarkingEnabled = true }; doc.Outlining.Mode = OutliningMode.Automatic; Location = new Point(0, 0); Name = "editor"; base.AllowDrop = false; Document = doc; DefaultContextMenuEnabled = true; IntelliPrompt.DropShadowEnabled = true; IntelliPrompt.SmartTag.ClearOnDocumentModification = true; IntelliPrompt.SmartTag.MultipleSmartTagsEnabled = false; LineNumberMarginVisible = true; IndentType = IndentType.Smart; BracketHighlightingVisible = true; SplitType = SyntaxEditorSplitType.FourWay; DocumentIndicatorRemoved += EditorDocumentIndicatorRemoved; SmartIndent += EditorSmartIndent; DocumentSyntaxLanguageLoaded += EditorDocumentSyntaxLanguageLoaded; DocumentIndicatorAdded += EditorDocumentIndicatorAdded; KeyTyping += EditorKeyTyping; ViewMouseHover += EditorViewMouseHover; DocumentTextChanged += EditorDocumentTextChanged; ContextMenuRequested += EditorContextMenuRequested; PasteDragDrop += EditorPasteDragDrop; TriggerActivated += EditorTriggerActivated; ViewMouseDown += EditorViewMouseDown; base.SelectionChanged += SyntaxEditorControlSelectionChanged; m_findReplaceOptions = new FindReplaceOptions(); m_findReplaceForm = new FindReplaceForm(this, m_findReplaceOptions); if (s_imgList == null) s_imgList = ReflectionImageList; // Added by PJO KeyUp += SyntaxEditorControlKeyUp; MouseUp += SyntaxEditorControlMouseUp; Renderer = new VisualStudio2005SyntaxEditorRenderer(); }
static void Main(string[] args) { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); FindReplaceOptions options = new FindReplaceOptions { MatchCase = false, FindWholeWordsOnly = true }; doc.Range.Replace("Hello world!", "Greetings planet!", options); doc.Save("Search for and Replace text.docx"); }
public static void Run() { // ExStart:ReplaceWithRegex // The path to the documents directory. string dataDir = RunExamples.GetDataDir_FindAndReplace(); Document doc = new Document(dataDir + "Document.doc"); FindReplaceOptions options = new FindReplaceOptions(); doc.Range.Replace(new Regex("[s|m]ad"), "bad", options); dataDir = dataDir + "ReplaceWithRegex_out.doc"; doc.Save(dataDir); // ExEnd:ReplaceWithRegex Console.WriteLine("\nText replaced with regex successfully.\nFile saved at " + dataDir); }
public void FindAndReplaceWithPreserveMetaCharacters() { //ExStart //ExFor:FindReplaceOptions.PreserveMetaCharacters //ExSummary:Shows how to preserved meta-characters that beginning with "&". Document doc = new Document(MyDir + "Range.FindAndReplaceWithPreserveMetaCharacters.docx"); FindReplaceOptions options = new FindReplaceOptions(); options.FindWholeWordsOnly = true; options.PreserveMetaCharacters = true; doc.Range.Replace("sad", "“ some text ”", options); //ExEnd doc.Save(ArtifactsDir + "Range.FindAndReplaceWithMetacharacters.docx"); }
public static void Run() { // ExStart:ReplaceWithEvaluator // The path to the documents directory. string dataDir = RunExamples.GetDataDir_FindAndReplace(); Document doc = new Document(dataDir + "Range.ReplaceWithEvaluator.doc"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new MyReplaceEvaluator(); doc.Range.Replace(new Regex("[s|m]ad"), "", options); dataDir = dataDir + "Range.ReplaceWithEvaluator_out.doc"; doc.Save(dataDir); // ExEnd:ReplaceWithEvaluator Console.WriteLine("\nText replaced successfully with evaluator.\nFile saved at " + dataDir); }
public void ReplaceWithString() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("This one is sad."); builder.Writeln("That one is mad."); FindReplaceOptions options = new FindReplaceOptions(); options.MatchCase = false; options.FindWholeWordsOnly = true; doc.Range.Replace("sad", "bad", options); doc.Save(ArtifactsDir + "Range.ReplaceWithString.docx"); }
public void ReplaceWithEvaluator() { //ExStart:ReplaceWithEvaluator Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("sad mad bad"); FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = new MyReplaceEvaluator() }; doc.Range.Replace(new Regex("[s|m]ad"), "", options); doc.Save(ArtifactsDir + "FindAndReplace.ReplaceWithEvaluator.docx"); //ExEnd:ReplaceWithEvaluator }
public void RecognizeAndSubstitutionsWithinReplacementPatterns() { //ExStart:RecognizeAndSubstitutionsWithinReplacementPatterns Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Jason give money to Paul."); Regex regex = new Regex(@"([A-z]+) give money to ([A-z]+)"); FindReplaceOptions options = new FindReplaceOptions { UseSubstitutions = true }; doc.Range.Replace(regex, @"$2 take money from $1", options); //ExEnd:RecognizeAndSubstitutionsWithinReplacementPatterns }
public void ReplaceTextInFooter() { //ExStart:ReplaceTextInFooter Document doc = new Document(MyDir + "Footer.docx"); HeaderFooterCollection headersFooters = doc.FirstSection.HeadersFooters; HeaderFooter footer = headersFooters[HeaderFooterType.FooterPrimary]; FindReplaceOptions options = new FindReplaceOptions { MatchCase = false, FindWholeWordsOnly = false }; footer.Range.Replace("(C) 2006 Aspose Pty Ltd.", "Copyright (C) 2020 by Aspose Pty Ltd.", options); doc.Save(ArtifactsDir + "FindAndReplace.ReplaceTextInFooter.docx"); //ExEnd:ReplaceTextInFooter }
public void FindAndHighlight() { //ExStart:FindAndHighlight Document doc = new Document(MyDir + "Find and highlight.docx"); FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = new ReplaceEvaluatorFindAndHighlight(), Direction = FindReplaceDirection.Backward }; Regex regex = new Regex("your document", RegexOptions.IgnoreCase); doc.Range.Replace(regex, "", options); doc.Save(ArtifactsDir + "FindAndReplace.FindAndHighlight.docx"); //ExEnd:FindAndHighlight }
public void InsertDocumentAtReplace() { //ExStart:InsertDocumentAtReplace Document mainDoc = new Document(MyDir + "Document insertion 1.docx"); // Set find and replace options. FindReplaceOptions options = new FindReplaceOptions { Direction = FindReplaceDirection.Backward, ReplacingCallback = new InsertDocumentAtReplaceHandler() }; // Call the replace method. mainDoc.Range.Replace(new Regex("\\[MY_DOCUMENT\\]"), "", options); mainDoc.Save(ArtifactsDir + "CloneAndCombineDocuments.InsertDocumentAtReplace.docx"); //ExEnd:InsertDocumentAtReplace }
public void ReplaceHtmlTextWithMetaCharacters() { //ExStart:ReplaceHtmlTextWithMetaCharacters Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("{PLACEHOLDER}"); FindReplaceOptions findReplaceOptions = new FindReplaceOptions { ReplacingCallback = new FindAndInsertHtml() }; doc.Range.Replace("{PLACEHOLDER}", "<p>“Some Text”</p>", findReplaceOptions); doc.Save(ArtifactsDir + "FindAndReplace.ReplaceHtmlTextWithMetaCharacters.docx"); //ExEnd:ReplaceHtmlTextWithMetaCharacters }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <c>FindReplaceForm</c> class. /// </summary> /// <param name="syntaxEditor">The <see cref="SyntaxEditor"/> for which to display the form.</param> /// <param name="options">The <see cref="FindReplaceOptions"/> to use.</param> public FindReplaceForm(SyntaxEditor syntaxEditor, FindReplaceOptions options) { // // Required for Windows Form Designer support // InitializeComponent(); // Ensure there are options if (options == null) { throw new ArgumentNullException("options"); } // Initalize parameters this.syntaxEditor = syntaxEditor; this.options = options; // Load text from resources //this.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_Text"); //closeButton.Text = AssemblyInfo.Instance.Resources.GetString("General_CloseButton_Text"); //findButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_FindButton_Text"); //findWhatLabel.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_FindWhatLabel_Text"); //markAllButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MarkAllButton_Text"); //markWithCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MarkWithCheckBox_Text"); //matchCaseCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MatchCaseCheckBox_Text"); //matchWholeWordCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MatchWholeWordCheckBox_Text"); //replaceButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceButton_Text"); //replaceAllButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceAllButton_Text"); //replaceWithLabel.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceWithLabel_Text"); //searchHiddenTextCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchHiddenTextCheckBox_Text"); //searchInSelectionCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchInSelectionCheckBox_Text"); //searchTypeCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeCheckBox_Text"); //this.searchTypeDropDownList.Items.AddRange(new object[] { // AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeDropDownList_Item_RegularExpressions"), // AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeDropDownList_Item_Wildcards") // }); //searchUpCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchUpCheckBox_Text"); this.searchTypeDropDownList.Items.AddRange(new object[] { "規則運算式", "萬用字元" }); // Select the first search type searchTypeDropDownList.SelectedIndex = 0; // Update options this.UpdateUIFromFindReplaceOptions(); }
public void ReplaceWithRegex() { //ExStart //ExFor:Range.Replace(Regex, String, FindReplaceOptions) //ExSummary:Shows how to replace all occurrences of words "sad" or "mad" to "bad". Document doc = new Document(MyDir + "Document.doc"); FindReplaceOptions options = new FindReplaceOptions(); options.MatchCase = false; options.FindWholeWordsOnly = false; doc.Range.Replace(new Regex("[s|m]ad"), "bad", options); //ExEnd doc.Save(ArtifactsDir + "ReplaceWithRegex.docx"); }
public static void Run() { //ExStart:ReplaceWithRegex // The path to the documents directory. string dataDir = RunExamples.GetDataDir_FindAndReplace(); Document doc = new Document(dataDir + "Document.doc"); FindReplaceOptions options = new FindReplaceOptions(); doc.Range.Replace(new Regex("[s|m]ad"), "bad", options); dataDir = dataDir + "ReplaceWithRegex_out_.doc"; doc.Save(dataDir); //ExEnd:ReplaceWithRegex Console.WriteLine("\nText replaced with regex successfully.\nFile saved at " + dataDir); }
public HttpResponseMessage Search(RequestData request) { Opts.AppName = "Viewer"; Opts.FileName = request.fileName; Opts.FolderName = request.folderName; Opts.MethodName = "Search"; try { if (Opts.FolderName.Contains("..")) { throw new Exception("Break-in attempt"); } if (string.IsNullOrEmpty(request.searchQuery)) { return(Request.CreateResponse(HttpStatusCode.OK, new int[] { })); } var doc = new Document(Opts.WorkingFileName); var lst = new HashSet <int>(); var findings = new AsposeWordsSearch.FindCallback(); var options = new FindReplaceOptions() { ReplacingCallback = findings, Direction = FindReplaceDirection.Forward, MatchCase = false }; doc.Range.Replace(new Regex(request.searchQuery, RegexOptions.IgnoreCase), "", options); var lc = new LayoutCollector(doc); foreach (var mathchedNode in findings.MatchedNodes) { foreach (var node in mathchedNode.Value.Select(x => x.MatchNode)) { var pageNumber = lc.GetStartPageIndex(node); lst.Add(pageNumber); } } return(Request.CreateResponse(HttpStatusCode.OK, lst)); } catch (Exception ex) { return(ExceptionResponse(ex)); } }
public static void ReplaceUsingPattern(string dataDir) { // ExStart:ReplaceWithEvaluator // The path to the documents directory. Document doc = new Document(dataDir + "Range.ReplaceWithEvaluator.doc"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new MyReplaceEvaluator(); doc.Range.Replace(new Regex("[s|m]ad"), "", options); dataDir = dataDir + "Range.ReplaceWithEvaluator_out.doc"; doc.Save(dataDir); // ExEnd:ReplaceWithEvaluator Console.WriteLine("\nText replaced successfully with evaluator.\nFile saved at " + dataDir); }
public void ChangeTextInATableFeature() { Document doc = new Document(MyDir + "Change text in a table.docx"); // Get the first table in the document. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); // Replace any instances of our string in the last cell of the table only. FindReplaceOptions options = new FindReplaceOptions { MatchCase = true, FindWholeWordsOnly = true }; table.Rows[1].Cells[2].Range.Replace("Mr", "test", options); doc.Save(ArtifactsDir + "Change text in a table - Aspose.Words.docx"); }
[Test] //ExSkip public void ReplaceWithInsertHtml() { // Open the document Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello <CustomerName>,"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new ReplaceWithHtmlEvaluator(); doc.Range.Replace(new Regex(@" <CustomerName>,"), string.Empty, options); // Save the modified document doc.Save(ArtifactsDir + "Range.ReplaceWithInsertHtml.docx"); Assert.AreEqual("James Bond, Hello\r\x000c", new Document(ArtifactsDir + "Range.ReplaceWithInsertHtml.docx").GetText()); //ExSkip }
public static void HighlightColor(string dataDir) { // Load a Word Docx document by creating an instance of the Document class. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello _CustomerName_,"); // ExStart:HighlightColor // Highlight word "the" with yellow color. FindReplaceOptions options = new FindReplaceOptions(); options.ApplyFont.HighlightColor = Color.Yellow; // Replace highlighted text. doc.Range.Replace("Hello", "Hello", options); // ExEnd:HighlightColor }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <c>FindReplaceForm</c> class. /// </summary> /// <param name="syntaxEditor">The <see cref="SyntaxEditor"/> for which to display the form.</param> /// <param name="options">The <see cref="FindReplaceOptions"/> to use.</param> public FindReplaceForm(SyntaxEditor syntaxEditor, FindReplaceOptions options) { // // Required for Windows Form Designer support // InitializeComponent(); // Ensure there are options if (options == null) throw new ArgumentNullException("options"); // Initalize parameters this.syntaxEditor = syntaxEditor; this.options = options; // Load text from resources //this.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_Text"); //closeButton.Text = AssemblyInfo.Instance.Resources.GetString("General_CloseButton_Text"); //findButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_FindButton_Text"); //findWhatLabel.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_FindWhatLabel_Text"); //markAllButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MarkAllButton_Text"); //markWithCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MarkWithCheckBox_Text"); //matchCaseCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MatchCaseCheckBox_Text"); //matchWholeWordCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_MatchWholeWordCheckBox_Text"); //replaceButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceButton_Text"); //replaceAllButton.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceAllButton_Text"); //replaceWithLabel.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_ReplaceWithLabel_Text"); //searchHiddenTextCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchHiddenTextCheckBox_Text"); //searchInSelectionCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchInSelectionCheckBox_Text"); //searchTypeCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeCheckBox_Text"); //this.searchTypeDropDownList.Items.AddRange(new object[] { // AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeDropDownList_Item_RegularExpressions"), // AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchTypeDropDownList_Item_Wildcards") // }); //searchUpCheckBox.Text = AssemblyInfo.Instance.Resources.GetString("FindReplaceForm_SearchUpCheckBox_Text"); this.searchTypeDropDownList.Items.AddRange(new object[] { "�W�h�B�⦡", "�U�Φr��" }); // Select the first search type searchTypeDropDownList.SelectedIndex = 0; // Update options this.UpdateUIFromFindReplaceOptions(); }
[TestCase(FindReplaceDirection.Forward)] //ExSkip public void Direction(FindReplaceDirection findReplaceDirection) { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert three runs which we can search for using a regex pattern. // Place one of those runs inside a text box. builder.Writeln("Match 1."); builder.Writeln("Match 2."); builder.Writeln("Match 3."); builder.Writeln("Match 4."); // We can use a "FindReplaceOptions" object to modify the find-and-replace process. FindReplaceOptions options = new FindReplaceOptions(); // Assign a custom callback to the "ReplacingCallback" property. TextReplacementRecorder callback = new TextReplacementRecorder(); options.ReplacingCallback = callback; // Set the "Direction" property to "FindReplaceDirection.Backward" to get the find-and-replace // operation to start from the end of the range, and traverse back to the beginning. // Set the "Direction" property to "FindReplaceDirection.Backward" to get the find-and-replace // operation to start from the beginning of the range, and traverse to the end. options.Direction = findReplaceDirection; doc.Range.Replace(new Regex(@"Match \d*"), "Replacement", options); Assert.AreEqual("Replacement.\r" + "Replacement.\r" + "Replacement.\r" + "Replacement.", doc.GetText().Trim()); switch (findReplaceDirection) { case FindReplaceDirection.Forward: Assert.AreEqual(new[] { "Match 1", "Match 2", "Match 3", "Match 4" }, callback.Matches); break; case FindReplaceDirection.Backward: Assert.AreEqual(new[] { "Match 4", "Match 3", "Match 2", "Match 1" }, callback.Matches); break; } }
public static void FindAndReplaceFeature() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("This one is sad."); builder.Writeln("That one is mad."); FindReplaceOptions options = new FindReplaceOptions(); options.MatchCase = false; options.FindWholeWordsOnly = true; ReplaceOneWordWithAnother(doc); doc.Save(ArtifactsDir + "Find and replace.Replace one word - Aspose.Words.docx"); ReplaceTwoSimilarWords(doc); doc.Save(ArtifactsDir + "Find and replace.Replace two words - Aspose.Words.docx"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_FindAndReplace(); string fileName = "Field.ReplaceTextWithFields.doc"; Document doc = new Document(dataDir + fileName); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new ReplaceTextWithFieldHandler(FieldType.FieldMergeField); // Replace any "PlaceHolderX" instances in the document (where X is a number) with a merge field. doc.Range.Replace(new Regex(@"PlaceHolder(\d+)"), "", options); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); doc.Save(dataDir); Console.WriteLine("\nText replaced with field successfully.\nFile saved at " + dataDir); }
//ExStart //ExFor:Range.Replace(Regex, string, FindReplaceOptions) //ExFor:ReplacingArgs.Replacement //ExFor:IReplacingCallback //ExFor:IReplacingCallback.Replacing //ExFor:ReplacingArgs //ExFor:DocumentBuilder.InsertHtml(string) //ExSummary:Replaces text specified with regular expression with HTML. public void ReplaceWithInsertHtml() { // Open the document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello <CustomerName>,"); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new ReplaceWithHtmlEvaluator(options); doc.Range.Replace(new Regex(@" <CustomerName>,"), String.Empty, options); //instead of obsolete method doc.Range.Replace(new Regex(@"<CustomerName>"), new ReplaceWithHtmlEvaluator(), false) // Save the modified document. doc.Save(MyDir + @"\Artifacts\Range.ReplaceWithInsertHtml.doc"); Assert.AreEqual("James Bond, Hello\r\x000c", doc.GetText()); //ExSkip }
public void HeaderFooterOrder() { //ExStart //ExFor:IReplacingCallback //ExFor:Range.Replace(String, String, FindReplaceOptions) //ExSummary: Show changes for headers and footers order Document doc = new Document(MyDir + "HeaderFooter.HeaderFooterOrder.docx"); // Assert that we use special header and footer for the first page // The order for this: first header\footer, even header\footer, primary header\footer Section firstPageSection = doc.FirstSection; Assert.AreEqual(true, firstPageSection.PageSetup.DifferentFirstPageHeaderFooter); ReplaceLog logger = new ReplaceLog(); FindReplaceOptions options = new FindReplaceOptions { ReplacingCallback = logger }; doc.Range.Replace(new Regex("(header|footer)"), "", options); doc.Save(ArtifactsDir + "HeaderFooter.HeaderFooterOrder.docx"); #if __MOBILE__ Assert.AreEqual("First header\nFirst footer\nSecond header\nSecond footer\nThird header\n" + "Third footer\n", logger.Text); #else Assert.AreEqual("First header\nFirst footer\nSecond header\nSecond footer\nThird header\n" + "Third footer\n", logger.Text.Replace("\r", "")); #endif // Prepare our string builder for assert results without "DifferentFirstPageHeaderFooter" logger.ClearText(); // Remove special first page // The order for this: primary header, default header, primary footer, default footer, even header\footer firstPageSection.PageSetup.DifferentFirstPageHeaderFooter = false; doc.Range.Replace(new Regex("(header|footer)"), "", options); #if __MOBILE__ Assert.AreEqual("Third header\nFirst header\nThird footer\nFirst footer\nSecond header\nSecond footer\n", logger.Text); #else Assert.AreEqual("Third header\nFirst header\nThird footer\nFirst footer\nSecond header\nSecond footer\n", logger.Text.Replace("\r", "")); #endif }
public void ReplaceWithoutPreserveMetaCharacters() { const string text = "some text"; const string replaceWithText = "“"; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write(text); FindReplaceOptions options = new FindReplaceOptions(); options.PreserveMetaCharacters = false; doc.Range.Replace(text, replaceWithText, options); Assert.AreEqual("\vdquo;\f", doc.GetText()); }
private static void ReplaceTextInFooter(string dataDir) { // ExStart:ReplaceTextInFooter // Open the template document, containing obsolete copyright information in the footer. Document doc = new Document(dataDir + "HeaderFooter.ReplaceText.doc"); HeaderFooterCollection headersFooters = doc.FirstSection.HeadersFooters; HeaderFooter footer = headersFooters[HeaderFooterType.FooterPrimary]; FindReplaceOptions options = new FindReplaceOptions { MatchCase = false, FindWholeWordsOnly = false }; footer.Range.Replace("(C) 2006 Aspose Pty Ltd.", "Copyright (C) 2019 by Aspose Pty Ltd.", options); doc.Save(dataDir + "HeaderFooter.ReplaceText.doc"); // ExEnd:ReplaceTextInFooter }
public static void RecognizeAndSubstitutionsWithinReplacementPatterns(string dataDir) { // ExStart:RecognizeAndSubstitutionsWithinReplacementPatterns // Create new document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Write some text. builder.Write("Jason give money to Paul."); Regex regex = new Regex(@"([A-z]+) give money to ([A-z]+)"); // Replace text using substitutions. FindReplaceOptions options = new FindReplaceOptions(); options.UseSubstitutions = true; doc.Range.Replace(regex, @"$2 take money from $1", options); // ExEnd:RecognizeAndSubstitutionsWithinReplacementPatterns Console.WriteLine(doc.GetText()); // The output is: Paul take money from Jason.\f }
public void InsertDocumentAtReplace() { //ExStart //ExFor:Range.Replace(Regex, String, FindReplaceOptions) //ExFor:IReplacingCallback //ExFor:ReplaceAction //ExFor:IReplacingCallback.Replacing //ExFor:ReplacingArgs //ExFor:ReplacingArgs.MatchNode //ExId:InsertDocumentAtReplace //ExSummary:Shows how to insert content of one document into another during a customized find and replace operation. Document mainDoc = new Document(MyDir + "InsertDocument1.doc"); FindReplaceOptions options = new FindReplaceOptions(); options.Direction = FindReplaceDirection.Backward; options.ReplacingCallback = new InsertDocumentAtReplaceHandler(); mainDoc.Range.Replace(new Regex("\\[MY_DOCUMENT\\]"), "", options); mainDoc.Save(MyDir + @"\Artifacts\InsertDocumentAtReplace.doc"); }
public static void Run() { // ExStart:FindAndHighlight // The path to the documents directory. string dataDir = RunExamples.GetDataDir_FindAndReplace(); string fileName = "TestFile.doc"; Document doc = new Document(dataDir + fileName); FindReplaceOptions options = new FindReplaceOptions(); options.ReplacingCallback = new ReplaceEvaluatorFindAndHighlight(); // We want the "your document" phrase to be highlighted. Regex regex = new Regex("your document", RegexOptions.IgnoreCase); doc.Range.Replace(regex, "", options); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); // Save the output document. doc.Save(dataDir); // ExEnd:FindAndHighlight Console.WriteLine("\nText highlighted successfully.\nFile saved at " + dataDir); }
/// <summary> /// Fills FoundLocations with positions in the text. /// </summary> /// <param name="text"></param> /// <param name="textToFind"></param> /// <param name="scope"></param> /// <param name="function"></param> /// <param name="isTemplateFunction"></param> /// <param name="options"></param> /// <param name="userOffset"></param> /// <param name="findOneOnly"></param> /// <returns></returns> private static bool FindInText(string text, string textToFind, Scope scope, FunctionInfo function, bool isTemplateFunction, FindReplaceOptions options, int userOffset, bool findOneOnly) { text = text.Replace("\r\n", "\n"); // TODO: this function is in dire need of refactoring. The searching code is repeated in multiple places. bool found = false; if (string.IsNullOrEmpty(textToFind)) { return false; } if (!isTemplateFunction) { // Only template functions should have 'script' and 'output' scope = Scope.Both; } if (!options.MatchCase) { text = text.ToLower(); textToFind = textToFind.ToLower(); } int scriptStartPos = 0; int scriptEndPos = 0; int nextPos; switch (scope) { case Scope.ScriptOnly: for (int i = 0; i < text.Length; i++) { if (text[i] == '<' && text.Length > (i + 1) && text[i + 1] == '%') { scriptStartPos = i + 2; } else if (text[i] == '%' && text.Length > (i + 1) && text[i + 1] == '>') { scriptEndPos = i; // Replace text string script = text.Substring(scriptStartPos, scriptEndPos - scriptStartPos); nextPos = script.IndexOf(textToFind); while (nextPos >= 0) { if (!options.MatchWholeWord || (options.MatchWholeWord && IsWholeWord(ref script, ref textToFind, ref nextPos))) { m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); if (scriptStartPos + nextPos > userOffset) { found = true; if (findOneOnly) { m_foundLocations.Clear(); m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); return found; } } } nextPos = script.IndexOf(textToFind, nextPos + 1); } i = scriptEndPos + 2; } } break; case Scope.OutputOnly: scriptStartPos = 0; // This works for template functions only for (int i = 0; i < text.Length; i++) { if (text[i] == '%' && text.Length > (i + 1) && text[i + 1] == '>') { scriptStartPos = i + 2; } else if (text[i] == '<' && text.Length > (i + 1) && text[i + 1] == '%') { scriptEndPos = i; // Replace text string script = text.Substring(scriptStartPos, scriptEndPos - scriptStartPos); nextPos = script.IndexOf(textToFind); while (nextPos >= 0) { if (!options.MatchWholeWord || (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos))) { m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); if (scriptStartPos + nextPos > userOffset) { found = true; if (findOneOnly) { m_foundLocations.Clear(); m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); return found; } } } nextPos = script.IndexOf(textToFind, nextPos + 1); } i = scriptEndPos + 2; } } // Search the remaining text if (scriptEndPos < text.Length) { string script = text.Substring(scriptStartPos); nextPos = script.IndexOf(textToFind); while (nextPos >= 0) { if (!options.MatchWholeWord || (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos))) { m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); if (scriptStartPos + nextPos > userOffset) { found = true; if (findOneOnly) { m_foundLocations.Clear(); m_foundLocations.Add(new FoundLocation(function, scriptStartPos + nextPos, textToFind.Length)); return found; } } } nextPos = script.IndexOf(textToFind, nextPos + 1); } } break; case Scope.Both: nextPos = text.IndexOf(textToFind); while (nextPos >= 0) { if (!options.MatchWholeWord || (options.MatchWholeWord && IsWholeWord(ref text, ref textToFind, ref nextPos))) { m_foundLocations.Add(new FoundLocation(function, nextPos, textToFind.Length)); if (scriptStartPos + nextPos > userOffset) { found = true; if (findOneOnly) { m_foundLocations.Clear(); m_foundLocations.Add(new FoundLocation(function, nextPos, textToFind.Length)); return found; } } } nextPos = text.IndexOf(textToFind, nextPos + 1); } break; default: throw new NotImplementedException("Not coded yet"); } return found; }
bool ICommandHandler.HandleCommand(Command command) { ISearchableDocumentView view; bool flag = false; bool flag2 = false; if (command.CommandGroup.Equals(typeof(GlobalCommands))) { switch (command.CommandID) { case 0x6c: goto Label_02E2; case 0x6d: { ISearchableDocumentView activeDocumentView = this.GetActiveDocumentView() as ISearchableDocumentView; if (activeDocumentView != null) { ReplaceDialog dialog2 = new ReplaceDialog(this._serviceProvider, activeDocumentView, this._lastFindReplaceOptions, activeDocumentView.InitialSearchString, this.FindMruList, this.ReplaceMruList); IUIService service7 = (IUIService) this._serviceProvider.GetService(typeof(IUIService)); if (service7 != null) { service7.ShowDialog(dialog2); this._lastFindReplaceOptions = dialog2.FindReplaceOptions; } flag2 = true; } flag = true; goto Label_052C; } case 110: { ISearchableDocumentView view3 = this.GetActiveDocumentView() as ISearchableDocumentView; if (((view3 != null) && (command.Text != null)) && (command.Text.Length > 0)) { this.FindMruList.AddEntry(command.Text); flag2 = true; if (!view3.PerformFind(command.Text, this._lastFindReplaceOptions & (FindReplaceOptions.WholeWord | FindReplaceOptions.MatchCase))) { IUIService service6 = (IUIService) this._serviceProvider.GetService(typeof(IUIService)); if (service6 != null) { service6.ShowMessage("Couldn't find '" + command.Text + "'", string.Empty, MessageBoxButtons.OK); } } } flag = true; goto Label_052C; } case 8: { IPrintService service = (IPrintService) this._serviceProvider.GetService(typeof(IPrintService)); if (service != null) { service.ConfigurePrintSettings(); } flag = true; goto Label_052C; } case 300: case 0x12d: case 0x12e: case 0x12f: case 0x130: case 0x131: case 0x132: case 0x133: case 0x134: case 0x135: case 320: case 0x141: ((ICommandHandler) this.AddInManager).HandleCommand(command); flag = true; goto Label_052C; case 310: case 0x137: case 0x138: case 0x139: case 0x13a: case 0x13b: case 0x13c: case 0x13d: case 0x13e: case 0x13f: case 0x142: case 0x143: case 0x259: case 0x25d: case 0x25f: case 0x260: case 0x261: goto Label_052C; case 0x144: { OptionsDialog dialog3 = new OptionsDialog(this._serviceProvider); ((IUIService) this._serviceProvider.GetService(typeof(IUIService))).ShowDialog(dialog3); flag = true; goto Label_052C; } case 0x145: case 0x146: case 0x147: { IToolboxService service8 = this._serviceProvider.GetService(typeof(IToolboxService)) as IToolboxService; ToolboxSection activeSection = service8.ActiveSection; if (activeSection != null) { activeSection.Customize(command.CommandID - 0x145, this._serviceProvider); } flag = true; goto Label_052C; } case 180: { ISearchableDocumentView view2 = this.GetActiveDocumentView() as ISearchableDocumentView; if (view2 != null) { if (this.FindMruList.Count == 0) { goto Label_02E2; } view2.PerformFind(this.FindMruList[0], this._lastFindReplaceOptions & (FindReplaceOptions.WholeWord | FindReplaceOptions.MatchCase)); flag2 = true; } flag = true; goto Label_052C; } case 600: this.OnCommandHelpTopics(); flag = true; goto Label_052C; case 0x25a: case 0x25e: { ApplicationInfoDialog dialog = new ApplicationInfoDialog(this._serviceProvider, command.CommandID == 0x25e); IUIService service4 = (IUIService) this._serviceProvider.GetService(typeof(IUIService)); if (service4 == null) { dialog.ShowDialog(); } else { service4.ShowDialog(dialog); } flag = true; goto Label_052C; } case 0x25b: case 0x25c: { string format = ConfigurationSettings.AppSettings["IDE.AskQuestionUrl"]; if ((format == null) || (format.Length == 0)) { ((IUIService) this._serviceProvider.GetService(typeof(IUIService))).ShowMessage("Unable to bring up launch the answer page.", "Ask Question"); } else { string entry = string.Empty; if (command.CommandID == 0x25c) { entry = command.Text; if (entry != null) { this.AskQuestionMruList.AddEntry(entry); format = string.Format(format, entry); flag2 = true; } } ((IWebBrowsingService) this._serviceProvider.GetService(typeof(IWebBrowsingService))).BrowseUrl(format); } flag = true; goto Label_052C; } case 610: case 0x263: case 0x264: case 0x265: case 0x266: case 0x267: case 0x268: case 0x269: case 0x26a: case 0x26b: { IDictionary webLinks = this.WebLinks; if (webLinks != null) { int num = command.CommandID - 610; string str = "Help" + num; WebLink link = (WebLink) webLinks[str]; if (link != null) { this.OnCommandBrowseUrl(link.Url); } } flag = true; goto Label_052C; } } } goto Label_052C; Label_02E2: view = this.GetActiveDocumentView() as ISearchableDocumentView; if (view != null) { SearchForm form = new SearchForm(this._serviceProvider, view, this._lastFindReplaceOptions, view.InitialSearchString, this.FindMruList); IUIService service5 = (IUIService) this._serviceProvider.GetService(typeof(IUIService)); if (service5 != null) { service5.ShowDialog(form); this._lastFindReplaceOptions = form.FindReplaceOptions; } flag2 = true; } flag = true; Label_052C: if (flag2) { ((ICommandManager) this._serviceProvider.GetService(typeof(ICommandManager))).UpdateCommands(false); } return flag; }
public void RenameVariable(ILuaIntellisenseDocument document) { VariableExpression expression; List<LuatValue.IReference> definitions; if (!CanRenameVariable(document, out expression, out definitions)) return; using (var dialog = new RenameVariableForm()) { dialog.InputText = expression.DisplayText; var se = (ActiproSoftware.SyntaxEditor.SyntaxEditor)document.SyntaxEditorControl; if (dialog.ShowDialog(se) != DialogResult.OK) return; if (CheckVariableNameInUse(expression, dialog.InputText)) { const string message = "A variable with this name already exists. Do you want to continue?"; const string caption = "Warning"; if (MessageBox.Show(message, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) return; } try { // save cursor and scroll pos to set it back to where it was after we are done replacing //int caretPos = se.Caret.Offset; //int scrollPos = se.SelectedView.FirstVisibleDisplayLineIndex; var options = new FindReplaceOptions { FindText = expression.DisplayText, MatchCase = true, MatchWholeWord = true, ReplaceText = dialog.InputText, SearchHiddenText = true, SearchType = FindReplaceSearchType.Normal }; se.Document.FindReplace.ReplaceAll(options); //// remove duplicates (for instance, if scripts are referenced multiple times in a project) //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // for (var j = i + 1; j < definitions.Count; ++j) // { // var potentialDuplicate = definitions[j]; // if ((original.Line == potentialDuplicate.Line) && // (original.TextRange.StartOffset == potentialDuplicate.TextRange.StartOffset) && // (original.TextRange.EndOffset == potentialDuplicate.TextRange.EndOffset) && // (string.Compare(original.Path, potentialDuplicate.Path, true) == 0)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// remove spans that are included in larger spans //for (var i = 0; i < definitions.Count; ++i) //{ // var original = definitions[i]; // var duplicates = new List<LuatValue.IReference>(); // foreach (var potentialDuplicate in definitions) // { // if (ReferenceEquals(original, potentialDuplicate)) // continue; // if (string.Compare(original.Path, potentialDuplicate.Path, true) != 0) // continue; // if ((potentialDuplicate.TextRange.StartOffset >= original.TextRange.StartOffset) && // (potentialDuplicate.TextRange.EndOffset <= original.TextRange.EndOffset)) // { // duplicates.Add(potentialDuplicate); // } // } // foreach (LuatValue.IReference duplicate in duplicates) // definitions.Remove(duplicate); //} //// sort the references so we replace the text bottom to top to avoid invalidating the //// other references text range //definitions.Sort( // (a, b) => // { // TextRange aRange = ((SyntaxEditorTextRange)a.TextRange).ToTextRange(); // TextRange bRange = ((SyntaxEditorTextRange)b.TextRange).ToTextRange(); // return bRange.FirstOffset.CompareTo(aRange.FirstOffset); // }); //foreach (LuatValue.IReference reference in definitions) //{ // TextRange textRange = ((SyntaxEditorTextRange)reference.TextRange).ToTextRange(); // se.Document.ReplaceText(DocumentModificationType.Replace, textRange, dialog.InputText); //} //// adjust the position of the cursor based on changes made to the document //int diff = dialog.InputText.Length - expression.DisplayText.Length; //caretPos += (diff * (definitions.Count - 1)); //se.Caret.Offset = caretPos; //se.SelectedView.FirstVisibleDisplayLineIndex = scrollPos; } catch (Exception ex) { ex.ToString(); } } }
/// <summary> /// Renames a function throughout the project. /// </summary> /// <param name="oldName"></param> /// <param name="newName"></param> public void RenameFunctionAll(string oldName, string newName) { // TODO: Replace this search with a regular expression that searches for a real function. ie: followed by 0-m spaces then an opening bracket. Also, preceeded by a non-alphanumeric character. oldName += "("; newName += "("; // Store original settings SearchHelper.SearchFunctions origSearchFunctions = SearchHelper.searchFunctions; SearchHelper.Scope origScope = SearchHelper.scope; FindReplaceOptions origFindReplaceOptions = SearchHelper.Options; string origTextToFind = SearchHelper.Options == null ? "" : SearchHelper.Options.FindText; // Modify settings for special replace SearchHelper.searchFunctions = SearchHelper.SearchFunctions.AllFunctions; SearchHelper.scope = SearchHelper.Scope.ScriptOnly; FindReplaceOptions opt = new FindReplaceOptions(); opt.MatchCase = true;// Might need to revisit this decision. Will miss possible mis-spellings in comments etc. SearchHelper.Options = opt; SearchHelper.Options.FindText = oldName; // Replace name in script portion of all functions SearchHelper.ReplaceAll(oldName, newName); // Replace in generated file names RenameFunctionInRootOuput(oldName, newName); if (Controller.Instance.MainForm.UcGenerationChoices != null) { Controller.Instance.MainForm.UcGenerationChoices.Populate(); } // Reset original settings SearchHelper.searchFunctions = origSearchFunctions; SearchHelper.scope = origScope; SearchHelper.Options = origFindReplaceOptions; if (SearchHelper.Options != null) { SearchHelper.Options.FindText = origTextToFind; } }
public LINQPadFindReplaceForm(ActiproSoftware.SyntaxEditor.SyntaxEditor editor, FindReplaceOptions options) : base(editor, options) { }
protected override bool PerformReplace(string searchString, string replaceString, FindReplaceOptions options) { if (this.InTemplateMode) { return ((ISearchableDocumentView) this._templateEditingDialog.DesignView).PerformReplace(searchString, replaceString, options); } return base.PerformReplace(searchString, replaceString, options); }
bool ISearchableDocumentView.PerformFind(string searchString, FindReplaceOptions options) { return this.PerformFind(searchString, options); }
public frmFindReplace(Control owner, SyntaxEditor editor, FindReplaceOptions options, string DefaultText) { // // Required for Windows Form Designer support // InitializeComponent(); // // Add any constructor code after InitializeComponent call // this.owner = owner; this.editor = editor; this.options = options; // Set the form owner this.Owner = g.Main; // Clear the status //owner.SetStatusMessage("Ready"); // Select the first search type searchTypeDropDownList.SelectedIndex = 0; // Update options findTextBox.Text = options.FindText; replaceTextBox.Text = options.ReplaceText; matchCaseCheckBox.Checked = options.MatchCase; matchWholeWordCheckBox.Checked = options.MatchWholeWord; searchUpCheckBox.Checked = options.SearchUp; searchHiddenTextCheckBox.Checked = options.SearchHiddenText; searchInSelectionCheckBox.Checked = options.SearchInSelection; searchTypeCheckBox.Checked = (options.SearchType != FindReplaceSearchType.Normal); searchTypeDropDownList.SelectedIndex = (options.SearchType != FindReplaceSearchType.Wildcard ? 0 : 1); this.findTextBox.Text = DefaultText; RehashRecent(); }
private static void FindInText(string text, string textToFind, Scope scope, FunctionInfo function, bool isTemplateFunction, FindReplaceOptions options) { FindInText(text, textToFind, scope, function, isTemplateFunction, options, -1, false); }
bool ISearchableDocumentView.PerformReplace(string searchString, string replaceString, FindReplaceOptions options) { return ((this._currentView.view is ISearchableDocumentView) && ((ISearchableDocumentView) this._currentView.view).PerformReplace(searchString, replaceString, options)); }
protected virtual bool PerformFind(string searchString, FindReplaceOptions options) { return this._editor.Find(searchString, (options & FindReplaceOptions.MatchCase) != FindReplaceOptions.None, (options & FindReplaceOptions.WholeWord) != FindReplaceOptions.None, (options & FindReplaceOptions.SearchUp) != FindReplaceOptions.None); }
bool ISearchableDocumentView.PerformReplace(string searchString, string replaceString, FindReplaceOptions options) { throw new NotSupportedException(); }
protected virtual bool PerformFind(string searchString, FindReplaceOptions options) { bool searchUp = (options & FindReplaceOptions.SearchUp) != FindReplaceOptions.None; bool matchCase = (options & FindReplaceOptions.MatchCase) != FindReplaceOptions.None; bool wholeWord = (options & FindReplaceOptions.WholeWord) != FindReplaceOptions.None; bool inSelection = (options & FindReplaceOptions.InSelection) != FindReplaceOptions.None; using (TextBufferSpan span = base.Find(searchString, matchCase, wholeWord, searchUp, inSelection)) { if (span != null) { base.Select(span); return true; } } return false; }
/// <summary> /// Called for each field belonging to an unmerged region in the document. /// </summary> public void FieldMerging(FieldMergingArgs args) { // ExStart:RemoveExtraParagraphs // Store the parent paragraph of the current field for easy access. Paragraph parentParagraph = args.Field.Start.ParentParagraph; // Define the logic to be used when the ContactDetails region is encountered. // The region is removed and replaced with a single line of text stating that there are no records. if (args.TableName == "ContactDetails") { // Called for the first field encountered in a region. This can be used to execute logic on the first field // In the region without needing to hard code the field name. Often the base logic is applied to the first field and // Different logic for other fields. The rest of the fields in the region will have a null FieldValue. if ((string)args.FieldValue == "FirstField") { FindReplaceOptions options = new FindReplaceOptions(); // Remove the "Name:" tag from the start of the paragraph parentParagraph.Range.Replace("Name:", string.Empty, options); // Set the text of the first field to display a message stating that there are no records. args.Text = "No records to display"; } else { // We have already inserted our message in the paragraph belonging to the first field. The other paragraphs in the region // will still remain so we want to remove these. A check is added to ensure that the paragraph has not already been removed. // which may happen if more than one field is included in a paragraph. if (parentParagraph.ParentNode != null) parentParagraph.Remove(); } } // ExEnd:RemoveExtraParagraphs // ExStart:MergeAllCells // Replace the unused region in the table with a "no records" message and merge all cells into one. if (args.TableName == "Suppliers") { if ((string)args.FieldValue == "FirstField") { // We will use the first paragraph to display our message. Make it centered within the table. The other fields in other cells // within the table will be merged and won't be displayed so we don't need to do anything else with them. parentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center; args.Text = "No records to display"; } // Merge the cells of the table together. Cell cell = (Cell)parentParagraph.GetAncestor(NodeType.Cell); if (cell != null) { if (cell.IsFirstCell) cell.CellFormat.HorizontalMerge = CellMerge.First; // If this cell is the first cell in the table then the merge is started using "CellMerge.First". else cell.CellFormat.HorizontalMerge = CellMerge.Previous; // Otherwise the merge is continued using "CellMerge.Previous". } } // ExEnd:MergeAllCells }
private static void FindInText(string text, string textToFind, Scope scope, ArchAngel.Interfaces.Template.File scriptFile, bool isTemplateFunction, FindReplaceOptions options) { FindInText(text, textToFind, scope, scriptFile, isTemplateFunction, options, -1, false); }
protected virtual bool PerformReplace(string searchString, string replaceString, FindReplaceOptions options) { bool searchUp = (options & FindReplaceOptions.SearchUp) != FindReplaceOptions.None; bool matchCase = (options & FindReplaceOptions.MatchCase) != FindReplaceOptions.None; bool wholeWord = (options & FindReplaceOptions.WholeWord) != FindReplaceOptions.None; bool replaceAll = (options & FindReplaceOptions.All) != FindReplaceOptions.None; bool inSelection = (options & FindReplaceOptions.InSelection) != FindReplaceOptions.None; return base.Replace(searchString, replaceString, matchCase, wholeWord, searchUp, replaceAll, inSelection); }