Beispiel #1
0
        /// <summary>Execute a search according to the terms currently in the
        ///   entry box.</summary>
        private bool Search()
        {
            AssertHasItems();

            Type int_type = typeof(int);

            GLib.List results = new GLib.List(IntPtr.Zero, int_type);

            lock (Global.DB) {
                if (this.entry.Text.Length > 0)
                {
                    foreach (Item item in this.items)
                    {
                        bool match =
                            item.FitsCriteria(this.entry.SearchBits);

                        if (!match)
                        {
                            continue;
                        }

                        results.Append(item.Handle);
                    }
                }
                else
                {
                    foreach (Item item in this.items)
                    {
                        if (!item.Public)
                        {
                            continue;
                        }

                        results.Append(item.Handle);
                    }
                }
            }

            this.list.Model.RemoveDelta(results);

            foreach (int ptr_i in results)
            {
                IntPtr ptr = new IntPtr(ptr_i);
                this.list.Model.Append(ptr);
            }

            this.list.SelectFirst();

            // Return
            return(false);
        }
        public RadioToolButton(RadioToolButton[] group, string stock_id) : base(IntPtr.Zero)
        {
            if (GetType() != typeof(RadioToolButton))
            {
                GLib.Value[] vals  = new GLib.Value [1];
                string[]     names = { "stock_id" };
                vals [0] = new GLib.Value(stock_id);
                CreateNativeObject(names, vals);
                Group = group;
                return;
            }
            IntPtr stock_id_as_native = GLib.Marshaller.StringToPtrGStrdup(stock_id);
            IntPtr native_group       = IntPtr.Zero;

            if (group != null)
            {
                GLib.List list = new GLib.List(IntPtr.Zero);
                foreach (RadioToolButton item in group)
                {
                    list.Append(item.Handle);
                }
                native_group = list.Handle;
            }
            Raw = gtk_radio_tool_button_new_from_stock(native_group, stock_id_as_native);
            GLib.Marshaller.Free(stock_id_as_native);
        }
Beispiel #3
0
 public RadioMenuItem(RadioMenuItem[] group, string label)
     : base(IntPtr.Zero)
 {
     if (GetType () != typeof (RadioMenuItem)) {
         CreateNativeObject (new string [0], new GLib.Value [0]);
         AccelLabel al = new AccelLabel ("");
         al.TextWithMnemonic = label;
         al.SetAlignment (0.0f, 0.5f);
         Add (al);
         al.AccelWidget = this;
         Group = group;
         return;
     }
     IntPtr native_label = GLib.Marshaller.StringToPtrGStrdup (label);
     IntPtr native_group = IntPtr.Zero;
     if (group != null) {
         GLib.List list = new GLib.List(IntPtr.Zero);
         foreach (RadioMenuItem item in group) {
             list.Append (item.Handle);
         }
         native_group = list.Handle;
     }
     Raw = gtk_radio_menu_item_new_with_mnemonic(native_group, native_label);
     GLib.Marshaller.Free (native_label);
 }
Beispiel #4
0
        public RadioMenuItem(RadioMenuItem[] group, string label) : base(IntPtr.Zero)
        {
            if (GetType() != typeof(RadioMenuItem))
            {
                CreateNativeObject(new string [0], new GLib.Value [0]);
                AccelLabel al = new AccelLabel("");
                al.TextWithMnemonic = label;
                al.SetAlignment(0.0f, 0.5f);
                Add(al);
                al.AccelWidget = this;
                Group          = group;
                return;
            }
            IntPtr native_label = GLib.Marshaller.StringToPtrGStrdup(label);
            IntPtr native_group = IntPtr.Zero;

            if (group != null)
            {
                GLib.List list = new GLib.List(IntPtr.Zero);
                foreach (RadioMenuItem item in group)
                {
                    list.Append(item.Handle);
                }
                native_group = list.Handle;
            }
            Raw = gtk_radio_menu_item_new_with_mnemonic(native_group, native_label);
            GLib.Marshaller.Free(native_label);
        }
Beispiel #5
0
        public static Result XferUriList(Uri[] sources,
                                         Uri[] targets,
                                         XferOptions options,
                                         XferErrorMode errorMode,
                                         XferOverwriteMode overwriteMode,
                                         XferProgressCallback callback)
        {
            XferProgressCallbackWrapper wrapper = new XferProgressCallbackWrapper(callback, null);

            GLib.List sourcesList = new GLib.List(typeof(Uri));
            foreach (Uri uri in sources)
            {
                sourcesList.Append(uri.Handle);
            }

            GLib.List targetsList = new GLib.List(typeof(Uri));
            foreach (Uri uri in targets)
            {
                targetsList.Append(uri.Handle);
            }

            return(gnome_vfs_xfer_uri_list(sourcesList.Handle,
                                           targetsList.Handle,
                                           options, errorMode,
                                           overwriteMode,
                                           wrapper.NativeDelegate,
                                           IntPtr.Zero));
        }
		public RadioToolButton (RadioToolButton[] group) : base (IntPtr.Zero)
		{
			if (GetType () != typeof (RadioToolButton)) {
				CreateNativeObject (new string [0], new GLib.Value [0]);
				Group = group;
				return;
			}
			IntPtr native_group = IntPtr.Zero;
			if (group != null) {
				GLib.List list = new GLib.List(IntPtr.Zero);
				foreach (RadioToolButton item in group) {
					list.Append (item.Handle);
				}
				native_group = list.Handle;
			}
			Raw = gtk_radio_tool_button_new(native_group);
		}
Beispiel #7
0
		protected void OpenFromMime (Hit hit)
		{
			string command = null;
			string uri = null, path = null;

			string mimetype = hit.MimeType;

			// FIXME: This is evil.  Nautilus should be handling
			// inode/directory, not just x-directory/normal
			if (mimetype == "inode/directory")
				mimetype = "x-directory/normal";

			// FIXME: I'm not sure that opening the parent
			// URI (if present) is the right thing to do in
			// all cases, but it does work for all our
			// current cases.
			if (hit.ParentUri != null)
				uri = hit.EscapedParentUri;
			else
				uri = hit.EscapedUri;

#if ENABLE_DESKTOP_LAUNCH
			RunDefaultHandler ("desktop-launch", uri);
#elif ENABLE_XDG_OPEN
			RunDefaultHandler ("xdg-open", uri);
#else
			MimeApplication app;
			app = Mime.GetDefaultApplication (mimetype);
			if (app == null) {
				Console.WriteLine ("Can't open MimeType '{0}'", mimetype);
				return;
			}
			
			bool expect_uris = app.SupportsUris ();
			path = hit.Path;

			GLib.List list = new GLib.List ((IntPtr) 0);
			list.Append (expect_uris ? uri : path);

			Gnome.Vfs.Result result = app.Launch (list);
			if (result != Gnome.Vfs.Result.Ok)
				Console.WriteLine ("Error in opening {0}: {1}", uri, result);
#endif
		}
        public RadioToolButton(RadioToolButton[] group) : base(IntPtr.Zero)
        {
            if (GetType() != typeof(RadioToolButton))
            {
                CreateNativeObject(new string [0], new GLib.Value [0]);
                Group = group;
                return;
            }
            IntPtr native_group = IntPtr.Zero;

            if (group != null)
            {
                GLib.List list = new GLib.List(IntPtr.Zero);
                foreach (RadioToolButton item in group)
                {
                    list.Append(item.Handle);
                }
                native_group = list.Handle;
            }
            Raw = gtk_radio_tool_button_new(native_group);
        }
		public RadioToolButton (RadioToolButton[] group, string stock_id) : base (IntPtr.Zero)
		{
			if (GetType () != typeof (RadioToolButton)) {
				GLib.Value[] vals = new GLib.Value [1];
				string[] names = { "stock_id" };
				vals [0] = new GLib.Value (stock_id);
				CreateNativeObject (names, vals);
				Group = group;
				return;
			}
			IntPtr stock_id_as_native = GLib.Marshaller.StringToPtrGStrdup (stock_id);
			IntPtr native_group = IntPtr.Zero;
			if (group != null) {
				GLib.List list = new GLib.List(IntPtr.Zero);
				foreach (RadioToolButton item in group) {
					list.Append (item.Handle);
				}
				native_group = list.Handle;
			}
			Raw = gtk_radio_tool_button_new_from_stock(native_group, stock_id_as_native);
			GLib.Marshaller.Free (stock_id_as_native);
		}
Beispiel #10
0
		public static Result XferUriList (Uri[] sources,
						  Uri[] targets,
						  XferOptions options,
						  XferErrorMode errorMode,
						  XferOverwriteMode overwriteMode,
						  XferProgressCallback callback)
		{
			XferProgressCallbackWrapper wrapper = new XferProgressCallbackWrapper (callback, null);
			GLib.List sourcesList = new GLib.List (typeof (Uri));
			foreach (Uri uri in sources)
				sourcesList.Append (uri.Handle);
				
			GLib.List targetsList = new GLib.List (typeof (Uri));
			foreach (Uri uri in targets)
				targetsList.Append (uri.Handle);
			
			return gnome_vfs_xfer_uri_list (sourcesList.Handle,
							targetsList.Handle,
							options, errorMode,
							overwriteMode,
							wrapper.NativeDelegate,
							IntPtr.Zero);
		}
Beispiel #11
0
        protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args)
        {
            Debug.WriteLine(5, "Row activated");

            Gtk.TreeIter iter;
            BibtexRecord record;

            if (!Model.GetIter(out iter, args.Path))
            {
                Debug.WriteLine(5, "Failed to open record because of GetIter faliure");
                return;
            }
            record = (BibtexRecord)Model.GetValue(iter, 0);
            string uriString = record.GetURI();

            if (string.IsNullOrEmpty(uriString))
            {
                Debug.WriteLine(5, "Selected record does not have a URI field");
                return;
            }

            var uri  = new Uri(uriString);
            var list = new GLib.List(typeof(String));

            list.Append(uriString);

            if (System.IO.File.Exists(uri.LocalPath))
            {
                bool   uncertain;
                string result;
                byte   data;
                ulong  data_size;

                data_size = 0;

                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    // TODO: Does this work under linux?
                    System.Diagnostics.Process.Start(@uri.ToString());
                }
                else
                {
                    result = GLib.ContentType.Guess(uri.ToString(), out data, data_size, out uncertain);

                    if (result != null & result != "" & !uncertain)
                    {
                        GLib.IAppInfo app;

                        app = GLib.AppInfoAdapter.GetDefaultForType(result, true);

                        if (app != null)
                        {
                            GLib.AppLaunchContext appContext;

                            appContext = new GLib.AppLaunchContext();
                            app.LaunchUris(list, appContext);
                            return;
                        }
                    }
                }
            }
            else
            {
                var md = new Gtk.MessageDialog((Gtk.Window)Toplevel, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading associated file:\n" + uri.LocalPath);
                md.Run();
                md.Destroy();

                Debug.WriteLine(0, "Error loading associated file:\n{0}", uri.LocalPath);
            }
        }
Beispiel #12
0
        public static void OnButtonPressEvent(Gdk.EventButton evnt, Item item)
        {
            if (evnt.Button == 1)
            {
                item.open();
            }
            else if (evnt.Button == 3)
            {
             	Menu popup_menu = new Menu();

                MenuItem open_item = new MenuItem(Mono.Unix.Catalog.GetString("Open"));
                open_item.Activated += delegate { item.open(); };
                popup_menu.Add(open_item);

                MenuItem open_with_item = new MenuItem(Mono.Unix.Catalog.GetString("Open with"));

                Gnome.Vfs.MimeApplication[] application_handlers = Gnome.Vfs.Mime.GetAllApplications(item.mime_type);

                if (application_handlers.Length > 0) {
                    Menu handlers_menu = new Menu();

                    foreach (Gnome.Vfs.MimeApplication m in application_handlers)
                    {
                        MenuItem handlers_menu_item = new MenuItem(m.Name);
                        GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name
                        tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(item.path));
                        Gnome.Vfs.MimeApplication tmp_m = m; // go lambda bug, go
                        handlers_menu_item.Activated += delegate { tmp_m.Launch(tmp); };
                        handlers_menu.Add(handlers_menu_item);
                    }

                    open_with_item.Submenu = handlers_menu;
                }

                popup_menu.Add(open_with_item);

                MenuItem open_folder = new MenuItem(Mono.Unix.Catalog.GetString("Open dir containing file"));
                open_folder.Activated += delegate {
                    string path = item.path;
                    int index = -1;
                    if ((index = path.LastIndexOf('/')) != -1) {
                        Gnome.Vfs.MimeApplication[] folder_handlers = Gnome.Vfs.Mime.GetAllApplications("inode/directory");
                        GLib.List tmp = new GLib.List(typeof(System.String)); // fixme, use better name
                        tmp.Append(Gnome.Vfs.Uri.GetUriFromLocalPath(path.Substring(0, index+1)));
                        folder_handlers[0].Launch(tmp);
                    }
                };
                popup_menu.Add(open_folder);

                MenuItem clipboard_item = new MenuItem(Mono.Unix.Catalog.GetString("Copy path to clipboard"));
                clipboard_item.Activated += delegate {
                    Gtk.Clipboard clipboard_x = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true));
                    clipboard_x.Text = item.path;
                    Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));
                    clipboard.Text = item.path;
                };
                popup_menu.Add(clipboard_item);

                MenuItem labels_item = new MenuItem(Mono.Unix.Catalog.GetString("Labels"));
                Menu categories_menu = new Menu();

                bool first_category = true;

                foreach (Category cat in Singleton<Categories>.Instance.categories) {

                    if (cat.labels.Count > 0 || Singleton<Categories>.Instance.categories.Count == 1) {

                        if (first_category)
                            first_category = false;
                        else
                            categories_menu.Add(new Gtk.SeparatorMenuItem());

                        MenuItem cat_item = new MenuItem(cat.metalabel.label);
                        categories_menu.Add(cat_item);

                        foreach (UserLabel tmp_label in cat.labels) {
                            UserLabel label = tmp_label; // go lambda bug, go

                            if (!item.contains_label(label))
                            {
                                ImageMenuItem label_item = new ImageMenuItem();

                                Gtk.Label l = new Gtk.Label(label.metalabel.label);
                                l.SetAlignment(0f, 0.5f);
                                GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b));
                                label_item.Add(l);

                                label_item.Image = CairoDrawing.create_dot_image(0, 0, 0, 0, 14, 14);

                                label_item.Activated += delegate { item.make_label(label); };
                                categories_menu.Add(label_item);
                            }
                            else
                            {
                                ImageMenuItem label_item = new ImageMenuItem();

                                Gtk.Label l = new Gtk.Label(label.metalabel.label);
                                l.SetAlignment(0f, 0.5f);
                                GtkCommon.set_foreground_color(l, new Gdk.Color(label.metalabel.color.r, label.metalabel.color.g, label.metalabel.color.b));
                                label_item.Add(l);

                                label_item.Image = label.dot();

                                label_item.Activated += delegate { item.remove_label(label); };
                                categories_menu.Add(label_item);
                            }
                        }
                    }
                }

                labels_item.Submenu = categories_menu;

                popup_menu.Add(labels_item);

                popup_menu.Add(new Gtk.SeparatorMenuItem());

                string starred_text = Mono.Unix.Catalog.GetString("Add star");
                if (item.file.starred)
                    starred_text = Mono.Unix.Catalog.GetString("Remove star");

                ImageMenuItem starred_item = new ImageMenuItem(starred_text);
                starred_item.Image = new Gtk.Image(new Gdk.Pixbuf(null, "stock_about.png"));
                starred_item.Activated += delegate { item.update_starred(); };

                popup_menu.Add(starred_item);

                popup_menu.ShowAll();
              			popup_menu.Popup(null, null, null, evnt.Button, evnt.Time);

            }
        }
Beispiel #13
0
		public void HandleOpenWith (object sender, ApplicationActivatedEventArgs e)
		{
			GLib.AppInfo application = e.AppInfo;
			Photo[] selected = SelectedPhotos ();

			if (selected == null || selected.Length < 1)
				return;

			string header = Catalog.GetPluralString ("Create New Version?", "Create New Versions?", selected.Length);
			string msg = String.Format (Catalog.GetPluralString (
				             "Before launching {1}, should F-Spot create a new version of the selected photo to preserve the original?",
				             "Before launching {1}, should F-Spot create new versions of the selected photos to preserve the originals?", selected.Length),
				             selected.Length, application.Name);

			// FIXME add cancel button? add help button?
			HigMessageDialog hmd = new HigMessageDialog (GetToplevel (sender), DialogFlags.DestroyWithParent,
				                       MessageType.Question, Gtk.ButtonsType.None,
				                       header, msg);

			hmd.AddButton (Gtk.Stock.No, Gtk.ResponseType.No, false);
			//hmd.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, false);
			hmd.AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes, true);

			bool support_xcf = false;
			;
			if (application.Id == "gimp.desktop")
				foreach (PixbufFormat format in Gdk.Pixbuf.Formats.Where(format => format.Name == "xcf"))
					support_xcf = true;

			//This allows creating a version with a .xcf extension.
			//There's no need to convert the file to xcf file format, gimp will take care of this
			if (support_xcf) {
				CheckButton cb = new CheckButton (Catalog.GetString ("XCF version"));
				cb.Active = Preferences.Get<bool> (Preferences.EDIT_CREATE_XCF_VERSION);
				hmd.VBox.Add (cb);
				cb.Toggled += (s, ea) => Preferences.Set (Preferences.EDIT_CREATE_XCF_VERSION, (s as CheckButton).Active);
				cb.Show ();
			}

			Gtk.ResponseType response = Gtk.ResponseType.Cancel;

			try {
				response = (Gtk.ResponseType)hmd.Run ();
			} finally {
				hmd.Destroy ();
			}

			bool create_xcf = false;
			if (support_xcf)
				create_xcf = Preferences.Get<bool> (Preferences.EDIT_CREATE_XCF_VERSION);

			Log.DebugFormat ("XCF ? {0}", create_xcf);

			if (response == Gtk.ResponseType.Cancel)
				return;

			bool create_new_versions = (response == Gtk.ResponseType.Yes);

			List<EditException> errors = new List<EditException> ();
			GLib.List uri_list = new GLib.List (typeof(string));
			foreach (Photo photo in selected) {
				try {
					if (create_new_versions) {
						uint version = photo.CreateNamedVersion (application.Name, create_xcf ? ".xcf" : null, photo.DefaultVersionId, true);
						photo.DefaultVersionId = version;
					}
				} catch (Exception ex) {
					errors.Add (new EditException (photo, ex));
				}

				uri_list.Append (photo.DefaultVersion.Uri.ToString ());
			}

			// FIXME need to clean up the error dialog here.
			if (errors.Count > 0) {
				Dialog md = new EditExceptionDialog (GetToplevel (sender), errors.ToArray ());
				md.Run ();
				md.Destroy ();
			}

			if (create_new_versions)
				Database.Photos.Commit (selected);

			try {
				application.LaunchUris (uri_list, null);
			} catch (Exception) {
				Log.ErrorFormat ("Failed to lauch {0}", application.Name);
			}
		}
Beispiel #14
0
		private void OpenWith (Gnome.Vfs.MimeApplication mime_application)
		{
			GLib.List uri_list = new GLib.List (typeof (string));
			uri_list.Append (Hit.EscapedUri);
			mime_application.Launch (uri_list);
		}