コード例 #1
0
ファイル: InlineRename.cs プロジェクト: wise0704/FlashDevelop
        /// <summary>
        /// Creates a new instance of <see cref="InlineRename"/>. Any existing instance in progress
        /// is automatically canceled.
        /// </summary>
        /// <param name="control">The <see cref="ScintillaControl"/> object.</param>
        /// <param name="original">The original name of the target.</param>
        /// <param name="position">Word end position of the target.</param>
        /// <param name="includeComments">Whether to initially include comments in search. Pass <code>null</code> to disable this option.</param>
        /// <param name="includeStrings">Whether to initially include strings in search. Pass <code>null</code> to disable this option.</param>
        /// <param name="previewChanges">Whether to initially preview changes during renaming. Pass <code>null</code> to disable this option.</param>
        /// <param name="previewTarget">An <see cref="ASResult"/> object specifying the target. This parameter must not be <code>null</code> if <code>previewChanges</code> is not <code>null</code>.</param>
        public InlineRename(ScintillaControl control, string original, int position, bool?includeComments, bool?includeStrings, bool?previewChanges, ASResult previewTarget)
        {
            if (previewChanges.HasValue && previewTarget == null)
            {
                throw new ArgumentNullException("previewTarget");
            }

            CancelCurrent();

            sci     = control;
            start   = position - original.Length;
            oldName = original;
            newName = original;
            //prevName = original;
            end              = position;
            currentDoc       = PluginBase.MainForm.CurrentDocument;
            delayedExecution = new DelayedExecution();
            history          = new List <string>()
            {
                oldName
            };
            historyIndex         = 0;
            this.includeComments = includeComments ?? false;
            this.includeStrings  = includeStrings ?? false;
            this.previewChanges  = previewChanges ?? false;

            sci.BeginUndoAction();
            InitializeHighlights();
            SetupLivePreview(includeComments.HasValue, includeStrings.HasValue, previewChanges.HasValue, previewTarget);
            AddMessageFilter();
            DisableControls();
            Highlight(start, end - start);
            sci.SetSel(start, end);
        }
コード例 #2
0
        /// <summary>
        /// Replaces all results specified by user input
        /// </summary>
        private void ReplaceAllButtonClick(Object sender, System.EventArgs e)
        {
            if (Globals.SciControl == null)
            {
                return;
            }
            ScintillaControl   sci           = Globals.SciControl;
            List <SearchMatch> matches       = this.GetResults(sci);
            Boolean            selectionOnly = this.lookComboBox.SelectedIndex == 1 && sci.SelText.Length > 0;

            if (matches != null && selectionOnly)
            {
                Int32 end   = sci.MBSafeCharPosition(sci.SelectionEnd);
                Int32 start = sci.MBSafeCharPosition(sci.SelectionStart);
                matches = FRDialogGenerics.FilterMatches(matches, start, end);
            }
            if (matches != null)
            {
                sci.BeginUndoAction();
                try
                {
                    for (Int32 i = 0, count = matches.Count; i < count; i++)
                    {
                        if (!selectionOnly)
                        {
                            FRDialogGenerics.SelectMatch(sci, matches[i]);
                        }
                        else
                        {
                            FRDialogGenerics.SelectMatchInTarget(sci, matches[i]);
                        }
                        String replaceWith = this.GetReplaceText(matches[i]);
                        FRSearch.PadIndexes(matches, i, matches[i].Value, replaceWith);
                        sci.EnsureVisible(sci.CurrentLine);
                        if (!selectionOnly)
                        {
                            sci.ReplaceSel(replaceWith);
                        }
                        else
                        {
                            sci.ReplaceTarget(sci.MBSafeTextLength(replaceWith), replaceWith);
                        }
                    }
                }
                finally
                {
                    sci.EndUndoAction();
                }
                FRDialogGenerics.UpdateComboBoxItems(this.findComboBox);
                FRDialogGenerics.UpdateComboBoxItems(this.replaceComboBox);
                String message   = TextHelper.GetString("Info.ReplacedMatches");
                String formatted = String.Format(message, matches.Count);
                this.ShowMessage(formatted, 0);
                this.lookupIsDirty = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// The actual process implementation
        /// </summary>
        protected override void ExecutionImplementation()
        {
            IASContext         context = ASContext.Context;
            ScintillaControl   sci     = PluginBase.MainForm.CurrentDocument.SciControl;
            Int32              pos     = sci.CurrentPos;
            List <MemberModel> imports = new List <MemberModel>(context.CurrentModel.Imports.Count);

            imports.AddRange(context.CurrentModel.Imports.Items);
            ImportsComparerLine comparerLine = new ImportsComparerLine();

            imports.Sort(comparerLine);
            sci.SetSel(sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineFrom), sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineTo));
            String publicClassText  = sci.SelText;
            String privateClassText = "";

            if (context.CurrentModel.Classes.Count > 1)
            {
                sci.SetSel(pos, pos);
                sci.SetSel(sci.PositionFromLine(context.CurrentModel.Classes[1].LineFrom), sci.PositionFromLine(sci.LineCount));
                privateClassText = sci.SelText;
            }
            if (imports.Count > 1 || (imports.Count > 0 && this.TruncateImports))
            {
                sci.BeginUndoAction();
                foreach (MemberModel import in imports)
                {
                    sci.GotoLine(import.LineFrom);
                    this.ImportIndents.Add(new KeyValuePair <MemberModel, Int32>(import, sci.GetLineIndentation(import.LineFrom)));
                    sci.LineDelete();
                }
                if (this.TruncateImports)
                {
                    for (Int32 j = 0; j < imports.Count; j++)
                    {
                        MemberModel import = imports[j];
                        String[]    parts  = import.Type.Split('.');
                        if (parts.Length > 0 && parts[parts.Length - 1] != "*")
                        {
                            parts[parts.Length - 1] = "*";
                        }
                        import.Type = String.Join(".", parts);
                    }
                }
                imports.Reverse();
                Imports separatedImports = this.SeparateImports(imports, context.CurrentModel.PrivateSectionIndex);
                this.InsertImports(separatedImports.PackageImports, publicClassText, sci, separatedImports.PackageImportsIndent);
                if (context.CurrentModel.Classes.Count > 1)
                {
                    this.InsertImports(separatedImports.PrivateImports, privateClassText, sci, separatedImports.PrivateImportsIndent);
                }
                sci.SetSel(pos, pos);
                sci.EndUndoAction();
            }
            this.FireOnRefactorComplete();
        }
コード例 #4
0
        /// <summary>
        /// Inserts the specified snippet to the document
        /// </summary>
        public static Int32 InsertSnippetText(ScintillaControl sci, Int32 currentPosition, String snippet)
        {
            sci.BeginUndoAction();
            try
            {
                Int32  newIndent;
                String text = snippet;
                if (sci.SelTextSize > 0)
                {
                    currentPosition -= sci.MBSafeTextLength(sci.SelText);
                }
                Int32 line   = sci.LineFromPosition(currentPosition);
                Int32 indent = sci.GetLineIndentation(line);
                sci.ReplaceSel("");

                Int32  lineMarker = LineEndDetector.DetectNewLineMarker(text, sci.EOLMode);
                String newline    = LineEndDetector.GetNewLineMarker(lineMarker);
                if (newline != "\n")
                {
                    text = text.Replace(newline, "\n");
                }
                newline = LineEndDetector.GetNewLineMarker((Int32)PluginBase.MainForm.Settings.EOLMode);
                text    = PluginBase.MainForm.ProcessArgString(text).Replace(newline, "\n");
                newline = LineEndDetector.GetNewLineMarker(sci.EOLMode);
                String[] splitted = text.Trim().Split('\n');
                for (Int32 j = 0; j < splitted.Length; j++)
                {
                    if (j != splitted.Length - 1)
                    {
                        sci.InsertText(sci.CurrentPos, splitted[j] + newline);
                    }
                    else
                    {
                        sci.InsertText(sci.CurrentPos, splitted[j]);
                    }
                    sci.CurrentPos += sci.MBSafeTextLength(splitted[j]) + newline.Length;
                    if (j > 0)
                    {
                        line      = sci.LineFromPosition(sci.CurrentPos - newline.Length);
                        newIndent = sci.GetLineIndentation(line) + indent;
                        sci.SetLineIndentation(line, newIndent);
                    }
                }
                Int32 length = sci.CurrentPos - currentPosition - newline.Length;
                Int32 delta  = PostProcessSnippets(sci, currentPosition);
                return(length + delta);
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
コード例 #5
0
        public void Execute()
        {
            ScintillaControl Sci = PluginBase.MainForm.CurrentDocument.SciControl;

            Sci.BeginUndoAction();
            try
            {
                ASGenerator.GenerateExtractMethod(Sci, NewName);
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        static public bool ReplaceText(ScintillaControl sci, String tail, char trigger)
        {
            sci.BeginUndoAction();
            try
            {
                String triggers = PluginBase.Settings.InsertionTriggers ?? "";
                if (triggers.Length > 0 && Regex.Unescape(triggers).IndexOf(trigger) < 0)
                {
                    return(false);
                }

                ICompletionListItem item = null;
                if (completionList.SelectedIndex >= 0)
                {
                    item = completionList.Items[completionList.SelectedIndex] as ICompletionListItem;
                }
                Hide();
                if (item != null)
                {
                    String replace = item.Value;
                    if (replace != null)
                    {
                        sci.SetSel(startPos, sci.CurrentPos);
                        if (word != null && tail.Length > 0)
                        {
                            if (replace.StartsWith(word, StringComparison.OrdinalIgnoreCase) && replace.IndexOfOrdinal(tail) >= word.Length)
                            {
                                replace = replace.Substring(0, replace.IndexOfOrdinal(tail));
                            }
                        }
                        sci.ReplaceSel(replace);
                        if (OnInsert != null)
                        {
                            OnInsert(sci, startPos, replace, trigger, item);
                        }
                        if (tail.Length > 0)
                        {
                            sci.ReplaceSel(tail);
                        }
                    }
                    return(true);
                }
                return(false);
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
コード例 #7
0
ファイル: SaveAsClass.cs プロジェクト: Dsnoi/flashdevelopjp
    public static void Execute()
    {
        if (Globals.SciControl == null)
        {
            return;
        }
        ScintillaControl sci = Globals.SciControl;

        //Project project = (Project) PluginBase.CurrentProject;
        //if (project == null) return;

        MainForm mainForm = (MainForm)Globals.MainForm;

        ITabbedDocument document = mainForm.CurrentDocument;

        String    dir     = Path.GetDirectoryName(document.FileName);
        Hashtable details = ASComplete.ResolveElement(sci, null);

        IASContext context = ASContext.Context;
        ClassModel cClass  = context.CurrentClass;
        string     package = context.CurrentModel.Package;

        sci.BeginUndoAction();

        if (sci.SelText == "")
        {
            sci.SelectionStart = sci.PositionFromLine(cClass.LineFrom);
            sci.SelectionEnd   = sci.PositionFromLine(cClass.LineTo + 1);
        }

        String content = Regex.Replace(
            sci.SelText,
            @"^",
            "\t",
            RegexOptions.Multiline);

        String contents = "package " + package + " {\n" + content + "\n}";

        TraceManager.Add(contents);
        //TraceManager.Add(cClass.LineTo.ToString());

        Encoding encoding = sci.Encoding;
        String   file     = dir + "\\" + cClass.Name + ".as";

        FileHelper.WriteFile(file, contents, encoding);

        sci.Clear();
        sci.EndUndoAction();
    }
コード例 #8
0
 /// <summary>
 /// Replaces only the matches in the current sci control
 /// </summary>
 public static void ReplaceMatches(IList <SearchMatch> matches, ScintillaControl sci, String replacement, String src)
 {
     if (sci == null || matches == null || matches.Count == 0)
     {
         return;
     }
     sci.BeginUndoAction();
     try
     {
         for (Int32 i = 0; i < matches.Count; i++)
         {
             SelectMatch(sci, matches[i]);
             FRSearch.PadIndexes((List <SearchMatch>)matches, i, matches[i].Value, replacement);
             sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(matches[i].Index)));
             sci.ReplaceSel(replacement);
         }
     }
     finally
     {
         sci.EndUndoAction();
     }
 }
コード例 #9
0
        private void BaseSimple(bool aternate)
        {
            ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();

            // Settings
            String setAlt = this.settingObject.AlternateFunction.Trim();

            if (setAlt == "")
            {
                setAlt = "MyLogger.log";
            }
            Boolean setIns = this.settingObject.InsertNewLine;
            Boolean setCmp = this.settingObject.CompactMode;
            Boolean setPkg = this.settingObject.ShowPackageName;
            Boolean setCls = this.settingObject.ShowClassName;

            PositionInfos t     = new PositionInfos(sci, sci.CurrentPos, PluginBase.MainForm.ProcessArgString(sArgsString));
            String        trace = "";
            Boolean       exec  = false;

            if (t.HasSelection)
            {
                if (!t.SelectionIsMultiline)
                {
                    String sel1 = t.SelectedText.Trim();
                    if (sel1.EndsWith(";"))
                    {
                        sel1 = sel1.Substring(0, sel1.Length - 1);
                    }

                    String sel0 = sel1;
                    if (sel0.IndexOf('"') > -1)
                    {
                        sel0 = sel0.Replace("\"", "\\\"");
                    }

                    String tr0 = "trace( \"";
                    if (aternate)
                    {
                        tr0 = setAlt + "( \"";
                    }
                    String tr1 = " : \" + ";
                    String tr2 = " );";
                    if (setCmp)
                    {
                        tr0 = "trace(\"";
                        if (aternate)
                        {
                            tr0 = setAlt + "(\"";
                        }
                        tr1 = ": \"+";
                        tr2 = ");";
                    }

                    trace = tr0 + sel0 + tr1 + sel1 + tr2;
                    exec  = true;
                }
            }
            else
            {
                if (t.PreviousWordIsFunction)
                {
                    String pckg = "";
                    String clas = "";

                    if (!t.HasArguments)
                    {
                        String tr0 = "trace( \"";
                        if (aternate)
                        {
                            tr0 = setAlt + "( \"";
                        }
                        String tr1 = "\" );";
                        if (setCmp)
                        {
                            tr0 = "trace(\"";
                            if (aternate)
                            {
                                tr0 = setAlt + "(\"";
                            }
                            tr1 = "\");";
                        }

                        if (setPkg)
                        {
                            pckg = t.ArgPackageName + ".";
                        }

                        if (setCls)
                        {
                            clas = t.ArgClassName + ".";
                        }

                        trace = tr0 + pckg + clas + t.WordFromPosition + tr1;
                        exec  = true;
                    }
                    else
                    {
                        String tr0 = "trace( \"";
                        if (aternate)
                        {
                            tr0 = setAlt + "( \"";
                        }
                        String tr1 = " > ";
                        String tr2 = " );";
                        if (setCmp)
                        {
                            tr0 = "trace(\"";
                            if (aternate)
                            {
                                tr0 = setAlt + "(\"";
                            }
                            tr1 = " > ";
                            tr2 = ");";
                        }

                        if (setPkg)
                        {
                            pckg = t.ArgPackageName + ".";
                        }

                        if (setCls)
                        {
                            clas = t.ArgClassName + ".";
                        }

                        String args = "";
                        String a    = "";
                        for (Int32 i = 0; i < t.Arguments.Count; i++)
                        {
                            a = (String)t.Arguments[i];
                            if (i == 0)
                            {
                                if (!setCmp)
                                {
                                    args += a + " : \" + " + a + " + ";
                                }
                                else
                                {
                                    args += a + ": \"+" + a + "+";
                                }
                            }
                            else
                            {
                                if (!setCmp)
                                {
                                    args += "\", " + a + " : \" + " + a + " + ";
                                }
                                else
                                {
                                    args += "\", " + a + ": \"+" + a + "+";
                                }
                            }
                        }

                        if (!setCmp)
                        {
                            args = args.Substring(0, args.Length - 3);
                        }
                        else
                        {
                            args = args.Substring(0, args.Length - 1);
                        }

                        trace = tr0 + pckg + clas + t.WordFromPosition + tr1 + args + tr2;
                        exec  = true;
                    }
                }
                else
                {
                    if (t.WordFromPosition != "")
                    {
                        String tr0 = "trace( \"";
                        if (aternate)
                        {
                            tr0 = setAlt + "( \"";
                        }
                        String tr1 = " : \" + ";
                        String tr2 = " );";
                        if (setCmp)
                        {
                            tr0 = "trace(\"";
                            if (aternate)
                            {
                                tr0 = setAlt + "(\"";
                            }
                            tr1 = ": \"+";
                            tr2 = ");";
                        }

                        trace = tr0 + t.WordFromPosition + tr1 + t.WordFromPosition + tr2;
                        exec  = true;
                    }
                }
            }

            if (exec)
            {
                HelpTools.SetCaretReadyToTrace(sci, true);

                sci.InsertText(sci.CurrentPos, trace);

                HelpTools.GoToLineEnd(sci, setIns);
            }

            sci.EndUndoAction();
        }
コード例 #10
0
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;
            Sci.BeginUndoAction();
            try
            {
                IASContext context = ASContext.Context;

                string selection = Sci.SelText;
                if (selection == null || selection.Length == 0)
                {
                    return;
                }

                if (selection.TrimStart().Length == 0)
                {
                    return;
                }

                Sci.SetSel(Sci.SelectionStart + selection.Length - selection.TrimStart().Length,
                           Sci.SelectionEnd);
                Sci.CurrentPos = Sci.SelectionEnd;

                Int32 pos = Sci.CurrentPos;

                int lineStart        = Sci.LineFromPosition(Sci.SelectionStart);
                int lineEnd          = Sci.LineFromPosition(Sci.SelectionEnd);
                int firstLineIndent  = Sci.GetLineIndentation(lineStart);
                int entryPointIndent = Sci.Indent;

                for (int i = lineStart; i <= lineEnd; i++)
                {
                    int indent = Sci.GetLineIndentation(i);
                    if (i > lineStart)
                    {
                        Sci.SetLineIndentation(i, indent - firstLineIndent + entryPointIndent);
                    }
                }

                string selText = Sci.SelText;
                Sci.ReplaceSel(NewName + "();");

                cFile = ASContext.Context.CurrentModel;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, Sci.Text);

                bool isAs3 = cFile.Context.Settings.LanguageId == "AS3";

                FoundDeclaration found = GetDeclarationAtLine(Sci, lineStart);
                if (found == null || found.member == null)
                {
                    return;
                }

                int position = Sci.PositionFromLine(found.member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
                Sci.SetSel(position, position);

                StringBuilder sb = new StringBuilder();
                sb.Append("$(Boundary)\n\n");
                if ((found.member.Flags & FlagType.Static) > 0)
                {
                    sb.Append("static ");
                }
                sb.Append(ASGenerator.GetPrivateKeyword());
                sb.Append(" function ");
                sb.Append(NewName);
                sb.Append("():");
                sb.Append(isAs3 ? "void " : "Void ");
                sb.Append("$(CSLB){\n\t");
                sb.Append(selText);
                sb.Append("$(EntryPoint)");
                sb.Append("\n}\n$(Boundary)");

                ASGenerator.InsertCode(position, sb.ToString());
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }
コード例 #11
0
        /// <summary>
        /// The actual process implementation
        /// </summary>
        protected override void ExecutionImplementation()
        {
            IASContext         context = ASContext.Context;
            ScintillaControl   sci     = PluginBase.MainForm.CurrentDocument.SciControl;
            Int32              pos     = sci.CurrentPos;
            List <MemberModel> imports = new List <MemberModel>(context.CurrentModel.Imports.Items);
            int cppPpStyle             = (int)ScintillaNet.Lexers.CPP.PREPROCESSOR;

            for (Int32 i = imports.Count - 1; i >= 0; i--)
            {
                bool isPP = sci.LineIsInPreprocessor(sci, cppPpStyle, imports[i].LineTo);
                if ((imports[i].Flags & (FlagType.Using | FlagType.Constant)) != 0 || isPP)
                {
                    imports.RemoveAt(i);
                }
            }
            imports.Sort(new ImportsComparerLine());
            if (sci.ConfigurationLanguage == "haxe")
            {
                if (context.CurrentModel.Classes.Count > 0)
                {
                    Int32 start = sci.PositionFromLine(context.CurrentModel.Classes[0].LineFrom);
                    sci.SetSel(start, sci.Length);
                }
            }
            else
            {
                Int32 start = sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineFrom);
                Int32 end   = sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineTo);
                sci.SetSel(start, end);
            }
            String publicClassText  = sci.SelText;
            String privateClassText = "";

            if (context.CurrentModel.Classes.Count > 1)
            {
                sci.SetSel(pos, pos);
                sci.SetSel(sci.PositionFromLine(context.CurrentModel.Classes[1].LineFrom), sci.PositionFromLine(sci.LineCount));
                privateClassText = sci.SelText;
            }
            sci.BeginUndoAction();
            try
            {
                foreach (MemberModel import in imports)
                {
                    sci.GotoLine(import.LineFrom);
                    this.ImportIndents.Add(new KeyValuePair <MemberModel, Int32>(import, sci.GetLineIndentation(import.LineFrom)));
                    sci.LineDelete();
                }
                if (this.TruncateImports)
                {
                    for (Int32 j = 0; j < imports.Count; j++)
                    {
                        MemberModel import = imports[j];
                        String[]    parts  = import.Type.Split('.');
                        if (parts.Length > 0 && parts[parts.Length - 1] != "*")
                        {
                            parts[parts.Length - 1] = "*";
                        }
                        import.Type = String.Join(".", parts);
                    }
                }
                imports.Reverse();
                Imports separatedImports = this.SeparateImports(imports, context.CurrentModel.PrivateSectionIndex);
                if (separatedImports.PackageImports.Count > 0)
                {
                    InsertImports(separatedImports.PackageImports, publicClassText, sci, separatedImports.PackageImportsIndent);
                }
                if (context.CurrentModel.Classes.Count > 1 && separatedImports.PrivateImports.Count > 0)
                {
                    this.InsertImports(separatedImports.PrivateImports, privateClassText, sci, separatedImports.PrivateImportsIndent);
                }
                sci.SetSel(pos, pos);
            }
            finally
            {
                sci.EndUndoAction();
            }
            context.UpdateCurrentFile(true);
            this.FireOnRefactorComplete();
        }
コード例 #12
0
        /// <summary>
        /// The actual process implementation
        /// </summary>
        protected void ExecutionImplementation()
        {
            ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();
            try
            {
                string selection = sci.SelText;
                if (string.IsNullOrEmpty(selection))
                {
                    return;
                }

                if (selection.TrimStart().Length == 0)
                {
                    return;
                }

                sci.SetSel(sci.SelectionStart + selection.Length - selection.TrimStart().Length,
                           sci.SelectionEnd);
                sci.CurrentPos = sci.SelectionEnd;
                selection      = sci.SelText;

                int lineStart        = sci.LineFromPosition(sci.SelectionStart);
                int lineEnd          = sci.LineFromPosition(sci.SelectionEnd);
                int firstLineIndent  = sci.GetLineIndentation(lineStart);
                int entryPointIndent = 0;

                string snippet = GetSnippet(SnippetCode, sci.ConfigurationLanguage, sci.Encoding);
                int    pos     = snippet.IndexOfOrdinal("{0}");
                if (pos > -1)
                {
                    while (pos >= 0)
                    {
                        string c = snippet.Substring(--pos, 1);
                        if (c.Equals("\t"))
                        {
                            entryPointIndent += sci.Indent;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                for (int i = lineStart; i <= lineEnd; i++)
                {
                    int indent = sci.GetLineIndentation(i);
                    if (i > lineStart)
                    {
                        sci.SetLineIndentation(i, indent - firstLineIndent + entryPointIndent);
                    }
                }

                snippet = snippet.Replace("{0}", sci.SelText);

                int insertPos = sci.SelectionStart;
                int selEnd    = sci.SelectionEnd;

                sci.SetSel(insertPos, selEnd);
                SnippetHelper.InsertSnippetText(sci, insertPos, snippet);
            }
            finally
            {
                sci.EndUndoAction();
            }
        }
コード例 #13
0
        private void ReplaceAll()
        {
            if (comboBoxFindWhat.Text == "")
            {
                return;
            }

            TextView         view        = mManager.ActiveView as TextView;
            ScintillaControl editControl = view.ScintillaControl;

            bool   matchCase      = checkBoxMatchCase.Checked;
            bool   matchWholeWord = checkBoxMatchWholeWord.Checked;
            bool   useRegex       = checkBoxUseRegularExpressions.Checked;
            string findString     = comboBoxFindWhat.Text;

            int flags = 0;

            if (matchCase)
            {
                flags = flags | (int)Scintilla.Enums.FindOption.MatchCase;
            }
            if (matchWholeWord)
            {
                flags = flags | (int)Scintilla.Enums.FindOption.WholeWord;
            }
            if (useRegex)
            {
                flags = flags | (int)Scintilla.Enums.FindOption.RegularExpression;
            }

            editControl.SearchFlags = flags;
            editControl.TargetStart = 0;
            editControl.TargetEnd   = editControl.Length;

            int count = 0;

            try
            {
                editControl.BeginUndoAction();

                while (editControl.SearchInTarget(comboBoxFindWhat.Text) >= 0)
                {
                    if (useRegex)
                    {
                        editControl.ReplaceTargetRE(comboBoxReplaceWith.Text);
                    }
                    else
                    {
                        editControl.ReplaceTarget(comboBoxReplaceWith.Text);
                    }

                    editControl.TargetStart = editControl.TargetEnd + 1;
                    editControl.TargetEnd   = editControl.Length;

                    // Abort after first attempt, if file wasn't made writable
                    if (editControl.IsReadOnly)
                    {
                        mManager.SetStatusMessage("Replace all cancelled", 10.0f);
                        return;
                    }

                    ++count;
                }
            }
            finally
            {
                editControl.EndUndoAction();
            }

            if (count == 0)
            {
                SystemSounds.Exclamation.Play();
                mManager.SetStatusMessage(String.Format("Not found '{0}'", comboBoxFindWhat.Text), 10.0f);
            }
            else
            {
                mManager.SetStatusMessage(String.Format("Replaced {0} strings", count), 10.0f);
            }
        }
コード例 #14
0
        private void BaseForIn(bool aternate)
        {
            ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            sci.BeginUndoAction();

            // Settings
            String setAlt = this.settingObject.AlternateFunction.Trim();

            if (setAlt == "")
            {
                setAlt = "MyLogger.log";
            }
            Boolean setIns = this.settingObject.InsertNewLine;
            Boolean setCmp = this.settingObject.CompactMode;

            String tr0 = "for( var i:String in ";
            String tr1 = " ) trace( \"key : \" + i + \", value : \" + ";

            if (aternate)
            {
                tr1 = " ) " + setAlt + "( \"key : \" + i + \", value : \" + ";
            }
            String tr2 = "[ i ] );";

            if (setCmp)
            {
                tr0 = "for(var i:String in ";
                tr1 = ") trace(\"key: \"+i+\", value: \"+";
                if (aternate)
                {
                    tr1 = ") " + setAlt + "(\"key: \"+i+\", value: \"+";
                }
                tr2 = "[i]);";
            }

            PositionInfos t    = new PositionInfos(sci, sci.CurrentPos, PluginBase.MainForm.ProcessArgString(sArgsString));
            Boolean       exec = false;
            String        sel  = "";

            if (t.HasSelection)
            {
                if (!t.SelectionIsMultiline)
                {
                    sel  = t.SelectedText.Trim();
                    exec = true;
                }
            }
            else
            {
                if (t.WordFromPosition != "")
                {
                    sel  = t.WordFromPosition;
                    exec = true;
                }
            }

            if (exec)
            {
                HelpTools.SetCaretReadyToTrace(sci, true);

                String trace = tr0 + sel + tr1 + sel + tr2;

                sci.InsertText(sci.CurrentPos, trace);

                HelpTools.GoToLineEnd(sci, setIns);
            }

            sci.EndUndoAction();
        }
コード例 #15
0
    public static void Execute()
    {
        if (Globals.SciControl == null)
        {
            return;
        }

        ScintillaControl sci = Globals.SciControl;

        string selectStr = sci.SelText;

        if (selectStr.Length < 1)
        {
            MessageBox.Show("クラスにするコマンドを選択してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }

        Project project = (Project)PluginBase.CurrentProject;

        if (project == null)
        {
            return;
        }

        MainForm            mainForm            = (MainForm)Globals.MainForm;
        FlashDevelopActions flashDevelopActions = new FlashDevelopActions(mainForm);
        FileActions         fileActions         = new FileActions(mainForm, flashDevelopActions);

        if (!File.Exists(TEMP_PATH))
        {
            StreamWriter tmpWriter = new StreamWriter(TEMP_PATH, false, System.Text.Encoding.UTF8, 512);
            tmpWriter.Write(TMP_FILE);
            tmpWriter.Close();
        }

        ITabbedDocument currentDocument = (ITabbedDocument)mainForm.CurrentDocument;
        String          parentPath      = System.IO.Path.GetDirectoryName(currentDocument.FileName);

        fileActions.AddFileFromTemplate(project, parentPath, TEMP_PATH);
        String fileName = fileActions.ProcessArgs(project, "$(FileName)");

        String newFilePath = parentPath + "\\" + fileName + ".as";

        if (!File.Exists(newFilePath))
        {
            TraceManager.Add("キャンセルされました");
            return;
        }

        StreamReader reader = new StreamReader(newFilePath);
        String       value  = reader.ReadToEnd();

        reader.Close();

        StreamWriter writer = new StreamWriter(newFilePath, false, System.Text.Encoding.UTF8, 512);

        writer.Write(fileActions.ProcessArgs(project, value));
        writer.Close();

        string insText = "new " + fileName + "()";

        sci.BeginUndoAction();
        sci.Clear();
        sci.InsertText(sci.CurrentPos, insText);
        sci.SelectionStart = sci.CurrentPos;
        sci.SelectionEnd   = sci.CurrentPos + insText.Length;
        sci.EndUndoAction();
        TraceManager.Add(fileName + " が作成されました");
    }
コード例 #16
0
ファイル: XMLComplete.cs プロジェクト: wise0704/FlashDevelop
        /// <summary>
        /// Handles the incoming character
        /// </summary>
        public static void OnChar(ScintillaControl sci, Int32 value)
        {
            if (cType == XMLType.Invalid || (sci.ConfigurationLanguage != "xml" && sci.ConfigurationLanguage != "html"))
            {
                return;
            }
            XMLContextTag ctag;
            Int32         position = sci.CurrentPos;

            if (sci.BaseStyleAt(position) == 6 && value != '"')
            {
                return; // in XML attribute
            }
            Char      c = ' ';
            DataEvent de;

            switch (value)
            {
            case 10:
                // Shift+Enter to insert <BR/>
                Int32 line = sci.LineFromPosition(position);
                if (Control.ModifierKeys == Keys.Shift)
                {
                    ctag = GetXMLContextTag(sci, position);
                    if (ctag.Tag == null || ctag.Tag.EndsWith('>'))
                    {
                        int start = sci.PositionFromLine(line) - ((sci.EOLMode == 0)? 2:1);
                        sci.SetSel(start, position);
                        sci.ReplaceSel((PluginSettings.UpperCaseHtmlTags) ? "<BR/>" : "<br/>");
                        sci.SetSel(start + 5, start + 5);
                        return;
                    }
                }
                if (PluginSettings.SmartIndenter)
                {
                    // There is no standard for XML formatting, although most IDEs have similarities. We are mostly going with Visual Studio style with slight differences.
                    // Get last non-empty line.
                    String text  = "";
                    Int32  line2 = line - 1;
                    while (line2 >= 0 && text.Length == 0)
                    {
                        text = sci.GetLine(line2).TrimEnd();
                        line2--;
                    }
                    if ((text.EndsWith('>') && !text.EndsWithOrdinal("?>") && !text.EndsWithOrdinal("%>")) || text.EndsWithOrdinal("<!--") || text.EndsWithOrdinal("<![CDATA["))
                    {
                        // Get the previous tag.
                        do
                        {
                            position--;
                            c = (Char)sci.CharAt(position);
                        }while (position > 0 && c != '>');
                        ctag = GetXMLContextTag(sci, c == '>' ? position + 1 : position);
                        // Line indentation.
                        Int32 indent = sci.GetLineIndentation(line2 + 1);

                        String checkStart = null;
                        bool   subIndent  = true;
                        if (text.EndsWithOrdinal("<!--"))
                        {
                            checkStart = "-->"; subIndent = false;
                        }
                        else if (text.EndsWithOrdinal("<![CDATA["))
                        {
                            checkStart = "]]>"; subIndent = false;
                        }
                        else if (ctag.Closed || ctag.Closing)
                        {
                            //Closed tag. Look for the nearest open and not closed tag for proper indentation
                            subIndent = false;
                            if (ctag.Name != null)
                            {
                                var tmpTags = new Stack <XMLContextTag>();
                                var tmpTag  = ctag;

                                if (!tmpTag.Closed)
                                {
                                    tmpTags.Push(tmpTag);
                                }
                                while (tmpTag.Position != 0)
                                {
                                    tmpTag = GetXMLContextTag(sci, tmpTag.Position);
                                    if (tmpTag.Tag != null && tmpTag.Name != null)
                                    {
                                        if (tmpTag.Closed)
                                        {
                                            continue;
                                        }
                                        else if (tmpTag.Closing)
                                        {
                                            tmpTags.Push(tmpTag);
                                        }
                                        else
                                        {
                                            if (tmpTags.Count > 0 && tmpTags.Peek().Name == tmpTag.Name)
                                            {
                                                tmpTags.Pop();
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (tmpTags.Count > 0)
                                {
                                    indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTags.Pop().Position));
                                }
                                else if (tmpTag.Name != null)
                                {
                                    subIndent  = true;
                                    checkStart = "</" + tmpTag.Name;
                                    indent     = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position));
                                }
                                else
                                {
                                    indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position));
                                }
                            }
                        }
                        else if (ctag.Name != null)
                        {
                            // Indentation. Some IDEs use the tag position, VS uses the tag start line indentation.
                            indent     = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position));
                            checkStart = "</" + ctag.Name;
                            if (ctag.Name.ToLower() == "script" || ctag.Name.ToLower() == "style")
                            {
                                subIndent = false;
                            }
                        }
                        try
                        {
                            sci.BeginUndoAction();
                            if (checkStart != null)
                            {
                                text = sci.GetLine(line).TrimStart();
                                if (text.StartsWithOrdinal(checkStart))
                                {
                                    sci.SetLineIndentation(line, indent);
                                    sci.InsertText(sci.PositionFromLine(line), LineEndDetector.GetNewLineMarker(sci.EOLMode));
                                }
                            }
                            // Indent the code
                            if (subIndent)
                            {
                                indent += sci.Indent;
                            }
                            sci.SetLineIndentation(line, indent);
                            position = sci.LineIndentPosition(line);
                            sci.SetSel(position, position);
                        }
                        finally { sci.EndUndoAction(); }
                        return;
                    }
                    else if (!text.EndsWith('>'))
                    {
                        ctag = GetXMLContextTag(sci, sci.CurrentPos);
                        if (ctag.Tag == null || ctag.Name == null)
                        {
                            return;
                        }
                        // We're inside a tag. Visual Studio indents with regards to the first line, other IDEs indent using the indentation of the last line with text.
                        int    indent;
                        string tag = (ctag.Tag.IndexOf('\r') > 0 || ctag.Tag.IndexOf('\n') > 0) ? ctag.Tag.Substring(0, ctag.Tag.IndexOfAny(new[] { '\r', '\n' })).TrimEnd() : ctag.Tag.TrimEnd();
                        if (tag.EndsWith('\"'))
                        {
                            int i;
                            int l = tag.Length;
                            for (i = ctag.Name.Length + 1; i < l; i++)
                            {
                                if (!char.IsWhiteSpace(tag[i]))
                                {
                                    break;
                                }
                            }
                            indent = sci.Column(ctag.Position) + sci.MBSafePosition(i);
                        }
                        else
                        {
                            indent = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position)) + sci.Indent;
                        }

                        sci.SetLineIndentation(line, indent);
                        position = sci.LineIndentPosition(line);
                        sci.SetSel(position, position);
                        return;
                    }
                }
                break;

            case '<':
            case '/':
                if (value == '/')
                {
                    if ((position < 2) || ((Char)sci.CharAt(position - 2) != '<'))
                    {
                        return;
                    }
                    ctag          = new XMLContextTag();
                    ctag.Position = position - 2;
                    ctag.Closing  = true;
                }
                else
                {
                    ctag = GetXMLContextTag(sci, position);
                    if (ctag.Tag != null)
                    {
                        return;
                    }
                }
                // Allow another plugin to handle this
                de = new DataEvent(EventType.Command, "XMLCompletion.Element", ctag);
                EventManager.DispatchEvent(PluginBase.MainForm, de);
                if (de.Handled)
                {
                    return;
                }

                // New tag
                if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known)
                {
                    List <ICompletionListItem> items = new List <ICompletionListItem>();
                    String previous = null;
                    foreach (string ns in namespaces)
                    {
                        items.Add(new NamespaceItem(ns));
                    }
                    foreach (HTMLTag tag in knownTags)
                    {
                        if (tag.Name != previous && (tag.NS == "" || tag.NS == defaultNS))
                        {
                            items.Add(new HtmlTagItem(tag.Name, tag.Tag));
                            previous = tag.Name;
                        }
                    }
                    items.Sort(new ListItemComparer());
                    CompletionList.Show(items, true);
                }
                return;

            case ':':
                ctag = GetXMLContextTag(sci, position);
                if (ctag.NameSpace == null || position - ctag.Position > ctag.Name.Length + 2)
                {
                    return;
                }
                // Allow another plugin to handle this
                de = new DataEvent(EventType.Command, "XMLCompletion.Namespace", ctag);
                EventManager.DispatchEvent(PluginBase.MainForm, de);
                if (de.Handled)
                {
                    return;
                }

                // Show namespace's tags
                if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known)
                {
                    List <ICompletionListItem> items = new List <ICompletionListItem>();
                    String previous = null;
                    foreach (HTMLTag tag in knownTags)
                    {
                        if (tag.Name != previous && tag.NS == ctag.NameSpace)
                        {
                            items.Add(new HtmlTagItem(tag.Name, tag.Name));
                            previous = tag.Name;
                        }
                    }
                    CompletionList.Show(items, true);
                }
                return;

            case '>':
                if (PluginSettings.CloseTags)
                {
                    ctag = GetXMLContextTag(sci, position);
                    if (ctag.Name != null && !ctag.Closed)
                    {
                        // Allow another plugin to handle this
                        de = new DataEvent(EventType.Command, "XMLCompletion.CloseElement", ctag);
                        EventManager.DispatchEvent(PluginBase.MainForm, de);
                        if (de.Handled)
                        {
                            return;
                        }

                        if (ctag.Closing)
                        {
                            return;
                        }

                        Boolean isLeaf = false;
                        if (cType == XMLType.Known)
                        {
                            foreach (HTMLTag tag in knownTags)
                            {
                                if (String.Compare(tag.Tag, ctag.Name, true) == 0)
                                {
                                    isLeaf = tag.IsLeaf;
                                    break;
                                }
                            }
                        }
                        if (isLeaf)
                        {
                            sci.SetSel(position - 1, position);
                            sci.ReplaceSel("/>");
                            sci.SetSel(position + 1, position + 1);
                        }
                        else
                        {
                            String closeTag = "</" + ctag.Name + ">";
                            sci.ReplaceSel(closeTag);
                            sci.SetSel(position, position);
                        }
                    }
                }
                return;

            case ' ':
                c = (char)sci.CharAt(position);
                if (c > 32 && c != '/' && c != '>' && c != '<')
                {
                    return;
                }
                ctag = GetXMLContextTag(sci, position);
                if (ctag.Tag != null)
                {
                    if (InQuotes(ctag.Tag) || ctag.Tag.LastIndexOf('"') < ctag.Tag.LastIndexOf('='))
                    {
                        return;
                    }
                    // Allow another plugin to handle this
                    Object[] obj = new Object[] { ctag, "" };
                    de = new DataEvent(EventType.Command, "XMLCompletion.Attribute", obj);
                    EventManager.DispatchEvent(PluginBase.MainForm, de);
                    if (de.Handled)
                    {
                        return;
                    }

                    if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known)
                    {
                        foreach (HTMLTag tag in knownTags)
                        {
                            if (String.Compare(tag.Tag, ctag.Name, true) == 0)
                            {
                                List <ICompletionListItem> items = new List <ICompletionListItem>();
                                String previous = null;
                                foreach (String attr in tag.Attributes)
                                {
                                    if (attr != previous)
                                    {
                                        items.Add(new HtmlAttributeItem(attr));
                                        previous = attr;
                                    }
                                }
                                CompletionList.Show(items, true);
                                return;
                            }
                        }
                    }
                }

                /*else
                 * {
                 *  if (Control.ModifierKeys == Keys.Shift)
                 *  {
                 *      sci.SetSel(position - 1, position);
                 *      sci.ReplaceSel("&nbsp;");
                 *  }
                 * }*/
                return;

            case '=':
                if (PluginSettings.InsertQuotes)
                {
                    ctag     = GetXMLContextTag(sci, position);
                    position = sci.CurrentPos - 2;
                    if (ctag.Tag != null && !String.IsNullOrEmpty(ctag.Name) && Char.IsLetter(ctag.Name[0]) &&
                        !InQuotes(ctag.Tag) && (GetWordLeft(sci, ref position).Length > 0))
                    {
                        position = sci.CurrentPos;
                        c        = (Char)sci.CharAt(position);
                        if (c > 32 && c != '>')
                        {
                            sci.ReplaceSel("\"\" ");
                        }
                        else
                        {
                            sci.ReplaceSel("\"\"");
                        }
                        sci.SetSel(position + 1, position + 1);
                        justInsertedQuotesAt = position + 1;
                        // Allow another plugin to handle this
                        de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty });
                        EventManager.DispatchEvent(PluginBase.MainForm, de);
                    }
                }
                return;

            case '"':
                ctag = GetXMLContextTag(sci, position);
                if (position > 1 && ctag.Tag != null && !ctag.Tag.StartsWithOrdinal("<!"))
                {
                    // TODO  Colorize text change to highlight what's been done
                    if (justInsertedQuotesAt == position - 1)
                    {
                        justInsertedQuotesAt = -1;
                        c = (Char)sci.CharAt(position - 2);
                        if (c == '"' && (Char)sci.CharAt(position - 2) == '"')
                        {
                            sci.SetSel(position - 2, position);
                            sci.ReplaceSel("\"");
                        }
                        // Allow another plugin to handle this
                        de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty });
                        EventManager.DispatchEvent(PluginBase.MainForm, de);
                    }
                    else
                    {
                        c = (Char)sci.CharAt(position - 1);
                        if (c == '"' && (Char)sci.CharAt(position) == '"')
                        {
                            sci.SetSel(position - 1, position + 1);
                            sci.ReplaceSel("\"");
                        }
                    }
                }
                break;

            case '?':
            case '%':
                if (PluginSettings.CloseTags && position > 1)
                {
                    ctag = GetXMLContextTag(sci, position - 2);
                    if (ctag.Tag == null || ctag.Tag.EndsWith('>'))
                    {
                        if ((Char)sci.CharAt(position - 2) == '<')
                        {
                            sci.ReplaceSel((Char)value + ">");
                            sci.SetSel(position, position);
                        }
                    }
                }
                break;

            case '!':
                if (PluginSettings.CloseTags && position > 1)
                {
                    ctag = GetXMLContextTag(sci, position - 2);
                    if (ctag.Tag == null || ctag.Tag.EndsWith('>'))
                    {
                        if ((Char)sci.CharAt(position - 2) == '<')
                        {
                            CompletionList.Show(xmlBlocks, true);
                        }
                    }
                }
                break;
            }
        }
コード例 #17
0
        /// <summary>
        /// Add closing brace to a code block.
        /// If enabled, move the starting brace to a new line.
        /// </summary>
        /// <param name="Sci"></param>
        /// <param name="txt"></param>
        /// <param name="line"></param>
        public static void AutoCloseBrace(ScintillaControl Sci, int line)
        {
            // find matching brace
            int bracePos = Sci.LineEndPosition(line - 1) - 1;

            while ((bracePos > 0) && (Sci.CharAt(bracePos) != '{'))
            {
                bracePos--;
            }
            if (bracePos == 0 || Sci.BaseStyleAt(bracePos) != 5)
            {
                return;
            }
            int match  = Sci.SafeBraceMatch(bracePos);
            int start  = line;
            int indent = Sci.GetLineIndentation(start - 1);

            if (match > 0)
            {
                int endIndent = Sci.GetLineIndentation(Sci.LineFromPosition(match));
                if (endIndent + Sci.TabWidth > indent)
                {
                    return;
                }
            }

            // find where to include the closing brace
            int    startIndent = indent;
            int    count       = Sci.LineCount;
            int    lastLine    = line;
            int    position;
            string txt = Sci.GetLine(line).Trim();

            line++;
            int    eolMode = Sci.EOLMode;
            string NL      = LineEndDetector.GetNewLineMarker(eolMode);

            if (txt.Length > 0 && ")]};,".IndexOf(txt[0]) >= 0)
            {
                Sci.BeginUndoAction();
                try
                {
                    position = Sci.CurrentPos;
                    Sci.InsertText(position, NL + "}");
                    Sci.SetLineIndentation(line, startIndent);
                }
                finally
                {
                    Sci.EndUndoAction();
                }
                return;
            }
            else
            {
                while (line < count - 1)
                {
                    txt = Sci.GetLine(line).TrimEnd();
                    if (txt.Length != 0)
                    {
                        indent = Sci.GetLineIndentation(line);
                        if (indent <= startIndent)
                        {
                            break;
                        }
                        lastLine = line;
                    }
                    else
                    {
                        break;
                    }
                    line++;
                }
            }
            if (line >= count - 1)
            {
                lastLine = start;
            }

            // insert closing brace
            Sci.BeginUndoAction();
            try
            {
                position = Sci.LineEndPosition(lastLine);
                Sci.InsertText(position, NL + "}");
                Sci.SetLineIndentation(lastLine + 1, startIndent);
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }
コード例 #18
0
ファイル: SaveAsClasses.cs プロジェクト: Dsnoi/flashdevelopjp
	public static void Execute()
	{
		if ( Globals.SciControl == null ) return;
		ScintillaControl sci = Globals.SciControl;

		MainForm mainForm = (MainForm) Globals.MainForm;

		ITabbedDocument document = mainForm.CurrentDocument;

		String documentDirectory = Path.GetDirectoryName(document.FileName);

		ASContext context = (ASContext) ASContext.Context;
		string currentPackage = context.CurrentModel.Package;
		List<ClassModel> classes = context.CurrentModel.Classes;
		MemberList imports = context.CurrentModel.Imports;
		
		sci.BeginUndoAction();
		
		String pattern = "}";
		FRSearch search = new FRSearch(pattern);
		search.Filter = SearchFilter.None;
		List<SearchMatch> matches = search.Matches(sci.Text);
		if (matches == null || matches.Count == 0) return;
		if (classes.Count < 2) return;
		
		SearchMatch match = GetNextDocumentMatch(sci, matches, sci.PositionFromLine(classes[0].LineTo + 1));
		
		Int32 packageEnd = sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value); // wchar to byte text length
		
		String strImport = "";
		
		if (imports.Count > 0)
		{
			for (int i=imports.Count-1; i>0; --i ) 
			{
				MemberModel import = imports[i];
				if(packageEnd < sci.PositionFromLine(import.LineFrom)) {
					sci.SelectionStart = sci.PositionFromLine(import.LineFrom);
					sci.SelectionEnd = sci.PositionFromLine(import.LineTo + 1);
					strImport = sci.SelText + strImport;
					sci.Clear();
				}
			}
		}
		
		context.UpdateCurrentFile(true);
		
		Int32 prevClassEnd = packageEnd;
		
		foreach (ClassModel currentClass in classes)
		{
			// 最初のクラスは無視
			if (currentClass == classes[0]) continue;
			
			sci.SelectionStart = prevClassEnd;
			sci.SelectionEnd = sci.PositionFromLine(currentClass.LineTo + 1);
			
			String content = "package "
					   + currentPackage
					   + "\n{\n"
					   + Regex.Replace( strImport, @"^", "\t", RegexOptions.Multiline)
					   + Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline)
					   + "\n}\n";
					   
			prevClassEnd = sci.PositionFromLine(currentClass.LineTo + 1);
			
			Encoding encoding = sci.Encoding;
			String file = documentDirectory + "\\" + currentClass.Name + ".as";
			FileHelper.WriteFile(file, content, encoding);
		}
		
		sci.SelectionStart = packageEnd;
		sci.Clear();		
		sci.EndUndoAction();
	}
コード例 #19
0
ファイル: AbstractTextEditor.cs プロジェクト: ngoffee/ela
 void ITextEditor.BeginUndoAction()
 {
     sci.BeginUndoAction();
 }
コード例 #20
0
        public void Execute()
        {
            Sci = PluginBase.MainForm.CurrentDocument.SciControl;
            Sci.BeginUndoAction();
            try
            {
                IASContext context = ASContext.Context;
                Int32      pos     = Sci.CurrentPos;

                string expression = Sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' });
                expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' });
                expression = expression.TrimStart(new char[] { ')', ']', '}', '>' });

                cFile = ASContext.Context.CurrentModel;
                ASFileParser parser = new ASFileParser();
                parser.ParseSrc(cFile, Sci.Text);

                MemberModel current = cFile.Context.CurrentMember;

                string characterClass = ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;

                int funcBodyStart = ASGenerator.GetBodyStart(current.LineFrom, current.LineTo, Sci);
                Sci.SetSel(funcBodyStart, Sci.LineEndPosition(current.LineTo));
                string currentMethodBody = Sci.SelText;

                bool isExprInSingleQuotes = (expression.StartsWith("'") && expression.EndsWith("'"));
                bool isExprInDoubleQuotes = (expression.StartsWith("\"") && expression.EndsWith("\""));
                int  stylemask            = (1 << Sci.StyleBits) - 1;
                int  lastPos = -1;
                char prevOrNextChar;
                Sci.Colourise(0, -1);
                while (true)
                {
                    lastPos = currentMethodBody.IndexOf(expression, lastPos + 1);
                    if (lastPos > -1)
                    {
                        if (lastPos > 0)
                        {
                            prevOrNextChar = currentMethodBody[lastPos - 1];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }
                        if (lastPos + expression.Length < currentMethodBody.Length)
                        {
                            prevOrNextChar = currentMethodBody[lastPos + expression.Length];
                            if (characterClass.IndexOf(prevOrNextChar) > -1)
                            {
                                continue;
                            }
                        }

                        int style = Sci.StyleAt(funcBodyStart + lastPos) & stylemask;
                        if (ASComplete.IsCommentStyle(style))
                        {
                            continue;
                        }
                        else if ((isExprInDoubleQuotes && currentMethodBody[lastPos] == '"' && currentMethodBody[lastPos + expression.Length - 1] == '"') ||
                                 (isExprInSingleQuotes && currentMethodBody[lastPos] == '\'' && currentMethodBody[lastPos + expression.Length - 1] == '\''))
                        {
                        }
                        else if (!ASComplete.IsTextStyle(style))
                        {
                            continue;
                        }

                        Sci.SetSel(funcBodyStart + lastPos, funcBodyStart + lastPos + expression.Length);
                        Sci.ReplaceSel(NewName);
                        currentMethodBody = currentMethodBody.Substring(0, lastPos) + NewName + currentMethodBody.Substring(lastPos + expression.Length);
                        lastPos          += NewName.Length;
                    }
                    else
                    {
                        break;
                    }
                }

                Sci.CurrentPos = funcBodyStart;
                Sci.SetSel(Sci.CurrentPos, Sci.CurrentPos);

                string snippet = "var " + NewName + ":$(EntryPoint) = " + expression + ";\n$(Boundary)";
                SnippetHelper.InsertSnippetText(Sci, Sci.CurrentPos, snippet);
            }
            finally
            {
                Sci.EndUndoAction();
            }
        }