public BinaryView(ResourceItem item) { byteDataTextBox.ReadOnly = true; byteDataTextBox.Multiline = true; byteDataTextBox.Top = 24; byteDataTextBox.Left = 0; byteDataTextBox.Width = Width; byteDataTextBox.Height = Height - 24; byteDataTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; byteDataTextBox.Font = WinFormsResourceService.LoadFont("Courier New", 10); byteDataTextBox.ScrollBars = ScrollBars.Both; byteDataTextBox.BackColor = SystemColors.Window; viewHexDumpCheckBox.Location = new Point(8, 4); viewHexDumpCheckBox.Size = new Size(Width - 16, 16); viewHexDumpCheckBox.Text = StringParser.Parse("${res:ResourceEditor.ResourceEdit.ShowAsHexDump}"); viewHexDumpCheckBox.CheckedChanged += new EventHandler(CheckEvt); Controls.Add(byteDataTextBox); Controls.Add(viewHexDumpCheckBox); byteDataTextBox.Select(); ResourceItem = item; }
public override void Run() { ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; if(editor.ResourceList.WriteProtected) { return; } int count = 1; string newNameBase = " new string entry "; string newName = newNameBase + count.ToString(); string type = "System.String"; while(editor.ResourceList.Resources.ContainsKey(newName)) { count++; newName = newNameBase + count.ToString(); } ResourceItem item = new ResourceItem(newName, ""); editor.ResourceList.Resources.Add(newName, item); ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); editor.ResourceList.Items.Add(lv); editor.ResourceList.OnChanged(); lv.BeginEdit(); }
public TextView(ResourceItem item) { this.Multiline = true; this.ResourceItem = item; this.ScrollBars = ScrollBars.Both; this.TextChanged += new EventHandler(textChanged); }
public BitmapView(ResourceItem item) : base(item) { updateLinkLabel = new LinkLabel(); updateLinkLabel.Text = ResourceService.GetString("ResourceEditor.BitmapView.UpdateBitmap"); updateLinkLabel.Location = new Point(4, 4); updateLinkLabel.AutoSize = true; updateLinkLabel.Click += new EventHandler(updateBitmapLinkLabelClick); Controls.Add(updateLinkLabel); }
protected AbstractImageView(ResourceItem item) { Dock = DockStyle.Fill; AutoScroll = true; pictureBox = new PictureBox(); pictureBox.BorderStyle = BorderStyle.FixedSingle; this.SizeChanged += new EventHandler(resized); pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; Controls.Add(this.pictureBox); ResourceItem = item; }
public BooleanView(ResourceItem item) { trueRadioButton.Location = new Point(4, 4); trueRadioButton.Text = "True"; trueRadioButton.CheckedChanged += new EventHandler(valueChanged); Controls.Add(trueRadioButton); falseRadioButton.Location = new Point(4, 24); falseRadioButton.Text = "False"; falseRadioButton.CheckedChanged += new EventHandler(valueChanged); Controls.Add(falseRadioButton); ResourceItem = item; }
void ShowResource(ResourceItem item) { if (item == null) { ShowView(null); return; } if (item.ResourceValue is Icon) { IconView iv = new IconView(item); ShowView(iv); } else if (item.ResourceValue is Bitmap) { BitmapView bv = new BitmapView(item); ShowView(bv); } else if (item.ResourceValue is Cursor) { CursorView cv = new CursorView(item); ShowView(cv); } else if (item.ResourceValue is string) { TextView tv = new TextView(item); ShowView(tv); } else if (item.ResourceValue is byte[]) { BinaryView bv = new BinaryView(item); ShowView(bv); } else if (item.ResourceValue is bool) { BooleanView bv = new BooleanView(item); ShowView(bv); } else { ShowView(null); } }
void ResourceListSelectionChanged(object sender, EventArgs e) { if (resourceList.SelectedItems.Count == 0) { internalState = ListViewViewState.Nothing; ShowResource(null); } else { internalState = ListViewViewState.ItemsSelected; } if (resourceList.SelectedItems.Count != 1) { return; } object key = resourceList.SelectedItems[0].Text; ResourceItem item = (ResourceItem)resourceList.Resources[key.ToString()]; ShowResource(item); }
public void InitializeListView() { BeginUpdate(); // Suspend sorting to improve performance ListViewItemSorter = null; Items.Clear(); foreach (KeyValuePair <string, ResourceItem> entry in resources) { ResourceItem item = entry.Value; string tmp = item.ToString(); string type = item.ResourceValue == null ? "(Nothing/null)" : item.ResourceValue.GetType().FullName; ListViewItem lv = new ListViewItem(new String[] { item.Name, type, tmp }, item.ImageIndex); Items.Add(lv); } ListViewItemSorter = sorter; EndUpdate(); }
public void SaveFile(string filename, Stream stream) { switch (Path.GetExtension(filename).ToLowerInvariant()) { // write XML resource case ".resx": ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename)); foreach (KeyValuePair <string, ResourceItem> entry in resources) { if (entry.Value != null) { ResourceItem item = entry.Value; rxw.AddResource(item.Name, item.ResourceValue); } } foreach (KeyValuePair <string, ResourceItem> entry in metadata) { if (entry.Value != null) { ResourceItem item = entry.Value; rxw.AddMetadata(item.Name, item.ResourceValue); } } rxw.Generate(); rxw.Close(); break; // write default resource default: ResourceWriter rw = new ResourceWriter(stream); foreach (KeyValuePair <string, ResourceItem> entry in resources) { ResourceItem item = (ResourceItem)entry.Value; rw.AddResource(item.Name, item.ResourceValue); } rw.Generate(); rw.Close(); break; } }
void updateBitmapLinkLabelClick(object sender, EventArgs e) { using(OpenFileDialog fileDialog = new OpenFileDialog()) { Bitmap bitmap; fileDialog.AddExtension = true; fileDialog.Filter = "All files (*.*)|*.*"; fileDialog.CheckFileExists = true; if(fileDialog.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { try { bitmap = new Bitmap(fileDialog.FileName); } catch { MessageService.ShowWarning("Can't load bitmap file."); return; } ResourceItem = new ResourceItem(resourceItem.Name, bitmap); OnResourceChanged(resourceItem.Name, bitmap); } } }
void updateBitmapLinkLabelClick(object sender, EventArgs e) { using (OpenFileDialog fileDialog = new OpenFileDialog()) { Bitmap bitmap; fileDialog.AddExtension = true; fileDialog.Filter = "All files (*.*)|*.*"; fileDialog.CheckFileExists = true; if (fileDialog.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { try { bitmap = new Bitmap(fileDialog.FileName); } catch { MessageService.ShowWarning("Can't load bitmap file."); return; } ResourceItem = new ResourceItem(resourceItem.Name, bitmap); OnResourceChanged(resourceItem.Name, bitmap); } } }
public IconView(ResourceItem item) : base(item) { }
public void Paste() { if (resourceEditor.ResourceList.WriteProtected) { return; } IDataObject dob = ClipboardWrapper.GetDataObject(); if (dob == null) return; if (dob.GetDataPresent(typeof(Hashtable).FullName)) { Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable)); foreach (DictionaryEntry entry in tmphash) { object resourceValue = GetClonedResource(entry.Value); ResourceItem item; if (!resourceEditor.ResourceList.Resources.ContainsKey((string)entry.Key)) { item = new ResourceItem(entry.Key.ToString(), resourceValue); } else { int count = 1; string newNameBase = entry.Key.ToString() + " "; string newName = newNameBase + count.ToString(); while(resourceEditor.ResourceList.Resources.ContainsKey(newName)) { count++; newName = newNameBase + count.ToString(); } item = new ResourceItem(newName, resourceValue); } resourceEditor.ResourceList.Resources.Add(item.Name, item); resourceEditor.ResourceList.OnChanged(); } resourceEditor.ResourceList.InitializeListView(); } }
public override void Run() { ResourceEditorControl editor = ((ResourceEditWrapper)WorkbenchSingleton.Workbench.ActiveViewContent).ResourceEditor; ResourceList list = editor.ResourceList; if (list.SelectedItems.Count != 1) { return; } string key = list.SelectedItems[0].Text; if (!list.Resources.ContainsKey(key)) { return; } ResourceItem item = list.Resources[key]; SaveFileDialog sdialog = new SaveFileDialog(); sdialog.AddExtension = true; sdialog.FileName = key; if (item.ResourceValue is Bitmap) { sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); sdialog.DefaultExt = ".png"; } else if (item.ResourceValue is Icon) { sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); sdialog.DefaultExt = ".ico"; } else if (item.ResourceValue is Cursor) { sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); sdialog.DefaultExt = ".cur"; } else if (item.ResourceValue is byte[]) { sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); sdialog.DefaultExt = ".bin"; } else { return; } DialogResult dr = sdialog.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); sdialog.Dispose(); if (dr != DialogResult.OK) { return; } try { if (item.ResourceValue is Icon) { FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); ((Icon)item.ResourceValue).Save(fstr); fstr.Close(); } else if (item.ResourceValue is Image) { Image img = (Image)item.ResourceValue; img.Save(sdialog.FileName); } else { FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); BinaryWriter wr = new BinaryWriter(fstr); wr.Write((byte[])item.ResourceValue); fstr.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Can't save resource to " + sdialog.FileName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public CursorView(ResourceItem item) : base(item) { }
void showResource(ResourceItem item) { if(item == null) { showView(null); return; } if (item.ResourceValue is Icon) { IconView iv = new IconView(item); showView(iv); } else if(item.ResourceValue is Bitmap) { BitmapView bv = new BitmapView(item); showView(bv); } else if(item.ResourceValue is Cursor) { CursorView cv = new CursorView(item); showView(cv); } else if(item.ResourceValue is string) { TextView tv = new TextView(item); showView(tv); } else if(item.ResourceValue is byte[]) { BinaryView bv = new BinaryView(item); showView(bv); } else if(item.ResourceValue is bool) { BooleanView bv = new BooleanView(item); showView(bv); } else { showView(null); } }