diff --git a/CASA/gui/ExportSecrets.cs b/CASA/gui/ExportSecrets.cs index a7eecc92..25e6660d 100644 --- a/CASA/gui/ExportSecrets.cs +++ b/CASA/gui/ExportSecrets.cs @@ -30,6 +30,9 @@ namespace Novell.CASA.GUI [Glade.Widget] Gtk.CheckButton checkbuttonNoEncrypt; + [Glade.Widget] + Gtk.Button buttonNewFolder; + public ExportSecrets(Config config) { m_config = config; @@ -91,7 +94,11 @@ namespace Novell.CASA.GUI if (sFileName != null) { //Store off this location for next export + int iLastSlash = sFileName.LastIndexOf("/"); + if (Common.IS_WINDOWS) + iLastSlash = sFileName.LastIndexOf("\\"); + if (iLastSlash > 0) { sHintFile = sFileName.Substring(iLastSlash + 1); @@ -115,7 +122,7 @@ namespace Novell.CASA.GUI fs.Flush(); fs.Close(); - CommonGUI.DisplayMessage(MessageType.Info, "Secrets saved to: \r\n" + sFileName.Substring(8)); + CommonGUI.DisplayMessage(MessageType.Info, "Secrets saved to: \r\n" + sFileName); } } @@ -137,7 +144,7 @@ namespace Novell.CASA.GUI private string GetStorageFileName(string sHintDir, string sHintFile) { - FileChooser fc = new FileChooser(); + FileChooser fc = new FileChooser(FileChooser.ACTION_SAVE); String sFileName = fc.GetFile(sHintDir, sHintFile); /* diff --git a/CASA/gui/FileChooser.cs b/CASA/gui/FileChooser.cs index fa5074c1..2ba65b3e 100644 --- a/CASA/gui/FileChooser.cs +++ b/CASA/gui/FileChooser.cs @@ -21,13 +21,19 @@ namespace Novell.CASA.GUI private string m_pathSeparator = "/"; + // actions + private int m_iAction = 1; + public const int ACTION_OPEN = 1; + public const int ACTION_SAVE = 2; + Thread tChooserThread = null; #region Glade Widgets [Glade.Widget] - Gtk.Dialog dialogFileChooser; + Gtk.Dialog dialogFileChooser, + dialogNewFolder; [Glade.Widget] Gtk.TreeView treeviewFavorites, @@ -35,17 +41,23 @@ namespace Novell.CASA.GUI [Glade.Widget] Gtk.Entry entrySelectedFile, - entryCurrentDir; + entryCurrentDir, + entryNewFolder; [Glade.Widget] - Gtk.Button buttonUP; + Gtk.Button buttonUP, + buttonNewFolder; + [Glade.Widget] + Gtk.Menu menuDeleteDirFile; #endregion - public FileChooser() + public FileChooser(int action) { + m_iAction = action; + if (Common.IS_WINDOWS) m_pathSeparator = "\\"; @@ -81,7 +93,11 @@ namespace Novell.CASA.GUI } DoWork(); - return m_currentDirectory + m_pathSeparator + m_sFileSelected; + + if (m_sFileSelected != null) + return m_currentDirectory + m_pathSeparator + m_sFileSelected; + else + return null; } @@ -124,6 +140,18 @@ namespace Novell.CASA.GUI Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogFileChooser", null); gxmlTemp.Autoconnect(this); + if (m_iAction == ACTION_OPEN) + { + buttonNewFolder.Visible = false; + entrySelectedFile.Sensitive = false; + dialogFileChooser.Title = "Select the file to open"; + } + else + { + dialogFileChooser.Title = "Save secrets to ...."; + } + + // show logical drives string[] drives = Directory.GetLogicalDrives(); for (int i=0; i 1) { // if windows drive letter, keep the slash @@ -292,6 +348,123 @@ namespace Novell.CASA.GUI private void imageUp_ButtonPressEvent(object o, ButtonPressEventArgs args) { - } + } + + private void treeviewListing_MoveCursor(object o, MoveCursorArgs args) + { + //Console.WriteLine("Cursor moved"); + DisplaySelectedFile(); + } + + private void treeviewListing_ButtonReleaseEvent(object o, ButtonReleaseEventArgs args) + { + + //Console.WriteLine("Button released"); + DisplaySelectedFile(); + + if( 3 == args.Event.Button ) + { + try + { + Logger.DbgLog("GUI:MiCasa.OnRightClicked() - Context menu opened."); + Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "menuDeleteDirFile", null); + gxmlTemp.Autoconnect (this); + menuDeleteDirFile.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime); + } + catch(Exception exp) + { + Logger.DbgLog("GUI:MiCasa.OnRightClicked() - EXCEPTION:" + exp.ToString()); + } + } + } + + public void onDeleteDirFile(object obj, EventArgs args) + { + string sDirFile = entrySelectedFile.Text; + if (sDirFile != null) + { + if (Directory.Exists(m_currentDirectory + m_pathSeparator + sDirFile)) + { + try + { + Directory.Delete(m_currentDirectory + m_pathSeparator + sDirFile); + } + catch (Exception e) + { + CommonGUI.DisplayMessage(Gtk.MessageType.Error, e.ToString()); + } + } + else + { + File.Delete(m_currentDirectory + m_pathSeparator + sDirFile); + } + + DisplayFileListing(); + + } + } + + private void DisplaySelectedFile() + { + TreeModel model; + TreeIter iter; + string selected; + + try + { + if( treeviewListing.Selection.GetSelected (out model, out iter) ) + { + selected = (string) model.GetValue(iter, 1); + entrySelectedFile.Text = selected; + } + } + catch (Exception e) + { + + } + } + + // new folder handler + public void on_buttonNewFolder_clicked(object obj, EventArgs args) + { + //prompt for new folder name + // load and connect handlers + Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogNewFolder", null); + gxmlTemp.Autoconnect(this); + + dialogNewFolder.SetPosition(Gtk.WindowPosition.CenterOnParent); + } + + public void on_okbuttonNewFolder_clicked(object obj, EventArgs args) + { + // create the new folder + string sNewFolder = entryNewFolder.Text; + if (sNewFolder != null) + { + // create folder in currentdir + try + { + Directory.CreateDirectory(m_currentDirectory + m_pathSeparator + sNewFolder); + if (dialogNewFolder != null) + { + dialogNewFolder.Destroy(); + } + + DisplayFileListing(); + } + catch (Exception e) + { + + } + } + } + + public void on_cancelbuttonNewFolder_clicked(object obj, EventArgs args) + { + if (dialogNewFolder != null) + { + dialogNewFolder.Destroy(); + } + } } } diff --git a/CASA/gui/ImportSecrets.cs b/CASA/gui/ImportSecrets.cs index f2f5dc3c..af2f7149 100644 --- a/CASA/gui/ImportSecrets.cs +++ b/CASA/gui/ImportSecrets.cs @@ -34,7 +34,7 @@ namespace Novell.CASA.GUI String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null); string sFile = null; - FileChooser fc = new FileChooser(); + FileChooser fc = new FileChooser(FileChooser.ACTION_OPEN); sFile = fc.GetFile(sHintDir, sHintFilename); //fc.Show(sHintDir, sHintFilename); diff --git a/CASA/gui/images/casa.glade b/CASA/gui/images/casa.glade index 239c26fe..e9125bd9 100644 --- a/CASA/gui/images/casa.glade +++ b/CASA/gui/images/casa.glade @@ -12357,7 +12357,7 @@ in clear text. True - <b>Export miCASA Secrets</b> + <b>Import miCASA Secrets</b> False True GTK_JUSTIFY_LEFT @@ -12531,6 +12531,7 @@ to encrypt this file 525 True True + CASAicons.ico True False False @@ -12576,6 +12577,7 @@ to encrypt this file GTK_RELIEF_NORMAL True -5 + @@ -12602,10 +12604,10 @@ to encrypt this file True - Look in: + Location: False False - GTK_JUSTIFY_LEFT + GTK_JUSTIFY_RIGHT False False 0.5 @@ -12719,6 +12721,23 @@ to encrypt this file False + + + + True + True + New Folder + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + 0 @@ -12831,4 +12850,153 @@ to encrypt this file + + True + New Folder + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ON_PARENT + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + Enter folder name + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + False + False + + + + + 0 + False + False + + + + + + + + + + + True + _Delete + True + + + + + + True + gtk-delete + 1 + 0.5 + 0.5 + 0 + 0 + + + + + +