/// <see cref="ISettings.Save"/> public void Save() { _settings.LastPath = LastDiagramLocation.FullName; _settings.GraphVizLocation = GraphVizExecutable.FullName; _settings.PlantUmlLocation = PlantUmlJar.FullName; _settings.RememberOpenFiles = RememberOpenFiles; var openFiles = new StringCollection(); openFiles.AddRange(OpenFiles.Select(file => file.FullName).ToArray()); _settings.OpenFiles = openFiles; _settings.MaximumRecentFiles = MaximumRecentFiles; var recentFiles = new StringCollection(); recentFiles.AddRange(RecentFiles.Select(file => file.FullName).ToArray()); _settings.RecentFiles = recentFiles; _settings.AutoSaveEnabled = AutoSaveEnabled; _settings.AutoSaveInterval = AutoSaveInterval; _settings.HighlightCurrentLine = HighlightCurrentLine; _settings.ShowLineNumbers = ShowLineNumbers; _settings.EnableVirtualSpace = EnableVirtualSpace; _settings.EnableWordWrap = EnableWordWrap; _settings.EmptySelectionCopiesEntireLine = EmptySelectionCopiesEntireLine; _settings.AllowScrollingBelowContent = AllowScrollingBelowContent; _settings.Save(); }
private void buttonFile_Click(object sender, EventArgs e) { if (OpenFiles.ShowDialog() == DialogResult.OK) { AttachFiles.DataSource = OpenFiles.SafeFileNames; } }
/// <inheritdoc /> /// <summary> /// Shuts down Kore and closes all plugins and open files. /// </summary> public void Dispose() { foreach (var kfi in OpenFiles.Select(f => f)) { CloseFile(kfi); } }
private void OpenFileInternal(string filename) { var exitingFile = _openFiles.FirstOrDefault(openfile => openfile.FileName == filename); if (exitingFile != null) { SelectedFile = exitingFile; return; } var file = new OpenFileViewModel(this); file.Ready += delegate { Dispatcher.CurrentDispatcher.InvokeAsync(() => { try { file.OpenFile(filename); } catch (Exception ex) { OpenFiles.Remove(file); MessageBoxService.ShowMessage($"Error: {ex.Message}", Constants.AppTitle); } }); }; OpenFiles.Add(file); _recentFiles.Remove(filename); _recentFiles.Insert(0, filename); if (_recentFiles.Count > 10) { _recentFiles.RemoveAt(9); } SelectedFile = file; }
internal void NotifyCloseFile(FileAccessor file) { lock (_locker) { OpenFiles.Remove(file); } }
/// <summary> /// Permite abrir un nuevo texto /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Open_Click(object sender, EventArgs e) { OpenFiles.InitialDirectory = "c:\\"; OpenFiles.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*|rtf files (*.rtf)|*.rtf"; //Filtra ficheros de texto y rtf OpenFiles.FilterIndex = 2; OpenFiles.RestoreDirectory = true; if (OpenFiles.ShowDialog() == DialogResult.OK) { filePath = OpenFiles.FileName; rutas.Items.Add(filePath); } richTextBox1.Clear(); if (Path.GetExtension(OpenFiles.FileName) == ".txt") { richTextBox1.LoadFile(OpenFiles.FileName, RichTextBoxStreamType.PlainText); } else if (Path.GetExtension(OpenFiles.FileName) == ".rtf") { richTextBox1.LoadFile(OpenFiles.FileName, RichTextBoxStreamType.RichText); } openFile = true; }
private void OpenToolStripMenuItem_Click(object sender, System.EventArgs e) //open data dialog and show processed text { this.Activate(); OpenFiles.ShowDialog(); string[] names = OpenFiles.FileNames; if (names == Array.Empty <string>()) { return; } try //get text from data output glued data on the screen { data = new DataSet(names); skriptTextField.Text = data.getResultData(); } catch (System.IO.FileNotFoundException Ex) //handles data expetions { MessageBox.Show(Ex.Message + "\nНет такого файла", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception Ex) //handles other expetions { MessageBox.Show(Ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
protected void OpenFilesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Settings set = SettingsManager.Load(); set.LastOpenedFiles.Clear(); set.LastOpenedFiles.AddRange(OpenFiles.Select(x => x.LoadedFile).ToList()); SettingsManager.Save(set); }
public void Commit() { if (OpenFiles.Any(x => (x.OpenMode & OpenMode.Write) != 0)) { ThrowHelper.ThrowResult(ResultFs.WritableFileOpen); } FileSystem.Commit(); }
private void OpenDialogButton_Click(object sender, EventArgs e) { var result = JsonLoadDialog.ShowDialog(); if (result == DialogResult.OK) { OpenFiles?.Invoke(sender, JsonLoadDialog.FileName); } }
private void AddTemplates() { var newTemplates = new OpenFiles().OpenTemplatesFile(); if (newTemplates != null && newTemplates.Count > 0) { repository.AddOrUpdateTemplates(newTemplates); } }
public Result Commit() { if (OpenFiles.Any(x => (x.OpenMode & OpenMode.Write) != 0)) { return(ResultFs.WriteModeFileNotClosed.Log()); } return(FileSystem.Commit()); }
public void CloseFile(EdataFileViewModel vm) { if (!OpenFiles.Contains(vm)) { return; } OpenFiles.Remove(vm); }
private static void FileEnum(string sPath, string sServer = "") { int EntriesRead = 0; int TotalRead = 0; IntPtr ResumeHandle = IntPtr.Zero; IntPtr bufptr = IntPtr.Zero; int ret; IntPtr ptrEntry; GCHandle handle = GCHandle.Alloc(sServer, GCHandleType.Pinned); IntPtr ptrServer; int totalEntries = 0; int idx = totalEntries; do { Console.WriteLine("Server: {0}", sServer); ret = OpenFiles.NetFileEnum(sServer, sPath, null, 3, ref bufptr, OpenFiles.MAX_PREFERRED_LENGTH, out EntriesRead, out TotalRead, ResumeHandle); OpenFiles.SetLastError((uint)ret); string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message; if (ret != (int)OpenFiles.NERR.ERROR_MORE_DATA && ret != (int)OpenFiles.NERR.NERR_Success) { Console.WriteLine("Error: " + errorMessage); //break; //return; } for (int i = 0; i < EntriesRead; i++) { OpenFiles.FILE_INFO_3 entry = new OpenFiles.FILE_INFO_3(); ptrEntry = bufptr + (Marshal.SizeOf(entry) * i); entry = (OpenFiles.FILE_INFO_3)Marshal.PtrToStructure(ptrEntry, typeof(OpenFiles.FILE_INFO_3)); idx = totalEntries + i; //if (i == 0) //{ // Console.WriteLine("#,Locks,\"Server Path\",Permissions,\"User ID\""); //} Console.WriteLine("{0},{1},\"{2}\",\"{3}\",{4}", i + 1, entry.fi3_NumLocks, entry.fi3_PathName, entry.fi3_Permissions, entry.fi3_UserName); FileLockInfo info = new FileLockInfo(); info.numberOfLocks = entry.fi3_NumLocks; info.remotePath = entry.fi3_PathName.ToString(); info.permissions = entry.fi3_Permissions.ToString(); info.userName = entry.fi3_UserName.ToString(); info.id = entry.fi3_Id; listFileInfo.Add(info); } } while (ret == (int)OpenFiles.NERR.ERROR_MORE_DATA); }
public void AddFile(string path) { var vm = new EdataFileViewModel(this); vm.LoadFile(path); OpenFiles.Add(vm); CollectionViewSource.GetDefaultView(OpenFiles).MoveCurrentTo(vm); }
public static ConfigFile ReadProjectConfigFile(PerforceConnection Perforce, string BranchClientPath, string SelectedClientFileName, List <KeyValuePair <string, DateTime> > LocalConfigFiles, TextWriter Log) { List <string> ConfigFilePaths = Utility.GetConfigFileLocations(BranchClientPath, SelectedClientFileName, '/'); List <PerforceFileRecord> OpenFiles; Perforce.GetOpenFiles(String.Format("{0}/....ini", BranchClientPath), out OpenFiles, Log); ConfigFile ProjectConfig = new ConfigFile(); foreach (string ConfigFilePath in ConfigFilePaths) { List <string> Lines = null; // If this file is open for edit, read the local version if (OpenFiles != null && OpenFiles.Any(x => x.ClientPath.Equals(ConfigFilePath, StringComparison.InvariantCultureIgnoreCase))) { try { string LocalFileName; if (Perforce.ConvertToLocalPath(ConfigFilePath, out LocalFileName, Log)) { DateTime LastModifiedTime = File.GetLastWriteTimeUtc(LocalFileName); LocalConfigFiles.Add(new KeyValuePair <string, DateTime>(LocalFileName, LastModifiedTime)); Lines = File.ReadAllLines(LocalFileName).ToList(); } } catch (Exception Ex) { Log.WriteLine("Failed to read local config file for {0}: {1}", ConfigFilePath, Ex.ToString()); } } // Otherwise try to get it from perforce if (Lines == null) { Perforce.Print(ConfigFilePath, out Lines, Log); } // Merge the text with the config file if (Lines != null) { try { ProjectConfig.Parse(Lines.ToArray()); Log.WriteLine("Read config file from {0}", ConfigFilePath); } catch (Exception Ex) { Log.WriteLine("Failed to read config file from {0}: {1}", ConfigFilePath, Ex.ToString()); } } } return(ProjectConfig); }
private async void Close_impl(TextEditorViewModel toClose) { if (!toClose.IsSaved) { Window target = Avalonia.Application.Current.Windows.Where(w => ReferenceEquals(w.DataContext, this)).Single(); if (toClose.File is null) { } } OpenFiles.Remove(toClose); }
/// <summary> /// Abre una ventana para seleccionar los archivos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowFiles_Click(object sender, EventArgs e) { OpenFiles.InitialDirectory = "c:\\"; OpenFiles.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*|rtf files (*.rtf)|*.rtf"; OpenFiles.FilterIndex = 2; OpenFiles.RestoreDirectory = true; if (OpenFiles.ShowDialog() == DialogResult.OK) { filePath = OpenFiles.FileName; rutas.Items.Add(filePath); } }
public FileAccessor OpenFile(string path, OpenMode mode) { IFile file = FileSystem.OpenFile(path, mode); var accessor = new FileAccessor(file, this, mode); lock (_locker) { OpenFiles.Add(accessor); } return(accessor); }
/// <summary> /// Gets the <see cref="FileViewModel"/> wrapping <paramref name="model"/>, provided it exists in <see cref="OpenFiles"/>. /// </summary> /// <param name="model">The model for which to find the <see cref="FileViewModel"/>.</param> /// <returns>The <see cref="FileViewModel"/> wrapping <paramref name="model"/>, <paramref name="model"/> if it is itself a <see cref="FileViewModel"/>, or null if it does not exist.</returns> public virtual FileViewModel GetFileViewModelForModel(object model) { var fvm = OpenFiles.FirstOrDefault(x => ReferenceEquals(x.Model, model)); if (fvm == null) { return(model as FileViewModel); // Return model or null } else { return(fvm); } }
bool HasModifiedSourceFiles() { List <PerforceFileRecord> OpenFiles; if (!Perforce.GetOpenFiles(ClientRootPath + "/...", out OpenFiles, Log)) { return(true); } if (OpenFiles.Any(x => x.DepotPath.IndexOf("/Source/", StringComparison.InvariantCultureIgnoreCase) != -1)) { return(true); } return(false); }
/// <summary> /// Opens a file from the given filename. /// </summary> /// <param name="filename">Full path of the file to open.</param> /// <param name="modelType">Type of the model of the file.</param> /// <remarks>This overload is intended to open files on disk, using a specific file type, that are not associated with a project. /// To open a project file, use <see cref="OpenFile(Object, Project)"/>. /// To open a file that is not necessarily on disk, use <see cref="OpenFile(Object, Boolean)"/>. /// To open a file, auto-detecting the file type, use <see cref="OpenFile(String)"/>. /// /// When the file is closed, the underlying model will be disposed.</remarks> public virtual async Task OpenFile(string filename, TypeInfo modelType) { var model = await IOHelper.OpenFile(filename, modelType, CurrentPluginManager); if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model))) { var wrapper = CreateViewModel(model); wrapper.Filename = filename; wrapper.DisposeOnClose = true; OpenFiles.Add(wrapper); FileOpened?.Invoke(this, new FileOpenedEventArguments { File = model, FileViewModel = wrapper, DisposeOnExit = true }); } }
private void AddCodes() { var newCodes = new OpenFiles().OpenCodesFile(); if (newCodes != null && newCodes.Count > 0) { bool ok = repository.AddCodes(newCodes); if (ok) { SaveAll(); LoadCodesAsync(); } } }
public void CloseFile(OpenFileViewModel file) { int index = OpenFiles.IndexOf(file); Debug.Assert(index >= 0); file.Dispose(); OpenFiles.RemoveAt(index); if (--index < 0) { index = 0; } if (OpenFiles.Count > 0) { SelectedFile = OpenFiles[index]; } }
/// <summary> /// Opens the given file /// </summary> /// <param name="model">The model to open</param> /// <param name="disposeOnClose">True to call the file's dispose method (if IDisposable) when closed.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is null.</exception> public virtual void OpenFile(object model, bool disposeOnClose) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model))) { var wrapper = CreateViewModel(model); wrapper.DisposeOnClose = disposeOnClose; OpenFiles.Add(wrapper); FileOpened?.Invoke(this, new FileOpenedEventArguments { File = model, FileViewModel = wrapper, DisposeOnExit = disposeOnClose }); } }
/// <summary> /// Closes the file /// </summary> /// <param name="File">File to close</param> public virtual void CloseFile(FileViewModel file) { if (file != null) { var args = new FileClosingEventArgs(); args.File = file; FileClosing?.Invoke(this, args); if (!args.Cancel) { for (var i = OpenFiles.Count - 1; i >= 0; i--) { if (ReferenceEquals(OpenFiles[i], file)) { OpenFiles[i].Dispose(); var openFilesCount = OpenFiles.Count; try { OpenFiles.RemoveAt(i); } catch (NullReferenceException) { // There's been a bug in a dependency where OpenFiles.RemoveAt fails because of UI stuff. // If the same exception is encountered, and the file has actually been removed, then ignore it. if (openFilesCount <= OpenFiles.Count) // OpenFiles.Count should have decreased by 1. If it has not, then throw the exception. { throw; } } } } if (ReferenceEquals(file, SelectedFile)) { SelectedFile = null; } FileClosed?.Invoke(this, new FileClosedEventArgs { File = file.Model }); } } }
public Result OpenFile(out FileAccessor file, U8Span path, OpenMode mode) { file = default; Result rc = FileSystem.OpenFile(out IFile rawFile, path, mode); if (rc.IsFailure()) { return(rc); } var accessor = new FileAccessor(rawFile, this, mode); lock (_locker) { OpenFiles.Add(accessor); } file = accessor; return(Result.Success); }
/// <summary> /// Opens the given file /// </summary> /// <param name="model">File to open</param> /// <param name="parentProject">Project the file belongs to. If the file does not belong to a project, don't use this overload.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> or <paramref name="parentProject"/> is null.</exception> public virtual void OpenFile(object model, Project parentProject) { if (ReferenceEquals(model, null)) { throw (new ArgumentNullException(nameof(model))); } if (ReferenceEquals(parentProject, null)) { throw (new ArgumentNullException(nameof(parentProject))); } if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model))) { var wrapper = CreateViewModel(model); wrapper.DisposeOnClose = false; wrapper.ParentProject = parentProject; OpenFiles.Add(wrapper); FileOpened?.Invoke(this, new FileOpenedEventArguments { File = model, FileViewModel = wrapper, DisposeOnExit = false, ParentProject = parentProject }); } }
public bool QueryCloseAll() { if (!OpenFiles.Any(file => file.IsModified)) { return(true); } var result = MessageBoxService.ShowMessage("Save modified files before exit?", Constants.AppTitle, MessageBoxButton.YesNoCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { foreach (var file in OpenFiles) { if (file.IsModified) { file.SaveInternal(); } } return(true); } return(result == MessageBoxResult.No); }
/// <summary> /// Called at the end of opening this workspace. /// </summary> public void LoadState(bool expandFolders = false, bool openFiles = false) { if (DB == null) { return; } try { Save.LoadingState = true; if (expandFolders) { if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='expanded'") && !s.NE()) { foreach (var v in s.Segments(" ")) { var f = FindById(s[v.Range]); //if (f != null) TreeControl.Expand(f, true); if (f != null) { f.SetIsExpanded(true); } } } } if (openFiles) { if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='open'") && !s.NE()) { //format: indexOfActiveDocOrMinusOne id1 id2 ... int i = -2, iActive = s.ToInt(); FileNode fnActive = null; //perf.first(); foreach (var v in s.Segments(" ")) { i++; if (i < 0) { continue; } var fn = FindById(s[v.Range]); if (fn == null) { continue; } OpenFiles.Add(fn); if (i == iActive) { fnActive = fn; } } //perf.next(); if (fnActive == null || !SetCurrentFile(fnActive)) { _UpdateOpenFiles(null); //disable Previous command } //perf.nw(); } } } catch (Exception ex) { Debug_.Print(ex); } finally { Save.LoadingState = false; } }