From 79814b1f007fa25c03555ca8ea742710532a5f8d Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Thu, 7 Sep 2006 20:07:32 +0000 Subject: [PATCH] Add file filter to FileChooser. --- CASA/gui/DbgFileChooser.cs | 6 ++-- CASA/gui/ExportSecrets.cs | 2 +- CASA/gui/FileChooser.cs | 45 +++++++++++++++++++++++++---- CASA/gui/ImportSecrets.cs | 2 +- CASA/gui/images/casa.glade | 58 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 10 deletions(-) diff --git a/CASA/gui/DbgFileChooser.cs b/CASA/gui/DbgFileChooser.cs index a0e3c873..f0da5424 100644 --- a/CASA/gui/DbgFileChooser.cs +++ b/CASA/gui/DbgFileChooser.cs @@ -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; diff --git a/CASA/gui/ExportSecrets.cs b/CASA/gui/ExportSecrets.cs index 35ea6106..889e6310 100644 --- a/CASA/gui/ExportSecrets.cs +++ b/CASA/gui/ExportSecrets.cs @@ -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 diff --git a/CASA/gui/FileChooser.cs b/CASA/gui/FileChooser.cs index 8a4b7821..9706c2c6 100644 --- a/CASA/gui/FileChooser.cs +++ b/CASA/gui/FileChooser.cs @@ -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 True + + + + True + False + 0 + + + + True + Filter: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 5 + False + False + + + + + + True + True + True + True + 0 + *.casa + True + * + False + + + + 5 + True + True + + + + + 0 + False + True + + 0