public static string GuessMimeType(string fileName) { // Guess the mime type of the new file string fn = Path.GetTempFileName(); string ext = Path.GetExtension(fileName); int n = 0; while (File.Exists(fn + n + ext)) { n++; } FileService.MoveFile(fn, fn + n + ext); string mimeType = DesktopService.GetMimeTypeForUri(fn + n + ext); FileService.DeleteFile(fn + n + ext); if (string.IsNullOrEmpty(mimeType)) { mimeType = "text"; } return(mimeType); }
void GetItemMimeTypes(HashSet <string> types, SolutionItem item) { if (item is SolutionFolder) { foreach (SolutionItem it in ((SolutionFolder)item).Items) { GetItemMimeTypes(types, it); } } else if (item is Project) { foreach (ProjectFile pf in ((Project)item).Files) { string mt = DesktopService.GetMimeTypeForUri(pf.FilePath); foreach (string mth in DesktopService.GetMimeTypeInheritanceChain(mt)) { types.Add(mth); } } } }
void PositionWidget(Gtk.Widget widget) { if (!(widget is Gtk.Window)) { return; } int ox, oy; ParentWindow.GetOrigin(out ox, out oy); int w; int itemXPosition = GetHoverXPosition(out w); int dx = ox + this.Allocation.X + itemXPosition; int dy = oy + this.Allocation.Bottom; var req = widget.SizeRequest(); Xwt.Rectangle geometry = DesktopService.GetUsableMonitorGeometry(Screen.Number, Screen.GetMonitorAtPoint(dx, dy)); int geomWidth = (int)geometry.Width; int geomLeft = (int)geometry.Left; int geomRight = (int)geometry.Right; int width = System.Math.Max(req.Width, w); if (width >= geomWidth - spacing * 2) { width = geomWidth - spacing * 2; dx = geomLeft + spacing; } widget.WidthRequest = width; if (dy + req.Height > geometry.Bottom) { dy = oy + this.Allocation.Y - req.Height; } if (dx + width > geomRight) { dx = geomRight - width; } (widget as Gtk.Window).Move(dx, dy); (widget as Gtk.Window).Resize(width, req.Height); widget.GrabFocus(); }
public static void DispatchLink(string uri) { try { if (uri.StartsWith("project://")) { string file = uri.Substring("project://".Length); Gdk.ModifierType mtype = GtkWorkarounds.GetCurrentKeyModifiers(); bool inWorkspace = (mtype & Gdk.ModifierType.ControlMask) != 0; // Notify the RecentFiles that this item does not exist anymore. // Possible other solution would be to check the recent projects list on focus in // and update them accordingly. if (!System.IO.File.Exists(file)) { var res = MessageService.AskQuestion( GettextCatalog.GetString("{0} could not be opened", file), GettextCatalog.GetString("Do you want to remove the reference to it from the Recent list?"), AlertButton.No, AlertButton.Yes); if (res == AlertButton.Yes) { FileService.NotifyFileRemoved(file); } return; } IdeApp.Workspace.OpenWorkspaceItem(file, !inWorkspace); } else if (uri.StartsWith("monodevelop://")) { var cmdId = uri.Substring("monodevelop://".Length); IdeApp.CommandService.DispatchCommand(cmdId, MonoDevelop.Components.Commands.CommandSource.WelcomePage); } else { DesktopService.ShowUrl(uri); } } catch (Exception ex) { LoggingService.LogInternalError(GettextCatalog.GetString("Could not open the url '{0}'", uri), ex); } }
public TooltipInformationWindow() : base() { TypeHint = Gdk.WindowTypeHint.Tooltip; this.SkipTaskbarHint = true; this.SkipPagerHint = true; this.AllowShrink = false; this.AllowGrow = false; this.CanFocus = false; this.CanDefault = false; this.Events |= Gdk.EventMask.EnterNotifyMask; headLabel = new FixedWidthWrapLabel(); headLabel.Indent = -20; headLabel.FontDescription = FontService.GetFontDescription("Editor").CopyModified(1.1); headLabel.Wrap = Pango.WrapMode.WordChar; headLabel.BreakOnCamelCasing = false; headLabel.BreakOnPunctuation = false; descriptionBox.Spacing = 4; VBox vb = new VBox(false, 8); vb.PackStart(headLabel, true, true, 4); vb.PackStart(descriptionBox, true, true, 4); HBox hb = new HBox(false, 4); hb.PackStart(vb, true, true, 6); WindowTransparencyDecorator.Attach(this); vb2.Spacing = 4; vb2.PackStart(hb, true, true, 0); ContentBox.Add(vb2); SetDefaultScheme(); ShowAll(); DesktopService.RemoveWindowShadow(this); }
protected override void Run(object tool) { Document doc = IdeApp.Workbench.ActiveDocument; if (doc == null) { return; } string mt = DesktopService.GetMimeTypeForUri(doc.FileName); var formatter = CodeFormatterService.GetFormatter(mt); if (formatter == null || !doc.Editor.IsSomethingSelected) { return; } var selection = doc.Editor.SelectionRange; using (var undo = doc.Editor.OpenUndoGroup()) { var version = doc.Editor.Version; if (formatter.SupportsOnTheFlyFormatting) { formatter.OnTheFlyFormat(doc, selection.Offset, selection.EndOffset); } else { var pol = doc.Project != null ? doc.Project.Policies : null; string text = formatter.FormatText(pol, doc.Editor.Text, selection.Offset, selection.EndOffset); if (text != null) { doc.Editor.Replace(selection.Offset, selection.Length, text); } } int newOffset = version.MoveOffsetTo(doc.Editor.Version, selection.Offset); int newEndOffset = version.MoveOffsetTo(doc.Editor.Version, selection.EndOffset); doc.Editor.SetSelection(newOffset, newEndOffset); } }
internal static bool ShowWindow(ICompletionDataList list, CodeCompletionContext completionContext) { if (wnd == null || !isShowing) { return(false); } var completionWidget = wnd.CompletionWidget; var ext = wnd.Extension; try { try { isShowing = false; if (!wnd.ShowListWindow(list, completionContext)) { if (list is IDisposable) { ((IDisposable)list).Dispose(); } HideWindow(); return(false); } if (IdeApp.Preferences.ForceSuggestionMode) { wnd.AutoSelect = false; } wnd.Show(); DesktopService.RemoveWindowShadow(wnd); OnWindowShown(EventArgs.Empty); return(true); } catch (Exception ex) { LoggingService.LogError(ex.ToString()); return(false); } } finally { ParameterInformationWindowManager.UpdateWindow(ext, completionWidget); } }
protected virtual void OnTitleChanged(EventArgs e) { fileTypeCondition.SetFileName(content.ContentName ?? content.UntitledName); if (show_notification) { tabLabel.Label.Markup = "<span foreground=\"blue\">" + Title + "</span>"; tabLabel.Label.UseMarkup = true; } else { tabLabel.Label.Text = Title; tabLabel.Label.UseMarkup = false; } if (content.ContentName != null && content.ContentName != "") { tabLabel.SetTooltip(content.ContentName, content.ContentName); } try { if (content.StockIconId != null) { tabLabel.Icon = new Gtk.Image((IconId)content.StockIconId, IconSize.Menu); } else if (content.ContentName != null && content.ContentName.IndexOfAny(new char[] { '*', '+' }) == -1) { tabLabel.Icon.Pixbuf = DesktopService.GetPixbufForFile(content.ContentName, Gtk.IconSize.Menu); } } catch (Exception ex) { LoggingService.LogError(ex.ToString()); tabLabel.Icon.Pixbuf = DesktopService.GetPixbufForType("gnome-fs-regular", Gtk.IconSize.Menu); } if (TitleChanged != null) { TitleChanged(this, e); } }
public static string[] GetCommentTags(string fileName) { //Document doc = IdeApp.Workbench.ActiveDocument; string loadedMimeType = DesktopService.GetMimeTypeForUri(fileName); var result = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "LineComment"); if (result != null) { return(result); } var start = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "BlockCommentStart"); var end = TextEditorFactory.GetSyntaxProperties(loadedMimeType, "BlockCommentEnd"); if (start != null && end != null) { return new [] { start[0], end[0] } } ; return(null); }
static string FormatGeneratedFile(string file, string content, CodeDomProvider provider) { content = StripHeaderAndBlankLines(content, provider); var pol = PolicyService.InvariantPolicies.Get <TextStylePolicy> (); string eol = pol.GetEolMarker(); if (Environment.NewLine != eol) { content = content.Replace(Environment.NewLine, eol); } string mt = DesktopService.GetMimeTypeForUri(file); var formatter = MonoDevelop.Ide.CodeFormatting.CodeFormatterService.GetFormatter(mt); if (formatter != null) { content = formatter.FormatText(PolicyService.InvariantPolicies, content); } return(content); }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { ProjectFile file = (ProjectFile) dataObject; label = file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName; if (!File.Exists (file.FilePath)) { label = "<span foreground='red'>" + label + "</span>"; } icon = DesktopService.GetPixbufForFile (file.FilePath, Gtk.IconSize.Menu); if (file.IsLink && icon != null) { icon = icon.Copy (); using (Gdk.Pixbuf overlay = Gdk.Pixbuf.LoadFromResource ("Icons.16x16.LinkOverlay.png")) { overlay.Composite (icon, 0, 0, icon.Width, icon.Width, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); } } }
public void EndReplace() { if (document != null) { Gtk.Application.Invoke(delegate { if (undoGroup != null) { undoGroup.Dispose(); undoGroup = null; } document.Editor.Document.CommitUpdateAll(); }); return; } if (buffer != null && somethingReplaced) { object attributes = DesktopService.GetFileAttributes(FileName); File.WriteAllText(FileName, buffer.ToString()); DesktopService.SetFileAttributes(FileName, attributes); } buffer = null; }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine(GettextCatalog.GetString("Looking in project '{0}'", project.Name)); var alreadyVisited = new HashSet <string> (); foreach (ProjectFile file in project.Files.Where(f => filterOptions.NameMatches(f.Name) && File.Exists(f.Name))) { if (!IncludeBinaryFiles && !DesktopService.GetFileIsText(file.Name)) { continue; } if (alreadyVisited.Contains(file.Name)) { continue; } alreadyVisited.Add(file.Name); yield return(new FileProvider(file.Name, project)); } } }
static void HandleDocumentOpened(object sender, DocumentEventArgs e) { var document = e.Document; if (document == null || !document.IsFile || !".resx".Equals(document.FileName.Extension, StringComparison.OrdinalIgnoreCase) || DesktopService.GetMimeTypeForUri(document.FileName) != "text/microsoft-resx") { return; } // Load resx data. var resx = ResXData.FromFile(document.FileName); int index = 0; foreach (var editor in AddinManager.GetExtensionObjects <ResXEditorBinding>(ResXEditorsExtensionPath)) { var viewContent = editor.CreateViewContent(resx); document.Window.InsertViewContent(index++, viewContent); } }
public virtual void EndReplace() { if (document != null) { Gtk.Application.Invoke((o, args) => { if (undoGroup != null) { undoGroup.Dispose(); undoGroup = null; } /*document.Editor.Document.CommitUpdateAll (); */ }); return; } if (buffer != null && somethingReplaced) { object attributes = DesktopService.GetFileAttributes(FileName); TextFileUtility.WriteText(FileName, buffer.ToString(), encoding ?? Encoding.UTF8); DesktopService.SetFileAttributes(FileName, attributes); } buffer = null; }
TreeIter AppendFileInfo(ChangeSetItem n) { Gdk.Pixbuf statusicon = VersionControlService.LoadIconForStatus(n.Status); string lstatus = VersionControlService.GetStatusLabel(n.Status); string scolor = null; string localpath = n.LocalPath.ToRelative(changeSet.BaseLocalPath); if (localpath.Length > 0 && localpath[0] == System.IO.Path.DirectorySeparatorChar) { localpath = localpath.Substring(1); } if (localpath == "") { localpath = "."; } // not sure if this happens bool hasComment = false; //GetCommitMessage (n.LocalPath).Length > 0; bool commit = true; //changeSet.ContainsFile (n.LocalPath); Gdk.Pixbuf fileIcon; if (n.IsDirectory) { fileIcon = ImageService.GetPixbuf(MonoDevelop.Ide.Gui.Stock.ClosedFolder, Gtk.IconSize.Menu); } else { fileIcon = DesktopService.GetPixbufForFile(n.LocalPath, Gtk.IconSize.Menu); } TreeIter it = filestore.AppendValues(statusicon, lstatus, GLib.Markup.EscapeText(localpath).Split('\n'), commit, false, n.LocalPath.ToString(), true, hasComment, fileIcon, n.HasLocalChanges, scolor); if (!n.IsDirectory) { filestore.AppendValues(it, statusicon, "", new string[0], false, true, n.LocalPath.ToString(), false, false, fileIcon, false, null); } return(it); }
protected override ITextSource FormatImplementation(PolicyContainer policyParent, string mimeType, ITextSource input, int startOffset, int length) { var chain = DesktopService.GetMimeTypeInheritanceChain(mimeType); var policy = policyParent.Get <CSharpFormattingPolicy> (chain); var textPolicy = policyParent.Get <TextStylePolicy> (chain); var optionSet = policy.CreateOptions(textPolicy); if (input is IReadonlyTextDocument doc) { try { var conventions = EditorConfigService.GetEditorConfigContext(doc.FileName).WaitAndGetResult(); if (conventions != null) { optionSet = new FormattingDocumentOptionSet(optionSet, new CSharpDocumentOptionsProvider.DocumentOptions(optionSet, conventions.CurrentConventions)); } } catch (Exception e) { LoggingService.LogError("Error while loading coding conventions.", e); } } return(new StringTextSource(FormatText(optionSet, input.Text, startOffset, startOffset + length))); }
static void SetFormatOptions(CSharpOutputVisitor outputVisitor, PolicyContainer policyParent) { IEnumerable <string> types = DesktopService.GetMimeTypeInheritanceChain(CSharpFormatter.MimeType); TextStylePolicy currentPolicy = policyParent != null?policyParent.Get <TextStylePolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> (types); CSharpFormattingPolicy codePolicy = policyParent != null?policyParent.Get <CSharpFormattingPolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <CSharpFormattingPolicy> (types); outputVisitor.Options.IndentationChar = currentPolicy.TabsToSpaces ? ' ' : '\t'; outputVisitor.Options.TabSize = currentPolicy.TabWidth; outputVisitor.Options.IndentSize = currentPolicy.TabWidth; outputVisitor.Options.EolMarker = TextStylePolicy.GetEolMarker(currentPolicy.EolMarker); Type optionType = outputVisitor.Options.GetType(); foreach (var property in typeof(CSharpFormattingPolicy).GetProperties()) { PropertyInfo info = optionType.GetProperty(property.Name); if (info == null) { continue; } object val = property.GetValue(codePolicy, null); object cval = null; if (info.PropertyType.IsEnum) { cval = Enum.Parse(info.PropertyType, val.ToString()); } else if (info.PropertyType == typeof(bool)) { cval = Convert.ToBoolean(val); } else { cval = Convert.ChangeType(val, info.PropertyType); } info.SetValue(outputVisitor.Options, cval, null); } }
public ParameterInformationWindow() { TypeHint = Gdk.WindowTypeHint.Tooltip; this.SkipTaskbarHint = true; this.SkipPagerHint = true; this.AllowShrink = false; this.AllowGrow = false; this.CanFocus = false; this.CanDefault = false; WindowTransparencyDecorator.Attach(this); headlabel = new MonoDevelop.Components.FixedWidthWrapLabel(); headlabel.Indent = -20; headlabel.Wrap = Pango.WrapMode.WordChar; headlabel.BreakOnCamelCasing = false; headlabel.BreakOnPunctuation = false; descriptionBox.Spacing = 4; VBox vb = new VBox(false, 0); vb.PackStart(headlabel, true, true, 0); vb.PackStart(descriptionBox, true, true, 0); HBox hb = new HBox(false, 0); hb.PackStart(vb, true, true, 0); vb2.Spacing = 4; vb2.PackStart(hb, true, true, 0); ContentBox.Add(vb2); UpdateStyle(); Styles.Changed += HandleSkinChanged; IdeApp.Preferences.ColorScheme.Changed += HandleSkinChanged; ShowAll(); DesktopService.RemoveWindowShadow(this); }
string TryGetFileType(string name) { if (name.StartsWith(".")) { name = name.Substring(1); } string tmpFile = null; try { tmpFile = System.IO.Path.GetTempFileName(); string f = System.IO.Path.ChangeExtension(tmpFile, "." + name); File.Move(tmpFile, f); tmpFile = f; return(DesktopService.GetMimeTypeForUri(tmpFile)); } catch { return(null); } finally { if (tmpFile != null) { try { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } catch { } } } }
static void PixbufCellDataFunc(TreeViewColumn col, CellRenderer cell, TreeModel model, TreeIter iter) { TreeIter parent; bool toplevel = !model.IterParent(out parent, iter); var crp = (CellRendererImage)cell; crp.Visible = !toplevel; if (toplevel) { return; } var section = (OptionsDialogSection)model.GetValue(iter, 0); //HACK: The mimetype panels can't register a single fake stock ID for all the possible image size. // Instead, give this some awareness of the mime system. var mimeSection = section as MonoDevelop.Ide.Projects.OptionPanels.MimetypeOptionsDialogSection; if (mimeSection != null && !string.IsNullOrEmpty(mimeSection.MimeType)) { var pix = DesktopService.GetIconForType(mimeSection.MimeType, treeIconSize); if (pix != null) { crp.Image = pix; } else { crp.Image = ImageService.GetIcon(emptyCategoryIcon, treeIconSize); } } else { string icon = section.Icon.IsNull? emptyCategoryIcon : section.Icon.ToString(); crp.Image = ImageService.GetIcon(icon, treeIconSize); } }
protected override void Update(CommandArrayInfo info) { RecentOpen recentOpen = IdeApp.Workbench.RecentOpen; if (recentOpen.RecentFilesCount > 0) { int i = 0; foreach (RecentItem ri in recentOpen.RecentFiles) { string accelaratorKeyPrefix = i < 10 ? "_" + ((i + 1) % 10).ToString() + " " : ""; string label = ((ri.Private == null || ri.Private.Length < 1) ? Path.GetFileName(ri.ToString()) : ri.Private); CommandInfo cmd = new CommandInfo(accelaratorKeyPrefix + label.Replace("_", "__")); cmd.Description = GettextCatalog.GetString("Open {0}", ri.ToString()); Gdk.Pixbuf icon = DesktopService.GetPixbufForFile(ri.ToString(), IconSize.Menu); if (icon != null) { cmd.Icon = ImageService.GetStockId(icon, IconSize.Menu); } info.Add(cmd, ri); i++; } } }
static string FormatGeneratedFile(string file, string content, Project project, CodeDomProvider provider) { content = StripHeaderAndBlankLines(content, provider); string mt = DesktopService.GetMimeTypeForUri(file); var formatter = MonoDevelop.Ide.CodeFormatting.CodeFormatterService.GetFormatter(mt); if (formatter != null) { content = formatter.FormatText(PolicyService.InvariantPolicies, content) ?? content; } // The project policies should be taken for generated files (windows git eol problem) var pol = project.Policies.Get <TextStylePolicy> (DesktopService.GetMimeTypeForUri(file)); string eol = pol.GetEolMarker(); if (Environment.NewLine != eol) { content = content.Replace(Environment.NewLine, eol); } return(content); }
public bool Supports(string fileName) { if (fileExtensions != null && fileExtensions.Length > 0) { string ext = System.IO.Path.GetExtension(fileName); return(((IList)fileExtensions).Contains(ext)); } if (mimeTypes != null && mimeTypes.Length > 0) { string mt = DesktopService.GetMimeTypeForUri(fileName); foreach (string t in mimeTypes) { if (DesktopService.GetMimeTypeIsSubtype(mt, t)) { return(true); } } return(false); } // No constraints on the file return(true); }
public bool Supports(string fileName) { if (fileExtensions != null && fileExtensions.Length > 0) { string ext = System.IO.Path.GetExtension(fileName); return(fileExtensions.Any(fe => string.Compare(fe, ext, StringComparison.OrdinalIgnoreCase) == 0)); } if (mimeTypes != null && mimeTypes.Length > 0) { string mt = DesktopService.GetMimeTypeForUri(fileName); foreach (string t in mimeTypes) { if (DesktopService.GetMimeTypeIsSubtype(mt, t)) { return(true); } } return(false); } // No constraints on the file return(true); }
public void EndReplace() { if (document != null) { Gtk.Application.Invoke(delegate { if (undoGroup != null) { undoGroup.Dispose(); undoGroup = null; } /*document.Editor.Document.CommitUpdateAll (); */ }); return; } if (buffer != null && somethingReplaced) { object attributes = DesktopService.GetFileAttributes(FileName); TextFileUtility.WriteText(FileName, buffer.ToString(), encoding, hadBom); DesktopService.SetFileAttributes(FileName, attributes); } FileService.NotifyFileChanged(FileName); buffer = null; }
void DispatchLink(string uri) { try { if (uri.StartsWith("project://")) { string file = uri.Substring("project://".Length); Gdk.ModifierType mtype = Mono.TextEditor.GtkWorkarounds.GetCurrentKeyModifiers(); bool inWorkspace = (mtype & Gdk.ModifierType.ControlMask) != 0; IdeApp.Workspace.OpenWorkspaceItem(file, !inWorkspace); } else if (uri.StartsWith("monodevelop://")) { var cmdId = uri.Substring("monodevelop://".Length); IdeApp.CommandService.DispatchCommand(cmdId, MonoDevelop.Components.Commands.CommandSource.WelcomePage); } else { DesktopService.ShowUrl(uri); } } catch (Exception ex) { LoggingService.LogInternalError(GettextCatalog.GetString("Could not open the url '{0}'", uri), ex); } }
internal static SyntaxHighlightingDefinition GetSyntaxHighlightingDefinition(FilePath fileName, string mimeType) { if (!fileName.IsNullOrEmpty) { var def = GetSyntaxHighlightingDefinitionByName(fileName); if (def != null) { return(def); } if (mimeType == null) { mimeType = DesktopService.GetMimeTypeForUri(fileName); } } if (mimeType == null) { return(null); } return(GetSyntaxHighlightingDefinitionByMimeType(mimeType)); }
/// <summary> /// Determines whether the task's file should be opened automatically when jumping to the next error. /// </summary> public static bool IsProjectTaskFile(TaskListEntry t) { if (t.FileName.IsNullOrEmpty) { return(false); } //only files that are part of project Project p = t.WorkspaceObject as Project; if (p == null) { return(false); } if (p.GetProjectFile(t.FileName) == null) { return(false); } //only text files var mimeType = DesktopService.GetMimeTypeForUri(t.FileName); if (!DesktopService.GetMimeTypeIsText(mimeType)) { return(false); } //only files for which we have a default internal display binding var binding = DisplayBindingService.GetDefaultBinding(t.FileName, mimeType, p); if (binding == null || !binding.CanUseAsDefault || binding is IExternalDisplayBinding) { return(false); } return(true); }
void OnDocumentChanged(object o, EventArgs a) { // Don't directly parse the document because doing it at every key press is // very inefficient. Do it after a small delay instead, so several changes can // be parsed at the same time. if (parsing) { return; } parsing = true; string currentParseFile = FileName; string mime = DesktopService.GetMimeTypeForUri(currentParseFile); GLib.Timeout.Add(ParseDelay, delegate { if (closed) { return(false); } parsing = false; string currentParseText = TextEditor.Text; Project curentParseProject = Project; System.Threading.ThreadPool.QueueUserWorkItem(delegate { // Don't access Document properties from the thread this.parsedDocument = ProjectDomService.Parse(curentParseProject, currentParseFile, mime, currentParseText); if (this.parsedDocument != null && !this.parsedDocument.HasErrors) { this.lastErrorFreeParsedDocument = parsedDocument; } DispatchService.GuiSyncDispatch(delegate { OnDocumentParsed(EventArgs.Empty); }); }); return(false); }); }