Exemple #1
0
		public ResourceList(ResourceEditorControl editor)
		{
			name.Text     = ResourceService.GetString("Global.Name");
			name.Width    = 250;
			
			type.Text     = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn");
			type.Width    = 170;
			
			content.Text  = ResourceService.GetString("ResourceEditor.ResourceEdit.ContentColumn");
			content.Width = 300;
			
			comment.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.CommentColumn");
			comment.Width = 300;
			
			Columns.AddRange(new ColumnHeader[] {name, type, content, comment});
			
			FullRowSelect = true;
			AutoArrange   = true;
			Alignment     = ListViewAlignment.Left;
			View          = View.Details;
			GridLines     = true;
			LabelEdit     = true;
			Dock          = DockStyle.Fill;
			HideSelection = false;
			
			BorderStyle   = System.Windows.Forms.BorderStyle.None;
			
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.string"));
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bmp"));
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.icon"));
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.cursor"));
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bin"));
			images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.obj"));
			SmallImageList = images;
			
			// Set up sorting:
			// User can sort the list by name and by type,
			// whereas sorting by type also implicitly sorts by name.
			IListViewItemComparer textComparer = new ListViewTextColumnComparer();
			IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0);
			sorter = new ListViewItemSorter(this,
			                                new IListViewItemComparer[] {
			                                	textComparer,
			                                	typeNameComparer,
			                                	null,
			                                	null
			                                });
			sorter.SortColumnIndex = 0;
			sorter.SortOrder = SortOrder.Ascending;
			
			ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu");
		}
        public override void Run()
        {
            ResourceEditorControl editor = ((ResourceEditWrapper)WorkbenchSingleton.Workbench.ActiveViewContent).ResourceEditor;

            if (editor.ResourceList.WriteProtected)
            {
                return;
            }

            using (OpenFileDialog fdiag = new OpenFileDialog()) {
                fdiag.AddExtension    = true;
                fdiag.Filter          = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*");
                fdiag.Multiselect     = true;
                fdiag.CheckFileExists = true;

                if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK)
                {
                    foreach (string filename in fdiag.FileNames)
                    {
                        string oresname = Path.ChangeExtension(Path.GetFileName(filename), null);
                        if (oresname == "")
                        {
                            oresname = "new";
                        }

                        string resname = oresname;

                        int i = 0;
TestName:
                        if (editor.ResourceList.Resources.ContainsKey(resname))
                        {
                            if (i == 10)
                            {
                                continue;
                            }
                            i++;
                            resname = oresname + "_" + i.ToString();
                            goto TestName;
                        }

                        object tmp = loadResource(filename);
                        if (tmp == null)
                        {
                            continue;
                        }
                        editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp));
                    }
                    editor.ResourceList.InitializeListView();
                }
            }
            editor.ResourceList.OnChanged();
        }
        public ResourceList(ResourceEditorControl editor)
        {
            undoStack = new UndoStack();

            name.Text  = ResourceService.GetString("Global.Name");
            name.Width = 250;

            type.Text  = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn");
            type.Width = 170;

            content.Text  = ResourceService.GetString("ResourceEditor.ResourceEdit.ContentColumn");
            content.Width = 300;

            Columns.AddRange(new ColumnHeader[] { name, type, content });

            FullRowSelect = true;
            AutoArrange   = true;
            Alignment     = ListViewAlignment.Left;
            View          = View.Details;
            GridLines     = true;
            LabelEdit     = true;
            Dock          = DockStyle.Fill;
            HideSelection = false;

            BorderStyle = System.Windows.Forms.BorderStyle.None;

            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.string"));
            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bmp"));
            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.icon"));
            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.cursor"));
            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.bin"));
            images.Images.Add(WinFormsResourceService.GetIcon("Icons.16x16.ResourceEditor.obj"));
            SmallImageList = images;

            // Set up sorting:
            // User can sort the list by name and by type,
            // whereas sorting by type also implicitly sorts by name.
            IListViewItemComparer textComparer     = new ListViewTextColumnComparer();
            IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0);

            sorter = new ListViewItemSorter(this,
                                            new IListViewItemComparer[] {
                textComparer,
                typeNameComparer,
                null
            });
            sorter.SortColumnIndex = 0;
            sorter.SortOrder       = SortOrder.Ascending;

            ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu");
        }
        public override void Run()
        {
            ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor;

            if (editor.ResourceList.SelectedItems.Count != 0)
            {
                var    item         = editor.ResourceList.SelectedItems[0].SubItems[3];
                string resourceName = editor.ResourceList.SelectedItems[0].Text;
                string newValue     = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}",
                                                                     "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}",
                                                                     item.Text);
                if (newValue != null && newValue != item.Text)
                {
                    editor.ResourceList.SetCommentValue(resourceName, newValue);
                }
            }
        }
Exemple #5
0
        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);
            }
        }