TreeViewItem TreeView_CreateComputerItem() { string header = LocalString.Get("OpenFolderWindow_RootNode"); TreeViewItem computer = new TreeViewItem { Header = header, IsExpanded = true }; foreach (var drive in DriveInfo.GetDrives()) { TreeViewItem driveItem = new TreeViewItem(); if (drive.IsReady) { driveItem.Header = String.Format("{0} ({1}:)", drive.VolumeLabel, drive.Name[0]); if (Directory.GetDirectories(drive.Name).Length > 0) { driveItem.Items.Add(null); } } else { driveItem.Header = String.Format("{0} ({1}:)", drive.DriveType, drive.Name[0]); } driveItem.Tag = drive.Name; driveItem.Expanded += TreeViewItem_Expanded; driveItem.MouseDoubleClick += TreeViewitem_DoubleClick; driveItem.KeyDown += TreeViewitem_KeyDown; driveItem.Selected += TreeViewItem_Selected; computer.Items.Add(driveItem); } return(computer); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var size = value as long?; if (size.HasValue) { double _size = size.Value; if (_size <= 1024) { return(_size.ToString() + " " + LocalString.Get("Byte_short")); } _size = _size / 1024; if (_size <= 1024) { return(_size.ToString("F2") + " " + LocalString.Get("KB_short")); } _size = _size / 1024; if (_size <= 1024) { return(_size.ToString("F2") + " " + LocalString.Get("MB_short")); } _size = _size / 1024; return(_size.ToString("F2") + " " + LocalString.Get("GB_short")); } else { return(""); } }
protected OpenFileWindowBase(Window owner) { Owner = owner; Files = new ObservableCollection <FileDesc>(); _upLabel = LocalString.Get("OpenFileWindowBase_Up"); InitializeComponent(); Loaded += (sender, args) => { ShowPreview.IsChecked = false; LoadWorkDirs(); // Начальная инициализация if (_lastPath != null) { _currentPath = _lastPath; } else { _currentPath = ((workDirsItem != null) ? workDirsItem.Items[0] : FavouriteItem.Items[0]) as string; } _parentPath = System.IO.Path.GetDirectoryName(_currentPath); DoOpenPath(); // т.к. тут при инициализации установили переменные напрямую, надо оповестить всех об этом OnPropertyChanged("Path"); }; }
public void Move(CodeFile file) { var window = new OpenFolderWindow(System.IO.Path.GetDirectoryName(file.Path)); bool?result = window.ShowDialog(); if (result.HasValue && result.Value) { // Сохраняем исходный file.Save(); try { // Перемещение file.Move(System.IO.Path.Combine(window.Path, file.Name)); CodeProjectManager.Instance.SaveCurrent(); } catch (FileMoveException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_MoveFile_short"), FullDesc = LocalString.Get("Error_MoveFile_full"), Exception = ex }; err.ShowDialog(); } } }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { UInt32 val = 0; bool result = UInt32.TryParse((string)value, out val) && (val > 0); return(new ValidationResult(result, LocalString.Get("ValidationError_PositiveNumber"))); }
public string GetDiagnostic() { string key; switch (ErrorType) { case Type.Type0: key = NeedFullDiagnostic(Type.Type0) ? "Err_0_full" : "Err_0_short"; break; case Type.Type1: key = NeedFullDiagnostic(Type.Type1) ? "Err_1_full" : "Err_1_short"; break; case Type.Type2: key = NeedFullDiagnostic(Type.Type2) ? "Err_2_full" : "Err_2_short"; break; case Type.Type3: key = NeedFullDiagnostic(Type.Type3) ? "Err_3_full" : "Err_3_short"; break; case Type.Type4: key = NeedFullDiagnostic(Type.Type4) ? "Err_4_full" : "Err_4_short"; break; case Type.Type5: key = NeedFullDiagnostic(Type.Type5) ? "Err_5_full" : "Err_5_short"; break; case Type.Type6: key = NeedFullDiagnostic(Type.Type6) ? "Err_6_full" : "Err_6_short"; break; case Type.Type7: key = NeedFullDiagnostic(Type.Type7) ? "Err_7_full" : "Err_7_short"; break; case Type.Type8: key = NeedFullDiagnostic(Type.Type8) ? "Err_8_full" : "Err_8_short"; break; case Type.Type9: key = NeedFullDiagnostic(Type.Type9) ? "Err_9_full" : "Err_9_short"; break; default: return(""); } return(LocalString.Get(key)); }
private void SaveXML() { try { using (var w = new XmlTextWriter(Path, Encoding.UTF8)) { w.Formatting = Formatting.Indented; w.WriteStartElement("Project"); //w.WriteAttributeString("Name", Name); w.WriteAttributeString("NextDefaultFileNumber", NextDefaultFileNumber.ToString()); w.WriteStartElement("Files"); foreach (CodeFile file in Files) { try { file.Save(); // Файл будет записан в проект, только если сохранение успешно прошло w.WriteStartElement("File"); w.WriteAttributeString("Path", file.Path); w.WriteEndElement(); // File } catch (SaveCodeFileException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_SaveFileInProject_short") + " '" + System.IO.Path.GetFileName(ex.FileName) + "'.", FullDesc = LocalString.Get("Error_SaveFileInProject_full"), Exception = ex }; err.ShowDialog(); } } w.WriteEndElement(); // Files w.WriteStartElement("WorkDirs"); foreach (string dir in WorkDirs) { w.WriteStartElement("WorkDir"); w.WriteAttributeString("Path", dir); w.WriteEndElement(); } w.WriteEndElement(); // WorkDirs w.WriteEndElement(); // Project } } catch (IOException ex) { throw new SaveProjectException(Path, ex); } catch (UnauthorizedAccessException ex) { throw new SaveProjectException(Path, ex); } }
private void window1_Loaded(object sender, RoutedEventArgs e) { if (CodeProjectManager.Instance.Current != null) { foreach (string dir in CodeProjectManager.Instance.Current.WorkDirs) { // TODO Сокращение WorkDirs.Add(dir); } } LocalString v = App.Current.Resources["LocalString"] as LocalString; WorkDirs.Add(v.Dict["AddNewFileWindow_AddWorkDir"]); }
public void SaveCurrent() { try { if (Current != null) { Current.Save(); } } catch (SaveProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_SaveProject_short"), FullDesc = LocalString.Get("Error_SaveProject_full"), Exception = ex }; err.ShowDialog(); } }
// Загрузить рабочие директории из проекта (если загружен) private void LoadWorkDirs() { if (CodeProjectManager.Instance.Current == null) { return; } // Load Work dirs from project workDirsItem = new TreeViewItem(); workDirsItem.ItemTemplate = FavouriteItem.ItemTemplate; workDirsItem.ApplyTemplate(); workDirsItem.Header = LocalString.Get("WorkDirs"); workDirsItem.IsExpanded = true; workDirsItem.SetBinding(TreeViewItem.ItemsSourceProperty, new Binding { Source = CodeProjectManager.Instance.Current.WorkDirs }); treeView1.Items.Insert(0, workDirsItem); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var type = (OpenFileWindowBase.FileDesc.Type)value; switch (type) { case OpenFileWindowBase.FileDesc.Type.File: return(LocalString.Get("OpenProjectWindow_ElementType_File")); case OpenFileWindowBase.FileDesc.Type.Dir: return(LocalString.Get("OpenProjectWindow_ElementType_Dir")); case OpenFileWindowBase.FileDesc.Type.Drive: return(LocalString.Get("OpenProjectWindow_ElementType_Drive")); case OpenFileWindowBase.FileDesc.Type.UpDir: return(""); default: return(""); } }
public void Load(string path) { try { // Закрыть предыдущий if (Current != null) { CloseCurrent(); } // Открыть новый Current = CodeProject.Load(path); // Поставить фокус на проджект эксплорер //_mainWindowView.ActivateProjectExplorer(); Logger.LogWithBinding("Status_ProjectOpened"); } catch (ParsingProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_OpenProject_short"), FullDesc = LocalString.Get("Error_OpenProject_full"), Exception = ex }; err.ShowDialog(); } catch (FileNotFoundException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_OpenProject_short"), FullDesc = LocalString.Get("Error_OpenProject_full"), Exception = ex }; err.ShowDialog(); } }
public void CloseCurrent() { try { if (Current != null) { Current.Close(); Current = null; Logger.LogWithBinding("Status_ProjectClosed"); } } catch (SaveProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_CloseProject_short"), FullDesc = LocalString.Get("Error_CloseProject_full"), Exception = ex }; err.ShowDialog(); } }
private void buttonOK_Click(object sender, RoutedEventArgs e) { if (System.IO.Directory.Exists(GetDirectory())) { MessageBoxResult result = MessageBox.Show(LocalString.Get("NewProjectWindow_DirExists"), LocalString.Get("NewProjectWindow_Attention"), MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { IDEState.Get().NextProjectNumber = NextProjectNumber; DialogResult = true; } else { // Ничего, возврат в предыдущую форму } } else { IDEState.Get().NextProjectNumber = NextProjectNumber; DialogResult = true; } }
private void LoadXML() { try { using (var xml_reader = new XmlTextReader(Path)) using (var reader = new XmlValidatingReader(xml_reader)) { int fileErrorsCounter = 0; XmlSchema schema = XmlSchema.Read(new StringReader(Resources.ResourceManager.GetString("ProjectSchema")), null); reader.Schemas.Add(schema); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Project") { //project.Name = reader.GetAttribute("Name"); //project.DefaultCodeFileExtension = reader.GetAttribute("DefaultCodeFileExtension"); NextDefaultFileNumber = Convert.ToInt32(reader.GetAttribute("NextDefaultFileNumber")); } // Files else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Files") { } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "File") { try { CodeFile file = new CodeFile(reader.GetAttribute("Path"), false); AddFile(file, false); } catch (LoadCodeFileException ex) { fileErrorsCounter++; ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_LoadFileInProject_short") + " '" + System.IO.Path.GetFileName(ex.FileName) + "'.", FullDesc = LocalString.Get("Error_LoadFileInProject_full"), Exception = ex }; err.ShowDialog(); } } // WorkDirs else if (reader.NodeType == XmlNodeType.Element && reader.Name == "WorkDirs") { } if (reader.NodeType == XmlNodeType.Element && reader.Name == "WorkDir") { WorkDirs.Add(reader.GetAttribute("Path")); } } if (fileErrorsCounter > 0) { } } } catch (IOException ex) { throw new ParsingProjectException(Path, ex); } catch (XmlException ex) { throw new ParsingProjectException(Path, ex); } catch (XmlSchemaException ex) { throw new ParsingProjectException(Path, ex); } catch (UnauthorizedAccessException ex) { throw new ParsingProjectException(Path, ex); } }
public DiagConverter() { _localString = App.Current.Resources["LocalString"] as LocalString; }
public OpenProjectWindow(Window owner) : base(owner) { base.Title = LocalString.Get("OpenProjectWindow_Title"); }
private void HelpGroupBoxLoaded(object sender, RoutedEventArgs e) { Dictionary <CompileError.Type, int> recent = IDEState.Get().RecentErrors; FlowDocument doc = new FlowDocument(); int[] num = new int[10]; recent.TryGetValue(CompileError.Type.Type0, out num[0]); recent.TryGetValue(CompileError.Type.Type1, out num[1]); recent.TryGetValue(CompileError.Type.Type2, out num[2]); recent.TryGetValue(CompileError.Type.Type3, out num[3]); recent.TryGetValue(CompileError.Type.Type4, out num[4]); recent.TryGetValue(CompileError.Type.Type5, out num[5]); recent.TryGetValue(CompileError.Type.Type6, out num[6]); recent.TryGetValue(CompileError.Type.Type7, out num[7]); recent.TryGetValue(CompileError.Type.Type8, out num[8]); recent.TryGetValue(CompileError.Type.Type9, out num[9]); int max_idx = 0, max = num[0]; for (int i = 1; i < 10; i++) { if (num[i] > max) { max_idx = i; max = num[i]; } } Paragraph par = new Paragraph(); if (IDEState.Get().IsFirstTime) { par.Inlines.Add(LocalString.Get("StartPage_Msg_FirstTime")); doc.Blocks.Add(par); } else if (recent.Count == 0) { par.Inlines.Add(LocalString.Get("StartPage_Msg_NoErrors")); doc.Blocks.Add(par); } else { par.Inlines.Add(LocalString.Get("StartPage_Msg_MostError")); par.Inlines.Add(new Bold(new Run("№" + max_idx))); doc.Blocks.Add(par); string shortDesc = LocalString.Get("Err_" + max_idx.ToString() + "_short"); string fullDesc = LocalString.Get("Err_" + max_idx.ToString() + "_full"); par = new Paragraph(); par.Inlines.Add(LocalString.Get("StartPage_Msg_Short")); par.Inlines.Add(new Bold(new Run(shortDesc))); doc.Blocks.Add(par); par = new Paragraph(); par.Inlines.Add(LocalString.Get("StartPage_Msg_Full")); par.Inlines.Add(new Bold(new Run(fullDesc))); doc.Blocks.Add(par); } richTextBox1.Document = doc; }