Commit 19d224a5 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

When launching gedit check if there is already a gedi window on the

2005-03-08  Paolo Borelli  <pborelli@katamail.com>

	* gedit/GNOME_Gedit.idl:
	* gedit/bonobo-mdi.c:
	* gedit/gedit-application-server.c:
	* gedit/gedit-utils.c:
	* gedit/gedit-utils.h:
	* gedit/gedit2.c:

	When launching gedit check if there is already a gedi window on the
	current workspace: if yes, open the the document there, otherwise
	create a new window.
parent 89325216
2005-03-08 Paolo Borelli <pborelli@katamail.com>
* gedit/GNOME_Gedit.idl:
* gedit/bonobo-mdi.c:
* gedit/gedit-application-server.c:
* gedit/gedit-utils.c:
* gedit/gedit-utils.h:
* gedit/gedit2.c:
When launching gedit check if there is already a gedi window on the
current workspace: if yes, open the the document there, otherwise
create a new window.
==== gedit 2.10.0 ====
==== gedit 2.9.7 ====
......
......@@ -34,7 +34,7 @@ module GNOME {
Window newWindow ();
Document getActiveDocument ();
Window getActiveWindow ();
Window getWindowInWorkspace (in long workspace);
oneway void quit ();
};
......
......@@ -665,10 +665,13 @@ child_list_menu_remove (BonoboMDI *mdi, BonoboWindow *win)
path = g_strdup_printf ("%sView_%p", mdi->priv->child_list_path, views->data);
cmd = g_strdup_printf ("/commands/%s", verb_name);
bonobo_ui_component_remove_verb (ui_component, verb_name);
if (bonobo_ui_component_path_exists (ui_component, path, NULL))
{
bonobo_ui_component_remove_verb (ui_component, verb_name);
bonobo_ui_component_rm (ui_component, path, NULL);
bonobo_ui_component_rm (ui_component, cmd, NULL);
bonobo_ui_component_rm (ui_component, path, NULL);
bonobo_ui_component_rm (ui_component, cmd, NULL);
}
g_free (path);
g_free (cmd);
......
......@@ -42,6 +42,7 @@
#include "GNOME_Gedit.h"
#include "gedit-file.h"
#include "gedit-mdi.h"
#include "gedit-utils.h"
#include "gedit2.h"
......@@ -108,15 +109,47 @@ impl_gedit_application_server_newWindow (PortableServer_Servant _servant,
return BONOBO_OBJREF (win_server);
}
static GNOME_Gedit_Window
impl_gedit_application_server_getActiveWindow (PortableServer_Servant _servant,
CORBA_Environment * ev)
impl_gedit_application_server_getWindowInWorkspace (PortableServer_Servant _servant,
const CORBA_long workspace,
CORBA_Environment *ev)
{
BonoboWindow *win;
BonoboObject *win_server;
GList *l;
guint ws;
/* first try if the active window is in the rquired workspace */
win = bonobo_mdi_get_active_window (BONOBO_MDI (gedit_mdi));
ws = gedit_utils_get_window_workspace (GTK_WINDOW (win));
if (ws != workspace && ws != GEDIT_ALL_WORKSPACES)
{
/* try to see if there is a window on this workspace */
l = bonobo_mdi_get_windows (BONOBO_MDI (gedit_mdi));
while (l != NULL)
{
win = l->data;
ws = gedit_utils_get_window_workspace (GTK_WINDOW (win));
if (ws == workspace || ws == GEDIT_ALL_WORKSPACES)
break;
l = g_list_next (l);
}
/* no window on this workspace... create a new one */
if (l == NULL)
{
bonobo_mdi_open_toplevel (BONOBO_MDI (gedit_mdi), NULL);
gedit_file_new ();
/* let the UI update */
while (gtk_events_pending ())
gtk_main_iteration ();
win = bonobo_mdi_get_active_window (BONOBO_MDI (gedit_mdi));
}
}
win_server = gedit_window_server_new (win);
......@@ -155,11 +188,10 @@ gedit_application_server_class_init (GeditApplicationServerClass *klass)
object_class->finalize = gedit_application_server_object_finalize;
/* connect implementation callbacks */
epv->newWindow = impl_gedit_application_server_newWindow;
epv->getActiveDocument = impl_gedit_application_server_getActiveDocument;
epv->getActiveWindow = impl_gedit_application_server_getActiveWindow;
epv->quit = impl_gedit_application_server_quit;
epv->newWindow = impl_gedit_application_server_newWindow;
epv->getActiveDocument = impl_gedit_application_server_getActiveDocument;
epv->getWindowInWorkspace = impl_gedit_application_server_getWindowInWorkspace;
epv->quit = impl_gedit_application_server_quit;
}
static void
......
......@@ -38,7 +38,11 @@
#include <sys/time.h>
#include <fcntl.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <gdk/gdkx.h>
#include <glib/gunicode.h>
#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs.h>
......@@ -777,6 +781,80 @@ gedit_utils_replace_home_dir_with_tilde (const gchar *uri)
}
g_free (home);
return g_strdup (uri);
}
/* the following two functions are courtesy of galeon */
/**
* gedit_utils_get_current_workspace: Get the current workspace
*
* Get the currently visible workspace for the #GdkScreen.
*
* If the X11 window property isn't found, 0 (the first workspace)
* is returned.
*/
guint
gedit_utils_get_current_workspace (GdkScreen *screen)
{
GdkWindow *root_win = gdk_screen_get_root_window (screen);
GdkDisplay *display = gdk_screen_get_display (screen);
Atom type;
gint format;
gulong nitems;
gulong bytes_after;
guint *current_desktop;
guint ret = 0;
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
0, G_MAXLONG,
False, XA_CARDINAL, &type, &format, &nitems,
&bytes_after, (gpointer)&current_desktop);
if (type == XA_CARDINAL && format == 32 && nitems > 0)
{
ret = current_desktop[0];
XFree (current_desktop);
}
return ret;
}
/**
* gedit_utils_get_window_workspace: Get the workspace the window is on
*
* This function gets the workspace that the #GtkWindow is visible on,
* it returns GEDIT_ALL_WORKSPACES if the window is sticky, or if
* the window manager doesn support this function
*/
guint
gedit_utils_get_window_workspace (GtkWindow *gtkwindow)
{
GdkWindow *window = GTK_WIDGET (gtkwindow)->window;
GdkDisplay *display = gdk_drawable_get_display (window);
Atom type;
gint format;
gulong nitems;
gulong bytes_after;
guint *workspace;
guint ret = GEDIT_ALL_WORKSPACES;
XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
0, G_MAXLONG,
False, XA_CARDINAL, &type, &format, &nitems,
&bytes_after, (gpointer)&workspace);
if (type == XA_CARDINAL && format == 32 && nitems > 0)
{
ret = workspace[0];
XFree (workspace);
}
return ret;
}
......@@ -43,6 +43,8 @@
#define MISSING_FILE N_("Could not find \"%s\". Please, reinstall gedit.\n")
#define MISSING_WIDGETS N_("Could not find the required widgets inside\"%s\". Please, reinstall gedit.\n")
enum { GEDIT_ALL_WORKSPACES = 0xffffffff };
void gedit_utils_flash (const gchar *msg);
void gedit_utils_flash_va (gchar *format, ...);
......@@ -88,6 +90,10 @@ gchar *gedit_utils_uri_get_dirname (const char *uri);
gchar *gedit_utils_replace_home_dir_with_tilde (const gchar *uri);
guint gedit_utils_get_current_workspace (GdkScreen *screen);
guint gedit_utils_get_window_workspace (GtkWindow *gtkwindow);
#endif /* __GEDIT_UTILS_H__ */
......@@ -195,10 +195,16 @@ gedit_handle_automation (GnomeProgram *program)
return;
}
if (new_window_option)
if (new_window_option)
{
window = GNOME_Gedit_Application_newWindow (server, &env);
}
else
window = GNOME_Gedit_Application_getActiveWindow (server, &env);
{
gint ws = gedit_utils_get_current_workspace (gdk_screen_get_default ());
window = GNOME_Gedit_Application_getWindowInWorkspace (server, ws, &env);
}
if (new_document_option)
GNOME_Gedit_Window_newDocument (window, &env);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment