Exemple #1
0
        public AppMenuItem(OpenWithMenu menu, MimeApplication mime_application) : base(mime_application.Name)
        {
            App = mime_application;

            if (menu.ShowIcons)
            {
                if (mime_application.Icon != null)
                {
                    Gdk.Pixbuf pixbuf = null;

                    try {
                        if (mime_application.Icon.StartsWith("/"))
                        {
                            pixbuf = new Gdk.Pixbuf(mime_application.Icon, 16, 16);
                        }
                        else
                        {
                            pixbuf = IconTheme.Default.LoadIcon(mime_application.Icon,
                                                                16, (IconLookupFlags)0);
                        }
                    } catch (System.Exception) {
                        pixbuf = null;
                    }

                    if (pixbuf != null)
                    {
                        Image = new Gtk.Image(pixbuf);
                    }
                }
            }
        }
        private DynamicMenu GetDynamicMenu(OpenWithMenu openWithMenu)
        {
            var dynMenuFieldInfo = typeof(OpenWithMenu).GetField("m_dynMenu", BindingFlags.Instance | BindingFlags.NonPublic);

            if (dynMenuFieldInfo != null)
            {
                return(dynMenuFieldInfo.GetValue(openWithMenu) as DynamicMenu);
            }
            return(null);
        }
        private void DetachOnClick(OpenWithMenu openWithMenu)
        {
            var dynMenu = GetDynamicMenu(openWithMenu);

            if (dynMenu != null)
            {
                // Detach our handler
                dynMenu.MenuClick -= mURLDropDownMenu_MenuClick;
            }
        }
        public EntryView(MainForm mainForm, Options options)
        {
            InitializeComponent();

            mMainForm = mainForm;
            mOptions  = options;

            mFieldsGrid.Initialise(mMainForm, mOptions);
            mMultipleSelectionFields.Initialise(mMainForm, mOptions);

            // KeePass 2.24 and above deprecates last access time
            mShowAccessTime = (PwDefs.FileVersion64 < 0x0002001800000000UL) || ((KeePass.Program.Config.UI.UIFlags & 0x20000) != 0);

            mAccessTimeLabel.Visible = mAccessTime.Visible = mShowAccessTime;

            // HACK: MainForm doesn't expose HandleMainWindowKeyMessage, so grab it via reflection
            mHandleMainWindowKeyMessageMethod = mMainForm.GetType().GetMethod("HandleMainWindowKeyMessage", BindingFlags.Instance | BindingFlags.NonPublic);
            if (mHandleMainWindowKeyMessageMethod != null)
            {
                mTabs.KeyDown += HandleMainWindowShortcutKeyDown;
                mTabs.KeyUp   += HandleMainWindowShortcutKeyUp;
            }

            mNotesContextMenu = new RichTextBoxContextMenu();
            mNotesContextMenu.Attach(mNotes, mMainForm);
            mNotes.SimpleTextOnly = true;

            SetLabel(mCreationTimeLabel, KPRes.CreationTime);
            if (mShowAccessTime)
            {
                SetLabel(mAccessTimeLabel, KPRes.LastAccessTime);
            }
            SetLabel(mModificationTimeLabel, KPRes.LastModificationTime);
            SetLabel(mExpiryTimeLabel, KPRes.ExpiryTime);
            SetLabel(mTagsLabel, KPRes.Tags);
            SetLabel(mOverrideUrlLabel, KPRes.UrlOverride);
            SetLabel(mUUIDLabel, KPRes.Uuid);

            TranslatePwEntryFormControls(m_lblIcon, m_cbCustomForegroundColor, m_cbCustomBackgroundColor);

            mEditFieldCommand.ShortcutKeyDisplayString   = KPRes.KeyboardKeyReturn;
            mDeleteFieldCommand.ShortcutKeyDisplayString = UIUtil.GetKeysName(Keys.Delete);
            mCopyCommand.ShortcutKeys = Keys.Control | Keys.C;

            mURLDropDownMenu = new OpenWithMenu(mURLDropDown);
            CustomizeOnClick(mURLDropDownMenu);

            mSplitGridPanels.SplitRatio        = mOptions.FieldsNotesSplitPosition;
            mSplitNotesAttachements.SplitRatio = mOptions.NotesAttachmentsSplitPosition;
        }
        private void CustomizeOnClick(OpenWithMenu openWithMenu)
        {
            // The OpenWithMenu will only open the entry main URL field when clicked, and it's sealed, so have to use reflection to hack it open

            var dynMenu = GetDynamicMenu(openWithMenu);

            if (dynMenu != null)
            {
                var onOpenUrlMethodInfo = typeof(OpenWithMenu).GetMethod("OnOpenUrl", BindingFlags.Instance | BindingFlags.NonPublic);
                if (onOpenUrlMethodInfo != null)
                {
                    // Detach the original handler
                    var onOpenUrlDelegate = Delegate.CreateDelegate(typeof(EventHandler <DynamicMenuEventArgs>), openWithMenu, onOpenUrlMethodInfo) as EventHandler <DynamicMenuEventArgs>;
                    if (onOpenUrlDelegate != null)
                    {
                        dynMenu.MenuClick -= onOpenUrlDelegate;

                        // Attach our handler
                        dynMenu.MenuClick += mURLDropDownMenu_MenuClick;
                    }
                }
            }
        }
Exemple #6
0
    public static OpenWithMenu AppendMenuTo(Gtk.Menu menu, MimeFetcher mime_fetcher, bool with_icon)
    {
        Gtk.MenuItem open_with;

        if (with_icon)
        {
            Gtk.ImageMenuItem img_item = new Gtk.ImageMenuItem(menu_text);
            img_item.Image = new Gtk.Image("gtk-open", Gtk.IconSize.Menu);
            open_with      = img_item;
        }
        else
        {
            open_with = new Gtk.MenuItem(menu_text);
        }

        OpenWithMenu app_menu = new OpenWithMenu(mime_fetcher);

        open_with.Submenu = app_menu;
        open_with.ShowAll();
        open_with.Activated += app_menu.Populate;
        menu.Append(open_with);

        return(app_menu);
    }
Exemple #7
0
        private void HandleURLFields()
        {
            #region URL context menu
            tsmiOpen.Text   = KPRes.OpenCmd;
            tsmiOpen.Image  = (Image)Program.Resources.GetObject("B16x16_FTP");
            tsmiOpen.Click += OnOpenUrl;
            ctxOpenWith.Items.Insert(0, tsmiOpen);
            Dictionary <string, string> translations = Program.Translation.SafeGetStringTableDictionary("KeePass.Forms.MainForm.m_ctxPwList");
            string translated = string.Empty;
            if (translations.TryGetValue("m_ctxEntryCopyUrl", out translated))
            {
                tsmiCopy.Text = translated;
            }
            else
            {
                tsmiCopy.Text = KPRes.Copy;
            }
            tsmiCopy.Image  = (Image)Program.Resources.GetObject("B16x16_EditCopyUrl");
            tsmiCopy.Click += OnCopyUrl;
            ctxOpenWith.Items.Insert(1, tsmiCopy);

            #region Add additional "Open with" entries
            ToolStripMenuItem tsmiOpenWith = new ToolStripMenuItem();
            m_dynOpenUrl = new OpenWithMenu(tsmiOpenWith);
            //Show dropdown to have the entries created
            try
            {
                //Use reflection first
                //Use 'ShowDropDown' as fallback, won't work on Mono
                MethodInfo mi_OnMenuOpening = m_dynOpenUrl.GetType().GetMethod("OnMenuOpening", BindingFlags.Instance | BindingFlags.NonPublic);
                if (mi_OnMenuOpening != null)
                {
                    mi_OnMenuOpening.Invoke(m_dynOpenUrl, new object[] { null, null });
                }
                else
                {
                    tsmiOpenWith.ShowDropDown();
                    tsmiOpenWith.HideDropDown();
                }
            }
            catch { }
            while (tsmiOpenWith.DropDownItems.Count > 0)
            {
                ToolStripItem x = tsmiOpenWith.DropDownItems[0];
                tsmiOpenWith.DropDownItems.Remove(x);
                if (!string.IsNullOrEmpty(m_pcadata.URL2) && (x is ToolStripMenuItem))
                {
                    ToolStripMenuItem newItem = new ToolStripMenuItem(x.Text, x.Image);
                    newItem.Tag    = x.Tag;
                    newItem.Click += OnOpenUrl;
                    x              = newItem;
                }
                ctxOpenWith.Items.Add(x);
            }
            ;
            tsmiOpenWith.Dispose();
            #endregion
            #endregion

            lURL.Links.Clear();
            lURL.Text = KPRes.Url + ": " + KPRes.Empty;
            if (!string.IsNullOrEmpty(m_pcadata.URL))
            {
                string url = CompileUrl(m_pcadata.URL);
                lURL.Links.Add(KPRes.Url.Length + 2, m_pcadata.URL.Length, m_pcadata.URL);
                lURL.Text = KPRes.Url + ": " + GetDisplayUrl(m_pcadata.URL, 60);
            }

            lURL2.Links.Clear();
            lURL2.Text   = KPRes.Url + ": ";
            tbURL2.Left  = lURL2.Left + lURL2.Width;
            tbURL2.Width = ClientSize.Width - tbURL2.Left - lURL2.Left;
            if (!string.IsNullOrEmpty(m_pcadata.URL2))
            {
                tbURL2.Text = m_pcadata.URL2;
            }
        }
	public static OpenWithMenu AppendMenuTo (Gtk.Menu menu, MimeFetcher mime_fetcher, bool with_icon)
	{
		Gtk.MenuItem open_with;
        
        if (with_icon) {
            Gtk.ImageMenuItem img_item = new Gtk.ImageMenuItem (menu_text);
            img_item.Image = new Gtk.Image ("gtk-open", Gtk.IconSize.Menu);
            open_with = img_item;
        } else {
            open_with = new Gtk.MenuItem (menu_text);
        }

		OpenWithMenu app_menu = new OpenWithMenu (mime_fetcher);
		open_with.Submenu = app_menu;
		open_with.ShowAll ();
		open_with.Activated += app_menu.Populate;
		menu.Append (open_with);

		return app_menu;
	}
		public AppMenuItem (OpenWithMenu menu, MimeApplication mime_application) : base (mime_application.Name)
		{
			App = mime_application;
			
			if (menu.ShowIcons) {
				if (mime_application.Icon != null) {
					Gdk.Pixbuf pixbuf = null; 

					try {
						if (mime_application.Icon.StartsWith ("/"))
							pixbuf = new Gdk.Pixbuf (mime_application.Icon, 16, 16);
						else 
							pixbuf = IconTheme.Default.LoadIcon (mime_application.Icon,
											     16, (IconLookupFlags)0);
					} catch (System.Exception) {
						pixbuf = null;
					}

					if (pixbuf != null)
						Image = new Gtk.Image (pixbuf);
				}
			}
		}
	private static void ApplicationsFor (OpenWithMenu menu, string [] mime_types, out ArrayList union, out ArrayList intersection)
	{
		//Console.WriteLine ("Getting applications");
		union = new ArrayList ();
		intersection = new ArrayList ();
		
		if (mime_types == null || mime_types.Length < 1)
			return;

		bool first = true;
		foreach (string mime_type in mime_types) {
			if (mime_type == null)
				continue;

			MimeApplication [] apps = Gnome.Vfs.Mime.GetAllApplications (mime_type);
			for (int i = 0; i < apps.Length; i++) {
				apps [i] = apps [i].Copy ();
			}

			foreach (MimeApplication app in apps) {
				// Skip apps that don't take URIs
				if (! app.SupportsUris ())
					continue;
				
				// Skip apps that we were told to ignore
				if (menu.IgnoreApp != null)
					if (app.BinaryName.IndexOf (menu.IgnoreApp) != -1)
						continue;

				if (! union.Contains (app))
					union.Add (app);
				
				if (first)
					intersection.Add (app);
			}

			if (! first) {
				for (int i = 0; i < intersection.Count; i++) {
					MimeApplication app = intersection [i] as MimeApplication;
					if (System.Array.IndexOf (apps, app) == -1) {
						intersection.Remove (app);
						i--;
					}
				}
			}

			first = false;
		}
	}
Exemple #11
0
    public void Activate(Widget toplevel, Gdk.EventButton eb)
    {
        // FIXME this is a hack to handle the --view case for the time being.
        creator = toplevel;

        if (MainWindow.Toplevel == null)
        {
            return;
        }

        int count = MainWindow.Toplevel.SelectedIds().Length;

        Gtk.Menu popup_menu     = this;
        bool     have_selection = count > 0;

        GtkUtil.MakeMenuItem(popup_menu, Catalog.GetString("Copy Photo Location"),
                             delegate { MainWindow.Toplevel.HandleCopyLocation(creator, null); }, have_selection);

        GtkUtil.MakeMenuSeparator(popup_menu);

        GtkUtil.MakeMenuItem(popup_menu, "f-spot-rotate-270",
                             delegate { MainWindow.Toplevel.HandleRotate270Command(creator, null); }, have_selection);
        GtkUtil.MakeMenuItem(popup_menu, "f-spot-rotate-90",
                             delegate { MainWindow.Toplevel.HandleRotate90Command(creator, null); }, have_selection);

        GtkUtil.MakeMenuSeparator(popup_menu);

        OpenWithMenu owm = OpenWithMenu.AppendMenuTo(popup_menu, MainWindow.Toplevel.SelectedMimeTypes, true);

        owm.IgnoreApp             = "f-spot";
        owm.ApplicationActivated += delegate(Gnome.Vfs.MimeApplication app) { MainWindow.Toplevel.HandleOpenWith(creator, app); };

        GtkUtil.MakeMenuItem(popup_menu, Catalog.GetString("Remove From Catalog"),
                             delegate { MainWindow.Toplevel.HandleRemoveCommand(creator, null); }, have_selection);
        GtkUtil.MakeMenuItem(popup_menu, Catalog.GetString("Delete From Drive"),
                             delegate { MainWindow.Toplevel.HandleDeleteCommand(creator, null); }, have_selection);

        GtkUtil.MakeMenuSeparator(popup_menu);

        //
        // FIXME TagMenu is ugly.
        //
        ImageMenuItem attach_item = new ImageMenuItem(Catalog.GetString("Attach Tag"));

        attach_item.Image = new Gtk.Image("gtk-add", IconSize.Menu);
        TagMenu attach_menu = new TagMenu(attach_item, MainWindow.Toplevel.Database.Tags);

        attach_menu.NewTagHandler += delegate { MainWindow.Toplevel.HandleCreateTagAndAttach(creator, null); };
        attach_menu.TagSelected   += MainWindow.Toplevel.HandleAttachTagMenuSelected;
        attach_item.ShowAll();
        popup_menu.Append(attach_item);

        //
        // FIXME finish the IPhotoSelection stuff and move the activate handler into the class
        // this current method is way too complicated.
        //
        ImageMenuItem remove_item = new ImageMenuItem(Catalog.GetString("Remove Tag"));

        remove_item.Image = new Gtk.Image("gtk-remove", IconSize.Menu);
        PhotoTagMenu remove_menu = new PhotoTagMenu();

        remove_menu.TagSelected += MainWindow.Toplevel.HandleRemoveTagMenuSelected;
        remove_item.Submenu      = remove_menu;
        remove_item.Activated   += MainWindow.Toplevel.HandleTagMenuActivate;
        remove_item.ShowAll();
        popup_menu.Append(remove_item);

        if (eb != null)
        {
            popup_menu.Popup(null, null, null, eb.Button, eb.Time);
        }
        else
        {
            popup_menu.Popup(null, null, null, 0, Gtk.Global.CurrentEventTime);
        }
    }
Exemple #12
0
    private static void ApplicationsFor(OpenWithMenu menu, string [] mime_types, out ArrayList union, out ArrayList intersection)
    {
        //Console.WriteLine ("Getting applications");
        union        = new ArrayList();
        intersection = new ArrayList();

        if (mime_types == null || mime_types.Length < 1)
        {
            return;
        }

        bool first = true;

        foreach (string mime_type in mime_types)
        {
            if (mime_type == null)
            {
                continue;
            }

            MimeApplication [] apps = Gnome.Vfs.Mime.GetAllApplications(mime_type);
            for (int i = 0; i < apps.Length; i++)
            {
                apps [i] = apps [i].Copy();
            }

            foreach (MimeApplication app in apps)
            {
                // Skip apps that don't take URIs
                if (!app.SupportsUris())
                {
                    continue;
                }

                // Skip apps that we were told to ignore
                if (menu.IgnoreApp != null)
                {
                    if (app.BinaryName.IndexOf(menu.IgnoreApp) != -1)
                    {
                        continue;
                    }
                }

                if (!union.Contains(app))
                {
                    union.Add(app);
                }

                if (first)
                {
                    intersection.Add(app);
                }
            }

            if (!first)
            {
                for (int i = 0; i < intersection.Count; i++)
                {
                    MimeApplication app = intersection [i] as MimeApplication;
                    if (System.Array.IndexOf(apps, app) == -1)
                    {
                        intersection.Remove(app);
                        i--;
                    }
                }
            }

            first = false;
        }
    }