Import/Export feature

This commit is contained in:
Jim Norman 2006-08-18 21:48:22 +00:00
parent 6b781a6b49
commit 6ddc58eb9c
5 changed files with 608 additions and 4 deletions

View File

@ -190,6 +190,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "FileChooser.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Firefox.cs"
SubType = "Code"

View File

@ -190,6 +190,7 @@ namespace Novell.CASA.GUI
if (m_bShowDebug)
{
message = e.ToString();
Console.WriteLine(e.StackTrace);
}
else
{

277
CASA/gui/FileChooser.cs Normal file
View File

@ -0,0 +1,277 @@
using System;
using System.IO;
using System.Threading;
using Gtk;
namespace Novell.CASA.GUI
{
/// <summary>
/// Summary description for FileChooser.
/// </summary>
public class FileChooser
{
private string m_currentDirectory = "c:/";
private string m_hintFile = null;
private string m_sFileSelected = null;
private bool m_bFileChoosing = true;
private Gtk.TreeStore tsDrives = new TreeStore(typeof(string));
private Gtk.TreeStore ts = new TreeStore(typeof(string), typeof(string));
Thread tChooserThread = null;
Thread tMainThread = null;
#region Glade Widgets
[Glade.Widget]
Gtk.Dialog dialogFileChooser;
[Glade.Widget]
Gtk.TreeView treeviewFavorites,
treeviewListing;
[Glade.Widget]
Gtk.Entry entrySelectedFile,
entryCurrentDir;
[Glade.Widget]
Gtk.Button buttonUP;
#endregion
public FileChooser()
{
//
// TODO: Add constructor logic here
//
}
public string GetFile(string sHintDir, string sHintFile)
{
if (sHintDir != null)
{
if (Directory.Exists(sHintDir))
m_currentDirectory = sHintDir;
}
if (sHintFile != null)
{
m_hintFile = sHintFile;
}
if (true)
{
DoWork();
}
else
{
//start a FileChooser Thread, and suspend this one until a file is selected or user cancels
tChooserThread = new Thread(new ThreadStart(DoWork));
tChooserThread.Start();
// wait for it to start
while (!tChooserThread.IsAlive);
// allow filechooser to run
Thread.Sleep(1);
// wait for FileChooserThread to complete
tChooserThread.Join();
}
return m_currentDirectory + m_sFileSelected;
}
private void DoWork()
{
// display chooser
Show();
// wait for user
while (m_bFileChoosing)
{
// Flush pending events to keep the GUI reponsive
while (Gtk.Application.EventsPending ())
Gtk.Application.RunIteration ();
Thread.Sleep(100);
}
}
public void Show(string sHintDir, string sHintFile)
{
if (sHintDir != null)
{
if (Directory.Exists(sHintDir))
m_currentDirectory = sHintDir;
}
if (sHintFile != null)
{
m_hintFile = sHintFile;
}
this.Show();
}
public void Show()
{
// load and connect handlers
Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogFileChooser", null);
gxmlTemp.Autoconnect(this);
// show logical drives
string[] drives = Directory.GetLogicalDrives();
for (int i=0; i<drives.Length; i++)
{
tsDrives.AppendValues(drives[i]);
}
treeviewFavorites.AppendColumn("Drive", new CellRendererText(), "text", 0);
treeviewFavorites.Model = tsDrives;
treeviewFavorites.RowActivated += new RowActivatedHandler(treeviewFavorites_RowActivated);
// FILE LISTING
// hook up the model
treeviewListing.AppendColumn("Name",new CellRendererText(),"text",0);
treeviewListing.AppendColumn("Date Modified",new CellRendererText(),"text",1);
treeviewListing.Model = ts;
// hook up the events
treeviewListing.RowActivated +=new RowActivatedHandler(treeviewListing_RowActivated);
DisplayFileListing();
if (m_hintFile != null)
entrySelectedFile.Text = m_hintFile;
}
public string GetSelectedFile()
{
return m_sFileSelected;
}
private void DisplayDirectory()
{
entryCurrentDir.Text = m_currentDirectory;
}
private void DisplayFileListing()
{
DisplayDirectory();
// add in the dirs and files
DirectoryInfo dirInfo = new DirectoryInfo(m_currentDirectory);
DirectoryInfo[] dirs = dirInfo.GetDirectories();
for (int i=0; i<dirs.Length; i++)
{
ts.AppendValues(dirs[i].Name, "Folder");
}
FileInfo[] files = dirInfo.GetFiles();
for (int i=0; i<files.Length; i++)
{
ts.AppendValues(files[i].Name, files[i].LastWriteTime.ToShortDateString() + " " + files[i].LastWriteTime.ToShortTimeString());
}
}
private void treeviewListing_RowActivated(object o, RowActivatedArgs args)
{
TreeModel model;
TreeIter iter;
string selected;
try
{
if( treeviewListing.Selection.GetSelected (out model, out iter) )
{
selected = (string) model.GetValue(iter, 0);
if (selected.Equals(".."))
{
// backup one directory
m_currentDirectory = m_currentDirectory.Substring(0, m_currentDirectory.LastIndexOf("/"));
}
else if (Directory.Exists(m_currentDirectory + "/" + selected))
{
m_currentDirectory = m_currentDirectory + "/" + selected;
// clear current view
ts.Clear();
DisplayFileListing();
}
else
{
// file selected
entrySelectedFile.Text = selected;
m_sFileSelected = selected;
// destroy dialog
dialogFileChooser.Destroy();
m_bFileChoosing = false;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void treeviewFavorites_RowActivated(object o, RowActivatedArgs args)
{
// change drive
TreeModel model;
TreeIter iter;
string selected;
try
{
if( treeviewFavorites.Selection.GetSelected (out model, out iter) )
{
selected = (string)model.GetValue(iter, 0);
m_currentDirectory = selected;
ts.Clear();
DisplayFileListing();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public void on_btnCancelFileChooser_clicked(object obj, EventArgs args)
{
m_bFileChoosing = false;
if (dialogFileChooser != null)
{
dialogFileChooser.Destroy();
}
}
public void on_dialogFileChooser_destroy(object o, EventArgs args)
{
m_bFileChoosing = false;
}
public void on_buttonUP_clicked(object o, EventArgs args)
{
Console.WriteLine("Button clicked");
}
private void imageUp_ButtonPressEvent(object o, ButtonPressEventArgs args)
{
}
}
}

View File

@ -31,17 +31,28 @@ namespace Novell.CASA.GUI
{
String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);;
String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null);
string sFile = null;
FileChooser fc = new FileChooser();
sFile = fc.GetFile(sHintDir, sHintFilename);
//fc.Show(sHintDir, sHintFilename);
//sFile = fc.GetSelectedFile();
#if W32
// ask the user to locate the secret file to import
string sFile = CommonGUI.FileChooser(Gtk.FileChooserAction.Open, "Select import file", sHintDir, sHintFilename);
//sFile = CommonGUI.FileChooser(Gtk.FileChooserAction.Open, "Select import file", sHintDir, sHintFilename);
#else
string sFile = null;
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Not implemented");
//sFile = null;
//CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Not implemented");
#endif
if (sFile != null)
{
// parse of the file:///
sFile = sFile.Substring(8);
if (sFile.StartsWith("file:///"))
{
sFile = sFile.Substring(8);
}
if (File.Exists(sFile))
{

View File

@ -12521,4 +12521,314 @@ to encrypt this file</property>
</child>
</widget>
<widget class="GtkDialog" id="dialogFileChooser">
<property name="visible">True</property>
<property name="title" translatable="yes">Choose File</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="modal">True</property>
<property name="default_width">500</property>
<property name="default_height">525</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">True</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">True</property>
<signal name="destroy" handler="on_dialogFileChooser_destroy" last_modification_time="Fri, 18 Aug 2006 21:35:18 GMT"/>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox10">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area10">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="btnCancelFileChooser">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
<signal name="clicked" handler="on_btnCancelFileChooser_clicked" last_modification_time="Thu, 17 Aug 2006 20:41:29 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="btnOkFileChooser">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox89">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkVBox" id="vbox157">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label270">
<property name="visible">True</property>
<property name="label" translatable="yes">Look in:</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">4</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow67">
<property name="width_request">50</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeviewFavorites">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">8</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox156">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox91">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkEntry" id="entryCurrentDir">
<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"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="buttonUP">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_buttonUP_clicked" last_modification_time="Fri, 18 Aug 2006 21:41:25 GMT"/>
<child>
<widget class="GtkImage" id="image3928">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">8</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow66">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeviewListing">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">6</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox90">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label269">
<property name="visible">True</property>
<property name="label" translatable="yes">File name: </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="entrySelectedFile">
<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"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</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>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>