Example #1
0
 /// <summary>
 /// Modifies the specified CommandBar item
 /// </summary>
 public static void ExecuteFlagAction(ToolStripItem item, String action, Boolean value)
 {
     if (action.StartsWithOrdinal("Check:"))
     {
         if (item is ToolStripMenuItem)
         {
             ((ToolStripMenuItem)item).Checked = value;
         }
     }
     else if (action.StartsWithOrdinal("Uncheck:"))
     {
         if (item is ToolStripMenuItem)
         {
             ((ToolStripMenuItem)item).Checked = !value;
         }
     }
     else if (action.StartsWithOrdinal("Enable:"))
     {
         item.Enabled = value;
     }
     else if (action.StartsWithOrdinal("Disable:"))
     {
         item.Enabled = !value;
     }
     else if (action.StartsWithOrdinal("Visible:"))
     {
         item.Visible = value;
     }
     else if (action.StartsWithOrdinal("Invisible:"))
     {
         item.Visible = !value;
     }
 }
Example #2
0
 /// <summary>
 /// Resolve a path which may be:
 /// - absolute or
 /// - relative to a specified path, or 
 /// - relative to base path
 /// </summary>
 public static String ResolvePath(String path, String relativeTo)
 {
     if (string.IsNullOrEmpty(path)) return null;
     Boolean isPathNetworked = path.StartsWithOrdinal("\\\\") || path.StartsWithOrdinal("//");
     Boolean isPathAbsSlashed = (path.StartsWith('\\') || path.StartsWith('/')) && !isPathNetworked;
     if (isPathAbsSlashed) path = Path.GetPathRoot(AppDir) + path.Substring(1);
     if (Path.IsPathRooted(path) || isPathNetworked) return path;
     String resolvedPath;
     if (relativeTo != null)
     {
         resolvedPath = Path.Combine(relativeTo, path);
         if (Directory.Exists(resolvedPath) || File.Exists(resolvedPath)) return resolvedPath;
     }
     if (!PluginBase.MainForm.StandaloneMode)
     {
         resolvedPath = Path.Combine(UserAppDir, path);
         if (Directory.Exists(resolvedPath) || File.Exists(resolvedPath)) return resolvedPath;
     }
     resolvedPath = Path.Combine(AppDir, path);
     if (Directory.Exists(resolvedPath) || File.Exists(resolvedPath)) return resolvedPath;
     return null;
 }
 /// <summary>
 /// Updates the shortcut if it changes or needs updating
 /// </summary>
 public static void UpdateShortcut(String id, Keys shortcut)
 {
     if (id.StartsWithOrdinal("Scintilla.")) shortcutOverrides[id].keys = shortcut;
 }
 public static Boolean IsUnderSDKPath(String file)
 {
     InstalledSDK sdk = PluginBase.CurrentSDK;
     if (sdk != null && !String.IsNullOrEmpty(sdk.Path) && file.StartsWithOrdinal(sdk.Path)) return true;
     return false;
 }
 /// <summary>
 /// Checks if files is related to the project
 /// TODO support SWCs -> refactor test as IProject method
 /// </summary>
 public static Boolean IsProjectRelatedFile(IProject project, String file)
 {
     if (project == null) return false;
     IASContext context = ASContext.GetLanguageContext(project.Language);
     if (context == null) return false;
     foreach (PathModel pathModel in context.Classpath)
     {
         string absolute = project.GetAbsolutePath(pathModel.Path);
         if (file.StartsWithOrdinal(absolute)) return true;
     }
     // If no source paths are defined, is it under the project?
     if (project.SourcePaths.Length == 0)
     {
         String projRoot = Path.GetDirectoryName(project.ProjectPath);
         if (file.StartsWithOrdinal(projRoot)) return true;
     }
     return false;
 }
 /// <summary>
 /// Creates a new editor control for the document
 /// </summary>
 public static ScintillaControl CreateControl(String file, String text, Int32 codepage)
 {
     Initialize();
     ScintillaControl sci = new ScintillaControl();
     sci.AutoCSeparator = 32;
     sci.AutoCTypeSeparator = 63;
     sci.IsAutoCGetAutoHide = true;
     sci.IsAutoCGetCancelAtStart = false;
     sci.IsAutoCGetChooseSingle = false;
     sci.IsAutoCGetDropRestOfWord = false;
     sci.IsAutoCGetIgnoreCase = false;
     sci.ControlCharSymbol = 0;
     sci.CurrentPos = 0;
     sci.CursorType = -1;
     sci.Dock = DockStyle.Fill;
     sci.EndAtLastLine = 0;
     sci.EdgeColumn = 0;
     sci.EdgeMode = 0;
     sci.IsMouseDownCaptures = true;
     sci.IsBufferedDraw = true;
     sci.IsOvertype = false;
     sci.IsReadOnly = false;
     sci.IsUndoCollection = true;
     sci.IsUsePalette = true;
     sci.IsTwoPhaseDraw = true;
     sci.LayoutCache = 1;
     sci.Lexer = 3;
     sci.Location = new Point(0, 0);
     sci.MarginLeft = 5;
     sci.MarginRight = 5;
     sci.ModEventMask = (Int32)ModificationFlags.InsertText | (Int32)ModificationFlags.DeleteText | (Int32)ModificationFlags.RedoPerformed | (Int32)ModificationFlags.UndoPerformed;
     sci.MouseDwellTime = ScintillaControl.MAXDWELLTIME;
     sci.Name = "sci";
     sci.PasteConvertEndings = false;
     sci.PrintColourMode = (Int32)PrintOption.Normal;
     sci.PrintWrapMode = (Int32)Wrap.Word;
     sci.PrintMagnification = 0;
     sci.SearchFlags = 0;
     sci.SelectionEnd = 0;
     sci.SelectionMode = 0;
     sci.SelectionStart = 0;
     sci.SmartIndentType = SmartIndent.CPP;
     sci.Status = 0;
     sci.StyleBits = 7;
     sci.TabIndex = 0;
     sci.TargetEnd = 0;
     sci.TargetStart = 0;
     sci.WrapStartIndent = PluginBase.Settings.IndentSize;
     sci.WrapVisualFlagsLocation = (Int32)WrapVisualLocation.EndByText;
     sci.WrapVisualFlags = (Int32)WrapVisualFlag.End;
     sci.XOffset = 0;
     sci.ZoomLevel = 0;
     sci.UsePopUp(false);
     sci.SetMarginTypeN(0, (Int32)MarginType.Symbol);
     sci.SetMarginMaskN(0, MarkerManager.MARKERS);
     sci.SetMarginWidthN(0, ScaleHelper.Scale(14));
     sci.SetMarginTypeN(1, (Int32)MarginType.Number);
     sci.SetMarginMaskN(1, (Int32)MarginType.Symbol);
     sci.SetMarginTypeN(2, (Int32)MarginType.Symbol);
     sci.SetMarginMaskN(2, -33554432 | 1 << 2);
     sci.MarginSensitiveN(2, true);
     sci.SetMultiSelectionTyping(true);
     sci.MarkerDefineRGBAImage(0, Bookmark);
     sci.MarkerDefine(2, MarkerSymbol.Fullrect);
     sci.MarkerDefine((Int32)MarkerOutline.Folder, MarkerSymbol.BoxPlus);
     sci.MarkerDefine((Int32)MarkerOutline.FolderOpen, MarkerSymbol.BoxMinus);
     sci.MarkerDefine((Int32)MarkerOutline.FolderSub, MarkerSymbol.VLine);
     sci.MarkerDefine((Int32)MarkerOutline.FolderTail, MarkerSymbol.LCorner);
     sci.MarkerDefine((Int32)MarkerOutline.FolderEnd, MarkerSymbol.BoxPlusConnected);
     sci.MarkerDefine((Int32)MarkerOutline.FolderOpenMid, MarkerSymbol.BoxMinusConnected);
     sci.MarkerDefine((Int32)MarkerOutline.FolderMidTail, MarkerSymbol.TCorner);
     sci.SetXCaretPolicy((Int32)CaretPolicy.Even, 0); // Match edge...
     sci.SetYCaretPolicy((Int32)CaretPolicy.Even, 0); // Match edge...
     sci.ScrollWidthTracking = (PluginBase.Settings.ScrollWidth == 3000);
     sci.CodePage = 65001; // Editor handles text as UTF-8
     sci.Encoding = Encoding.GetEncoding(codepage);
     sci.SaveBOM = IsUnicode(codepage) && PluginBase.Settings.SaveUnicodeWithBOM;
     sci.Text = text; sci.FileName = file; // Set text and save file name
     sci.Modified += new ModifiedHandler(Globals.MainForm.OnScintillaControlModified);
     sci.MarginClick += new MarginClickHandler(Globals.MainForm.OnScintillaControlMarginClick);
     sci.UpdateUI += new UpdateUIHandler(Globals.MainForm.OnScintillaControlUpdateControl);
     sci.URIDropped += new URIDroppedHandler(Globals.MainForm.OnScintillaControlDropFiles);
     sci.ModifyAttemptRO += new ModifyAttemptROHandler(Globals.MainForm.OnScintillaControlModifyRO);
     String untitledFileStart = TextHelper.GetString("Info.UntitledFileStart");
     if (!file.StartsWithOrdinal(untitledFileStart)) sci.IsReadOnly = FileHelper.FileIsReadOnly(file);
     sci.SetFoldFlags((Int32)PluginBase.Settings.FoldFlags);
     sci.EmptyUndoBuffer(); ApplySciSettings(sci);
     UITools.Manager.ListenTo(sci);
     return sci;
 }
 /// <summary>
 /// Check if file is hidden in project
 /// </summary>
 private Boolean IsFileHidden(String file, IProject project)
 {
     String[] hiddenPaths = project.GetHiddenPaths();
     foreach (String hiddenPath in hiddenPaths)
     {
         String absHiddenPath = project.GetAbsolutePath(hiddenPath);
         if (Directory.Exists(absHiddenPath) && file.StartsWithOrdinal(absHiddenPath)) return true;
     }
     return false;
 }
 public static String ResolvePath(String path, String relativeTo)
 {
     if (string.IsNullOrEmpty(path)) return null;
     Boolean isPathNetworked = path.StartsWithOrdinal("\\\\") || path.StartsWithOrdinal("//");
     if (Path.IsPathRooted(path) || isPathNetworked) return path;
     String resolvedPath = Path.Combine(relativeTo, path);
     if (Directory.Exists(resolvedPath) || File.Exists(resolvedPath)) return resolvedPath;
     return null;
 }
Example #9
0
 /// <summary>
 /// Converts a String to a color (BGR order)
 /// </summary>
 public static Int32 StringToColor(String aColor)
 {
     if (aColor != null)
     {
         Color c = Color.FromName(aColor);
         if (c.ToArgb() == 0 && aColor.Length >= 6)
         {
             Int32 col = 0;
             if (aColor.StartsWithOrdinal("0x")) Int32.TryParse(aColor.Substring(2), NumberStyles.HexNumber, null, out col);
             else Int32.TryParse(aColor, out col);
             return TO_COLORREF(col);
         }
         return TO_COLORREF(c.ToArgb() & 0x00ffffff);
     }
     return 0;
 }
Example #10
0
 /// <summary>
 /// Gets a localized string if available
 /// </summary>
 private static String GetLocalizedString(String key)
 {
     try
     {
         if (!key.StartsWithOrdinal("Label.")) return key;
         else return TextHelper.GetString(key);
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
         return String.Empty;
     }
 }