Add file selector with auto populated filter.

This commit is contained in:
Starbeamrainbowlabs 2016-08-01 20:41:31 +01:00
parent 4d42de98ab
commit 054d7d5169
2 changed files with 24 additions and 3 deletions

View file

@ -4,6 +4,7 @@ using System.Linq;
using Gtk; using Gtk;
using Ext.SilentorBit; using Ext.SilentorBit;
using System.Drawing.Imaging;
namespace SpritePacker.GUI namespace SpritePacker.GUI
{ {
@ -12,6 +13,8 @@ namespace SpritePacker.GUI
private static bool initialised = false; private static bool initialised = false;
private SpriteListView spriteListDisplay; private SpriteListView spriteListDisplay;
private FileChooserWidget spriteListSelector;
private FileFilter spriteListSelectorFilter;
public MainWindow() : base("SpritePacker GUI") public MainWindow() : base("SpritePacker GUI")
{ {
@ -26,7 +29,7 @@ namespace SpritePacker.GUI
Application.Quit(); Application.Quit();
}; };
setupLayout(); setupWidgets();
} }
/// <summary> /// <summary>
@ -44,23 +47,40 @@ namespace SpritePacker.GUI
Application.Run(); Application.Run();
} }
private void setupLayout() private void setupWidgets()
{ {
// Create the layout containers
HBox masterContainer = new HBox(true, 10); HBox masterContainer = new HBox(true, 10);
VBox leftPanel = new VBox(false, 0) { MarginRight = 5 }; VBox leftPanel = new VBox(false, 0) { MarginRight = 5 };
VBox rightPanel = new VBox(false, 0) { MarginLeft = 5 }; VBox rightPanel = new VBox(false, 0) { MarginLeft = 5 };
Frame leftPanelFrame = new Frame("Sprites") { Child = leftPanel, Margin = 10, MarginRight = 5 }; Frame leftPanelFrame = new Frame("Sprites") { Child = leftPanel, Margin = 10, MarginRight = 5 };
Frame rightPanelFrame = new Frame("Preview") { Child = rightPanel, Margin = 10, MarginLeft = 5 }; Frame rightPanelFrame = new Frame("Preview") { Child = rightPanel, Margin = 10, MarginLeft = 5 };
// Create the file selector filter
spriteListSelectorFilter = new FileFilter() { Name = "Images" };
foreach (ImageCodecInfo currentDecoder in ImageCodecInfo.GetImageDecoders())
spriteListSelectorFilter.AddMimeType(currentDecoder.MimeType);
// Create the file selector
spriteListSelector = new FileChooserWidget(FileChooserAction.Open) {
Margin = 10,
PreviewWidgetActive = true,
Filter = spriteListSelectorFilter
};
// Create the ListView to display the added sprites
spriteListDisplay = new SpriteListView() { Margin = 10 }; spriteListDisplay = new SpriteListView() { Margin = 10 };
spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png")); spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png"));
leftPanel.OverrideBackgroundColor(StateFlags.Normal, Gdk.RGBA.Zero); // Populate the left panel
leftPanel.PackStart(spriteListSelector, true, true, 0);
leftPanel.PackStart(spriteListDisplay, true, true, 0); leftPanel.PackStart(spriteListDisplay, true, true, 0);
// Pack the master container
masterContainer.PackStart(leftPanelFrame, true, true, 0); masterContainer.PackStart(leftPanelFrame, true, true, 0);
masterContainer.PackStart(rightPanelFrame, true, true, 0); masterContainer.PackStart(rightPanelFrame, true, true, 0);
// Add the master container to the window itself
Add(masterContainer); Add(masterContainer);
} }
} }

View file

@ -52,6 +52,7 @@
<Reference Include="pango-sharp"> <Reference Include="pango-sharp">
<HintPath>..\packages\GtkSharp.3.1.3\lib\net45\pango-sharp.dll</HintPath> <HintPath>..\packages\GtkSharp.3.1.3\lib\net45\pango-sharp.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Drawing" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />