internal static Size?ImageSize(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } if (!check.Value) { return(null); } using var magick = new MagickImage(); try { magick.Read(file); } #if DEBUG catch (MagickException e) { Trace.WriteLine("ImageSize returned " + file + " null, \n" + e.Message); return(null); } #else catch (MagickException) { return(null); } #endif return(new Size(magick.Width, magick.Height)); }
private void OpenSelectedFileNode(string file) { //check if it is already opened List <CodeEditor> listeditors = this.GetCodeEditors(); foreach (CodeEditor CE in listeditors) { if (CE.FilePath == file) { CE.Activate(); return; } } string fileextesion = Path.GetExtension(file); if (fileextesion != ".mpr") { CodeEditor MCED = this.CreateEditor(file, SupportedFiles.GetType(fileextesion.Replace(".", ""))); MCED.SetContent(FileHelper.GetContent(file)); MCED.Show(MDockArea); MCED.DockState = DockState.Document; //add to recent if (MOO_APPLICATION_SETTINGS.RecentFiles.Count <= 5) { MOO_APPLICATION_SETTINGS.RecentFiles.Add(file); } } }
//file menu handlers private void NewPrjectFile(object sender, EventArgs e) { NewDialog newdialog = new NewDialog(MOO_APPLICATION_SETTINGS.CurrentProject); if (newdialog.ShowDialog() != DialogResult.OK) { return; } if (newdialog.NewOption == "PROJECT") { Project CreateProject = ProjectFactory.Create(newdialog.ResultObjectFolder, newdialog.ResultObjectName, newdialog.ResultProjectType, newdialog.ResultTemplate); if (CreateProject != null) { MOO_APPLICATION_SETTINGS.CurrentProject = CreateProject; MOO_PROJECT_BROWSER.BuildNodes(CreateProject.Folder, CreateProject.File, CreateProject.Name); } } else { string filename = newdialog.ResultObjectFolder + @"\" + newdialog.ResultObjectName; filename += SupportedFiles.GetExtension(newdialog.ResultObjectType); CodeEditor MCDE = this.CreateEditor(filename, newdialog.ResultObjectType); MCDE.Show(MDockArea); MCDE.DockState = DockState.Document; } }
internal static string GetIcon(MonoDevelop.Core.FilePath document) { if (SupportedFiles.Contains(document.Extension)) { return($"file_{document.Extension.Remove(0, 1)}"); } return("file"); }
private void OpenPrjectFile(object sender, EventArgs e) { string filter = "All files (*.*)|*.*|Moo Project (*.mpr)|*.mpr|Text file (*.txt)|*.txt|Html file ((*.html))|*.html|Xml file(*.xml)|*.xml"; //we check if the sender was a (StartPage) or a (FProjectBrowser) to restrict for only project file //because those components can only send project open event if ((sender.GetType() == typeof(StartPage)) || (sender.GetType() == typeof(FProjectBrowser))) { filter = "Moo Project (*.mpr)|*.mpr"; } string openfilepath; string openfilename; string openfilecontent = FileHelper.GetContent(filter, out openfilepath, out openfilename); string openfileextesion = Path.GetExtension(openfilepath); if (openfilepath != String.Empty) { if (openfileextesion == ".mpr") { //deal with project Project PRJT = ProjectFactory.Open(openfilepath); MOO_APPLICATION_SETTINGS.CurrentProject = PRJT; //load the project into the project browser MOO_PROJECT_BROWSER.BuildNodes(PRJT.Folder, PRJT.File, PRJT.Name); //add to recent if (MOO_APPLICATION_SETTINGS.RecentProjects.Count <= 5) { MOO_APPLICATION_SETTINGS.RecentProjects.Add(openfilepath); } } else { //check if it is already opened List <CodeEditor> listeditors = this.GetCodeEditors(); foreach (CodeEditor CE in listeditors) { if (CE.FilePath == openfilepath) { CE.Activate(); return; } } //deal with file CodeEditor MCED = this.CreateEditor(openfilepath, SupportedFiles.GetType(openfileextesion.Replace(".", ""))); MCED.SetContent(openfilecontent); MCED.Show(MDockArea); MCED.DockState = DockState.Document; //add to recent if (MOO_APPLICATION_SETTINGS.RecentFiles.Count <= 5) { MOO_APPLICATION_SETTINGS.RecentFiles.Add(openfilepath); } } } }
public void TestSupportedFiles() { var ok = SupportedFiles.IsSupported(".jpg"); Assert.IsTrue(ok); var notok = SupportedFiles.IsSupported("somestring"); Assert.IsFalse(notok); }
private void OpenRecentHandler(object sender, EventArgs e) { MenuItem mi = (MenuItem)sender; string openfilepath = mi.Tag.ToString(); if (!new FileInfo(openfilepath).Exists) { MessageBox.Show(this, "This file has been removed", "Moo { + }", MessageBoxButtons.OK, MessageBoxIcon.Information); MenuItem Parent = (MenuItem)mi.Parent; Parent.MenuItems.Remove(mi); if (Parent == MRecentFiles) { MOO_APPLICATION_SETTINGS.RecentFiles.Remove(mi.Tag.ToString()); } else { MOO_APPLICATION_SETTINGS.RecentProjects.Remove(mi.Tag.ToString()); } return; } string openfilecontent = FileHelper.GetContent(openfilepath); string openfileextesion = Path.GetExtension(openfilepath); if (openfilepath != String.Empty) { if (openfileextesion == ".mpr") { //deal with project Project PRJT = ProjectFactory.Open(openfilepath); MOO_APPLICATION_SETTINGS.CurrentProject = PRJT; //load the project into the project browser MOO_PROJECT_BROWSER.BuildNodes(PRJT.Folder, PRJT.File, PRJT.Name); } else { //check if it is already opened List <CodeEditor> listeditors = this.GetCodeEditors(); foreach (CodeEditor CE in listeditors) { if (CE.FilePath == openfilepath) { CE.Activate(); return; } } //deal with file CodeEditor MCED = this.CreateEditor(openfilepath, SupportedFiles.GetType(openfileextesion.Replace(".", ""))); MCED.SetContent(openfilecontent); MCED.Show(MDockArea); MCED.DockState = DockState.Document; } } }
private void WriteXmlTags(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; WorkerArgs args = e.Argument as WorkerArgs; var filteredfileNames = Directory.GetFiles(args.Directory, "*.*", SearchOption.AllDirectories); MPTVSeriesImporter importer = new MPTVSeriesImporter(); importer.OpenConnection(); int current = 0; int total = filteredfileNames.Count(); foreach (var file in filteredfileNames) { if (worker.CancellationPending) { e.Cancel = true; break; } current++; worker.ReportProgress(100 * current / total); // Check only video files if (!SupportedFiles.IsFileSupportedVideo(file)) { continue; } // build xml file name string xmlFile = GetXmlFilename(file); // init document MatroskaTags tag = new MatroskaTags(); // Read MKV tags, if existing should be reused if (App.Config.BasedOnExistingTags) { tag = MatroskaLoader.ReadTag(file); } // update tags from MP-TVSeries tag.Series = importer.UpdateTags(tag.Series, file); string logText = File.Exists(xmlFile) ? "XML updated: " : "XML created: "; MatroskaLoader.WriteTagToXML(tag, xmlFile); worker.ReportProgress(100 * current / total, new FileBasedLogEntry(xmlFile, logText)); } importer.CloseConnection(); }
/// <summary> /// Check if dragged file is valid, /// returns false for valid file with no thumbnail, /// true for valid file with thumbnail /// and null for invalid file /// </summary> /// <param name="files"></param> /// <returns></returns> private static bool?Drag_Drop_Check(string[] files) { // Return if file strings are null if (files == null) { return(null); } if (files[0] == null) { return(null); } // Return status of useable file return(SupportedFiles.IsSupportedFile(Path.GetExtension(files[0]))); }
private CodeEditor CreateEditor(string filename, string filetype) { string lexer = SupportedFiles.GetLexer(filetype); CodeEditor ce = new CodeEditor(MOO_APPLICATION_SETTINGS.EditorConfig, filename); ce.SetLanguage(lexer); //get keywordlist from current project if (MOO_APPLICATION_SETTINGS.CurrentProject != null) { ce.UpadateCompletionList(MOO_APPLICATION_SETTINGS.CurrentProject.GetKeywords()); } //add brunchs to editor list Dictionary <string, string> dic = MOO_BRUNCH_BROWSER.GetBrunchDictionary(filetype); ce.UpdateSnippets(dic); ce.CaretPositionChanged += new CaretPositionHandler(UpdateSatutsLineColumn); return(ce); }
internal static BitmapSource GetBitmapSourceThumb(string path) { var supported = SupportedFiles.IsSupportedFile(path); if (!supported.HasValue) { return(null); } if (supported.Value) { return(GetWindowsThumbnail(path)); } else if (!supported.Value) { return(GetMagickImageThumb(path)); } return(null); }
/// <summary> /// Returns thumb for common images /// </summary> /// <param name="x"></param> /// <param name="startup"></param> /// <returns></returns> internal static BitmapSource GetThumb(int x, bool startup) { if (!startup) { return(GetThumb(x)); } var supported = SupportedFiles.IsSupportedFile(Pics[x]); if (!supported.HasValue) { return(null); } if (supported.Value) { return(GetThumb(x)); } return(null); }
private async void loadThubmadilands() { if (vm.Folder == null) { return; } ImageGalleryGrid.Items.Clear(); var folder = await StorageFolder.GetFolderFromPathAsync(vm.Folder); var files = await folder.GetFilesAsync(); foreach (var file in files) { if (SupportedFiles.IsSupported(file.FileType)) { var img = new Smallmage(file); ImageGalleryGrid.Items.Add(img); } } ImageGalleryGrid_SelectionChanged(null, null); }
/// <summary> /// Decodes image from file to BitMapSource /// </summary> /// <param name="file">Absolute path of the file</param> /// <returns></returns> internal static BitmapSource RenderToBitmapSource(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } try { using var filestream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.SequentialScan); if (check.Value) { var sKBitmap = SKBitmap.Decode(filestream); if (sKBitmap == null) { return(null); } var pic = sKBitmap.ToWriteableBitmap(); pic.Freeze(); sKBitmap.Dispose(); return(pic); } else { using MagickImage magick = new MagickImage(); var mrs = new MagickReadSettings() { Density = new Density(300, 300), BackgroundColor = MagickColors.Transparent, }; try { magick.Read(filestream, mrs); filestream.Close(); } catch (MagickException e) { #if DEBUG Trace.WriteLine("GetMagickImage returned " + file + " null, \n" + e.Message); #endif return(null); } // Set values for maximum quality magick.Quality = 100; magick.ColorSpace = ColorSpace.Transparent; var pic = magick.ToBitmapSource(); pic.Freeze(); magick.Dispose(); return(pic); } } catch (Exception e) { #if DEBUG Trace.WriteLine("RenderToBitmapSource returned " + file + " null, \n" + e.Message); #endif return(null); } }
/// <summary> /// Decodes image from file to BitMapSource /// </summary> /// <param name="file">Absolute path of the file</param> /// <returns></returns> internal static async Task <BitmapSource> RenderToBitmapSource(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } try { if (check.Value) { var filestream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.SequentialScan); var sKBitmap = SKBitmap.Decode(filestream); await filestream.DisposeAsync().ConfigureAwait(false); if (sKBitmap == null) { return(null); } var pic = sKBitmap.ToWriteableBitmap(); pic.Freeze(); sKBitmap.Dispose(); return(pic); } else { using MagickImage magick = new MagickImage(); try { magick.Read(file); } catch (MagickException e) { #if DEBUG Trace.WriteLine("GetMagickImage returned " + file + " null, \n" + e.Message); #endif return(null); } // Set values for maximum quality magick.Quality = 100; magick.ColorSpace = ColorSpace.Transparent; var pic = magick.ToBitmapSource(); pic.Freeze(); return(pic); } } catch (Exception e) { #if DEBUG Trace.WriteLine("RenderToBitmapSource returned " + file + " null, \n" + e.Message); #endif return(null); } }