Add file filter to FileChooser.
This commit is contained in:
parent
9bc19e9c60
commit
79814b1f00
@ -34,7 +34,7 @@ namespace Novell.CASA.GUI
|
||||
public void on_buttonSaveFile_clicked(object obj, EventArgs args)
|
||||
{
|
||||
FileChooser fc = new FileChooser(FileChooser.ACTION_SAVE);
|
||||
string sFile = fc.GetFile(null, null);
|
||||
string sFile = fc.GetFile(null, null, "*.casa");
|
||||
if (sFile != null)
|
||||
{
|
||||
entrySaveFile.Text = sFile;
|
||||
@ -49,7 +49,7 @@ namespace Novell.CASA.GUI
|
||||
public void on_buttonOpenFile_clicked(object obj, EventArgs args)
|
||||
{
|
||||
FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN);
|
||||
string sFile = fc.GetFile(null, null);
|
||||
string sFile = fc.GetFile(null, null, "*.casa");
|
||||
if (sFile != null)
|
||||
{
|
||||
entryOpenFile.Text = sFile;
|
||||
@ -62,7 +62,7 @@ namespace Novell.CASA.GUI
|
||||
public void on_buttonChooseDirectory_clicked(object obj, EventArgs args)
|
||||
{
|
||||
FileChooser fc = new FileChooser(FileChooser.ACTION_CHOOSE_DIR);
|
||||
string sFile = fc.GetFile(null, null);
|
||||
string sFile = fc.GetFile(null, null, "*.casa");
|
||||
if (sFile != null)
|
||||
{
|
||||
entryChooseDirectory.Text = sFile;
|
||||
|
@ -151,7 +151,7 @@ namespace Novell.CASA.GUI
|
||||
{
|
||||
|
||||
FileChooser fc = new FileChooser(FileChooser.ACTION_SAVE);
|
||||
String sFileName = fc.GetFile(sHintDir, sHintFile);
|
||||
String sFileName = fc.GetFile(sHintDir, sHintFile, "*.casa");
|
||||
|
||||
/*
|
||||
#if W32
|
||||
|
@ -12,6 +12,7 @@ namespace Novell.CASA.GUI
|
||||
public class FileChooser
|
||||
{
|
||||
private string m_currentDirectory;
|
||||
private string m_currentFilter = "*";
|
||||
private string m_hintFile = null;
|
||||
private string m_sFileSelected = null;
|
||||
private bool m_bFileChoosing = true;
|
||||
@ -43,7 +44,8 @@ namespace Novell.CASA.GUI
|
||||
[Glade.Widget]
|
||||
Gtk.Entry entrySelectedFile,
|
||||
entryCurrentDir,
|
||||
entryNewFolder;
|
||||
entryNewFolder,
|
||||
entryFilter;
|
||||
|
||||
[Glade.Widget]
|
||||
Gtk.Button buttonUP,
|
||||
@ -82,7 +84,12 @@ namespace Novell.CASA.GUI
|
||||
DisplayDirectory();
|
||||
}
|
||||
|
||||
public string GetFile(string sHintDir, string sHintFile)
|
||||
public string GetFile(string sHintDir, string sHintFile)
|
||||
{
|
||||
return GetFile(sHintDir, sHintFile, null);
|
||||
}
|
||||
|
||||
public string GetFile(string sHintDir, string sHintFile, string sFilter)
|
||||
{
|
||||
if (sHintDir != null)
|
||||
{
|
||||
@ -94,12 +101,32 @@ namespace Novell.CASA.GUI
|
||||
{
|
||||
m_hintFile = sHintFile;
|
||||
}
|
||||
|
||||
if (sFilter != null)
|
||||
{
|
||||
m_currentFilter = sFilter;
|
||||
}
|
||||
|
||||
DisplayChooser();
|
||||
|
||||
if (m_sFileSelected != null)
|
||||
{
|
||||
// is there a filter?
|
||||
if (m_currentFilter.Length > 0)
|
||||
{
|
||||
int dotPosition = m_currentFilter.LastIndexOf(".");
|
||||
if (dotPosition > 0)
|
||||
{
|
||||
string sFileExt = m_currentFilter.Substring(dotPosition);
|
||||
if (!m_sFileSelected.EndsWith(sFileExt))
|
||||
{
|
||||
return m_currentDirectory + m_sFileSelected + sFileExt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_currentDirectory + m_sFileSelected;
|
||||
|
||||
}
|
||||
else
|
||||
return null;
|
||||
@ -160,8 +187,8 @@ namespace Novell.CASA.GUI
|
||||
else
|
||||
{
|
||||
dialogFileChooser.Title = "Save secrets to ....";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// show logical drives
|
||||
string[] drives = Directory.GetLogicalDrives();
|
||||
@ -204,6 +231,8 @@ namespace Novell.CASA.GUI
|
||||
{
|
||||
if (entryCurrentDir != null)
|
||||
entryCurrentDir.Text = m_currentDirectory;
|
||||
if (entryFilter != null)
|
||||
entryFilter.Text = m_currentFilter;
|
||||
}
|
||||
|
||||
private void DisplayFileListing()
|
||||
@ -221,7 +250,7 @@ namespace Novell.CASA.GUI
|
||||
|
||||
if (m_iAction < FileChooser.ACTION_CHOOSE_DIR)
|
||||
{
|
||||
FileInfo[] files = dirInfo.GetFiles();
|
||||
FileInfo[] files = dirInfo.GetFiles(m_currentFilter);
|
||||
for (int i=0; i<files.Length; i++)
|
||||
{
|
||||
ts.AppendValues(new Gdk.Pixbuf (Common.IMAGE_PATH + "CASA_16.png"), files[i].Name, (files[i].Length/1000).ToString() + " KB", files[i].LastWriteTime.ToShortDateString() + " " + files[i].LastWriteTime.ToShortTimeString());
|
||||
@ -229,6 +258,12 @@ namespace Novell.CASA.GUI
|
||||
}
|
||||
}
|
||||
|
||||
public void on_entryFilter_changed(object obj, EventArgs args)
|
||||
{
|
||||
m_currentFilter = entryFilter.Text;
|
||||
DisplayFileListing();
|
||||
}
|
||||
|
||||
private int GetItemCount(string sDir)
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(sDir);
|
||||
|
@ -35,7 +35,7 @@ namespace Novell.CASA.GUI
|
||||
String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null);
|
||||
|
||||
FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN);
|
||||
sFile = fc.GetFile(sHintDir, sHintFilename);
|
||||
sFile = fc.GetFile(sHintDir, sHintFilename, "*.casa");
|
||||
|
||||
//fc.Show(sHintDir, sHintFilename);
|
||||
//sFile = fc.GetSelectedFile();
|
||||
|
@ -12980,6 +12980,64 @@ to encrypt this file</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox95">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label279">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"> Filter: </property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">5</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkEntry" id="entryFilter">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="visibility">True</property>
|
||||
<property name="max_length">0</property>
|
||||
<property name="text" translatable="yes">*.casa</property>
|
||||
<property name="has_frame">True</property>
|
||||
<property name="invisible_char">*</property>
|
||||
<property name="activates_default">False</property>
|
||||
<signal name="changed" handler="on_entryFilter_changed" last_modification_time="Thu, 07 Sep 2006 19:37:01 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">5</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
|
Loading…
Reference in New Issue
Block a user