Back to index

lightning-sunbird  0.9+nobinonly
FileBookmark.cs
Go to the documentation of this file.
00001 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Manticore.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Silverstone Interactive.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Ben Goodger <ben@netscape.com> (Original Author)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 namespace Silverstone.Manticore.Bookmarks
00041 {
00042   using System;
00043   using System.Drawing;
00044   using System.Collections;
00045   using System.ComponentModel;
00046   using System.Windows.Forms;
00047 
00048   using Silverstone.Manticore.Toolkit;
00049   using Silverstone.Manticore.Core;
00050 
00054        public class FileBookmark : System.Windows.Forms.Form
00055        {
00056     private Label label1;
00057     private Label label2;
00058     private Label label3;
00059     private BookmarksTreeView mFolderTree;
00060     private Button mOKButton;
00061     private Button mCancelButton;
00062     private Button mUseDefaultButton;
00063     private Button mNewFolderButton;
00064     private TextBox mLocationField;
00065     private TextBox mNameField;
00069               private System.ComponentModel.Container components = null;
00070 
00071               public FileBookmark(String aURL, String aTitle)
00072               {
00073                      //
00074                      // Required for Windows Form Designer support
00075                      //
00076                      InitializeComponent();
00077 
00078       mNameField.Text = aTitle;
00079       mLocationField.Text = aURL;
00080 
00081       //
00082       // Button XP Theme support. 
00083       //
00084       mOKButton.FlatStyle = FlatStyle.System;
00085       mCancelButton.FlatStyle = FlatStyle.System;
00086       mUseDefaultButton.FlatStyle = FlatStyle.System;
00087       mNewFolderButton.FlatStyle = FlatStyle.System;
00088 
00089       // 
00090       // folderTree
00091       // 
00092       mFolderTree = new BookmarksTreeView("BookmarksRoot");
00093       mFolderTree.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
00094         | System.Windows.Forms.AnchorStyles.Left) 
00095         | System.Windows.Forms.AnchorStyles.Right);
00096       mFolderTree.ImageIndex = -1;
00097       mFolderTree.Location = new System.Drawing.Point(64, 88);
00098       mFolderTree.Name = "folderTree";
00099       mFolderTree.SelectedImageIndex = -1;
00100       mFolderTree.Size = new System.Drawing.Size(208, 144);
00101       mFolderTree.TabIndex = 5;
00102 
00103       // Only show folders in this |TreeView|
00104       mFolderTree.AddCriteria(new String[] {"container", "true"});
00105 
00106       Controls.Add(mFolderTree);
00107       mFolderTree.Build();
00108 
00109       Bitmap bmp = new Bitmap(@"resources\bookmark.png");
00110       bmp.MakeTransparent(ColorTranslator.FromOle(0x00FF00));
00111 //      this.Icon = new Icon(
00112               }
00113 
00117               protected override void Dispose(bool aDisposing)
00118               {
00119                      if (aDisposing && components != null)
00120         components.Dispose();
00121                      base.Dispose(aDisposing);
00122               }
00123 
00124               #region Windows Form Designer generated code
00125 
00126 
00127 
00128 
00129               private void InitializeComponent()
00130               {
00131       this.mLocationField = new System.Windows.Forms.TextBox();
00132       this.mCancelButton = new System.Windows.Forms.Button();
00133       this.mNameField = new System.Windows.Forms.TextBox();
00134       this.mNewFolderButton = new System.Windows.Forms.Button();
00135       this.mUseDefaultButton = new System.Windows.Forms.Button();
00136       this.mOKButton = new System.Windows.Forms.Button();
00137       this.label1 = new System.Windows.Forms.Label();
00138       this.label2 = new System.Windows.Forms.Label();
00139       this.label3 = new System.Windows.Forms.Label();
00140       this.SuspendLayout();
00141       // 
00142       // mLocationField
00143       // 
00144       this.mLocationField.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
00145         | System.Windows.Forms.AnchorStyles.Right);
00146       this.mLocationField.Location = new System.Drawing.Point(64, 48);
00147       this.mLocationField.Name = "mLocationField";
00148       this.mLocationField.Size = new System.Drawing.Size(296, 20);
00149       this.mLocationField.TabIndex = 3;
00150       this.mLocationField.Text = "";
00151       // 
00152       // mCancelButton
00153       // 
00154       this.mCancelButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
00155       this.mCancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
00156       this.mCancelButton.Location = new System.Drawing.Point(288, 248);
00157       this.mCancelButton.Name = "mCancelButton";
00158       this.mCancelButton.TabIndex = 9;
00159       this.mCancelButton.Text = "Cancel";
00160       // 
00161       // mNameField
00162       // 
00163       this.mNameField.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
00164         | System.Windows.Forms.AnchorStyles.Right);
00165       this.mNameField.Location = new System.Drawing.Point(64, 16);
00166       this.mNameField.Name = "mNameField";
00167       this.mNameField.Size = new System.Drawing.Size(296, 20);
00168       this.mNameField.TabIndex = 1;
00169       this.mNameField.Text = "";
00170       // 
00171       // mNewFolderButton
00172       // 
00173       this.mNewFolderButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
00174       this.mNewFolderButton.Location = new System.Drawing.Point(280, 88);
00175       this.mNewFolderButton.Name = "mNewFolderButton";
00176       this.mNewFolderButton.Size = new System.Drawing.Size(80, 23);
00177       this.mNewFolderButton.TabIndex = 6;
00178       this.mNewFolderButton.Text = "Ne&w Folder...";
00179       this.mNewFolderButton.Click += new System.EventHandler(this.mNewFolderButton_Click);
00180       // 
00181       // mUseDefaultButton
00182       // 
00183       this.mUseDefaultButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
00184       this.mUseDefaultButton.Location = new System.Drawing.Point(280, 120);
00185       this.mUseDefaultButton.Name = "mUseDefaultButton";
00186       this.mUseDefaultButton.Size = new System.Drawing.Size(80, 23);
00187       this.mUseDefaultButton.TabIndex = 7;
00188       this.mUseDefaultButton.Text = "Use &Default";
00189       // 
00190       // mOKButton
00191       // 
00192       this.mOKButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
00193       this.mOKButton.Location = new System.Drawing.Point(208, 248);
00194       this.mOKButton.Name = "mOKButton";
00195       this.mOKButton.TabIndex = 8;
00196       this.mOKButton.Text = "OK";
00197       this.mOKButton.Click += new System.EventHandler(this.mOKButton_Click);
00198       // 
00199       // label1
00200       // 
00201       this.label1.AutoSize = true;
00202       this.label1.Location = new System.Drawing.Point(8, 16);
00203       this.label1.Name = "label1";
00204       this.label1.Size = new System.Drawing.Size(38, 13);
00205       this.label1.TabIndex = 0;
00206       this.label1.Text = "&Name:";
00207       // 
00208       // label2
00209       // 
00210       this.label2.AutoSize = true;
00211       this.label2.Location = new System.Drawing.Point(8, 48);
00212       this.label2.Name = "label2";
00213       this.label2.Size = new System.Drawing.Size(50, 13);
00214       this.label2.TabIndex = 2;
00215       this.label2.Text = "&Location:";
00216       // 
00217       // label3
00218       // 
00219       this.label3.AutoSize = true;
00220       this.label3.Location = new System.Drawing.Point(8, 88);
00221       this.label3.Name = "label3";
00222       this.label3.Size = new System.Drawing.Size(53, 13);
00223       this.label3.TabIndex = 4;
00224       this.label3.Text = "Create in:";
00225       // 
00226       // FileBookmark
00227       // 
00228       this.AcceptButton = this.mOKButton;
00229       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
00230       this.CancelButton = this.mCancelButton;
00231       this.ClientSize = new System.Drawing.Size(376, 277);
00232       this.ControlBox = false;
00233       this.Controls.AddRange(new System.Windows.Forms.Control[] {
00234                                                                   this.mCancelButton,
00235                                                                   this.mOKButton,
00236                                                                   this.mUseDefaultButton,
00237                                                                   this.mNewFolderButton,
00238                                                                   this.label3,
00239                                                                   this.label2,
00240                                                                   this.label1,
00241                                                                   this.mLocationField,
00242                                                                   this.mNameField});
00243       this.MinimumSize = new System.Drawing.Size(384, 300);
00244       this.Name = "FileBookmark";
00245       this.ShowInTaskbar = false;
00246       this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
00247       this.Text = "File Bookmark";
00248       this.ResumeLayout(false);
00249 
00250     }
00251               #endregion
00252 
00253     private void mNewFolderButton_Click(object sender, System.EventArgs e)
00254     {
00255       mFolderTree.NewFolder();
00256     }
00257 
00258     private void mOKButton_Click(object sender, System.EventArgs e)
00259     {
00260       String destinationFolder = "Bookmarks"; // XXX Parameterize this
00261       ManticoreTreeNode node = mFolderTree.SelectedNode as ManticoreTreeNode;
00262       if (node != null) 
00263         destinationFolder = node.Data as String;
00264       Bookmarks bmks = ServiceManager.Bookmarks;
00265       String bookmarkID = bmks.CreateBookmark(mNameField.Text, destinationFolder, -1);
00266       bmks.SetBookmarkAttribute(bookmarkID, "url", mLocationField.Text);
00267       Close();
00268     }
00269        }
00270 }