Commit 0c1ccd7e authored by Pavel Cisler's avatar Pavel Cisler Committed by Pavel Cisler

Bug 1792 - "New Terminal" command in menus. Added a menu item to the

2000-07-27  Pavel Cisler  <pavel@eazel.com>

	* src/file-manager/fm-desktop-icon-view.c:
	(new_terminal_menu_item_callback),
	(fm_desktop_icon_view_create_background_context_menu_items):
	Bug 1792 - "New Terminal" command in menus.
	Added a menu item to the desktop context menu to start a new
	terminal.

	* libnautilus-extensions/nautilus-gnome-extensions.c:
	* libnautilus-extensions/nautilus-gnome-extensions.h:
	(max_open_files), (nautilus_gnome_terminal_shell_execute),
	(nautilus_gnome_open_terminal):
	For the above, added a call to launch a new Terminal, pieced together
	from the origina GMC code, getting rid of some cruft we do not
	need and using stock glib calls where possible.

	* src/file-manager/fm-directory-view.c:
	(new_folder_menu_item_callback), (fm_directory_view_add_menu_item),
	(fm_directory_view_real_create_background_context_menu_items),
	(fm_directory_view_real_create_selection_context_menu_items):
	* src/file-manager/fm-directory-view.h:
	Did a part of 1063 - "The right click desktop menu needs more commands
	to match gmc" that is not covered by a separate bug - added a "New
	Folder" menu item.
	Fixes 1065 and 1067.

	* src/file-manager/dfos-xfer-progress-dialog.c:
	(create_titled_label), (dfos_xfer_progress_dialog_initialize):
	Complete task 1504 - Copy progress dialog needs a visual redesign.
	Made it so that the Copying:, From: and To: lines are packed more
	snugly, as per the design. The spacing of the original GtkLabels
	was too spacy.
	Used a non-zero border to offset the items more from the dialog edges
	to make it look more as designed.
parent fd36e297
2000-07-27 Pavel Cisler <pavel@eazel.com>
* src/file-manager/fm-desktop-icon-view.c:
(new_terminal_menu_item_callback),
(fm_desktop_icon_view_create_background_context_menu_items):
Bug 1792 - "New Terminal" command in menus.
Added a menu item to the desktop context menu to start a new
terminal.
* libnautilus-extensions/nautilus-gnome-extensions.c:
* libnautilus-extensions/nautilus-gnome-extensions.h:
(max_open_files), (nautilus_gnome_terminal_shell_execute),
(nautilus_gnome_open_terminal):
For the above, added a call to launch a new Terminal, pieced together
from the origina GMC code, getting rid of some cruft we do not
need and using stock glib calls where possible.
* src/file-manager/fm-directory-view.c:
(new_folder_menu_item_callback), (fm_directory_view_add_menu_item),
(fm_directory_view_real_create_background_context_menu_items),
(fm_directory_view_real_create_selection_context_menu_items):
* src/file-manager/fm-directory-view.h:
Did a part of 1063 - "The right click desktop menu needs more commands
to match gmc" that is not covered by a separate bug - added a "New
Folder" menu item.
Fixes 1065 and 1067.
* src/file-manager/dfos-xfer-progress-dialog.c:
(create_titled_label), (dfos_xfer_progress_dialog_initialize):
Complete task 1504 - Copy progress dialog needs a visual redesign.
Made it so that the Copying:, From: and To: lines are packed more
snugly, as per the design. The spacing of the original GtkLabels
was too spacy.
Used a non-zero border to offset the items more from the dialog edges
to make it look more as designed.
2000-07-27 Mathieu Lacage <set EMAIL_ADDRESS environment variable>
Fixes a number of bugs from rebecka latest commit.
......
......@@ -162,7 +162,10 @@ create_titled_label (GtkBox *vbox, GtkWidget **title_widget, GtkWidget **label_t
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
/* There might be a cleaner way of packing the text labels closer together
* than using -2 here. The default is too far appart.
*/
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, -2);
gtk_widget_show (hbox);
gtk_widget_set_usize (hbox, LABEL_BOX_WIDTH, 0);
......@@ -190,9 +193,13 @@ dfos_xfer_progress_dialog_initialize (DFOSXferProgressDialog *dialog)
dialog->details = g_new0 (DFOSXferProgressDialogDetails, 1);
gnome_dialog = GNOME_DIALOG (dialog);
vbox = GTK_BOX (gnome_dialog->vbox);
/* This is evil but makes the dialog look less cramped. */
gtk_container_border_width (GTK_CONTAINER (vbox), 5);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, TRUE, TRUE, 3);
gtk_widget_show (hbox);
......
......@@ -25,11 +25,22 @@
*/
#include <config.h>
#include <sys/stat.h>
#include "nautilus-gnome-extensions.h"
#include <libart_lgpl/art_rgb.h>
#include <libart_lgpl/art_rect.h>
#include "nautilus-gdk-extensions.h"
#include <libgnome/gnome-util.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
void
nautilus_gnome_canvas_world_to_window_rectangle (GnomeCanvas *canvas,
......@@ -366,3 +377,168 @@ nautilus_gnome_canvas_set_scroll_region_left_justify (GnomeCanvas *canvas,
(canvas, x1, y1,
MAX (x2, x1 + width), MAX (y2, y1 + height));
}
/* Code from GMC, contains all the voodoo needed to start
* a terminal from the file manager nicely
*/
static int
max_open_files (void)
{
static int files;
if (files != 0) {
return files;
}
#ifdef HAVE_SYSCONF
files = sysconf (_SC_OPEN_MAX);
if (files != -1)
return files;
#endif
#ifdef OPEN_MAX
files = OPEN_MAX;
#else
files = 256;
#endif
return files;
}
static int
nautilus_gnome_terminal_shell_execute (const char *shell, const char *command)
{
struct sigaction ignore, save_intr, save_quit, save_stop;
int status, i;
int pid;
ignore.sa_handler = SIG_IGN;
sigemptyset (&ignore.sa_mask);
ignore.sa_flags = 0;
status = 0;
sigaction (SIGINT, &ignore, &save_intr);
sigaction (SIGQUIT, &ignore, &save_quit);
pid = fork ();
if (pid < 0){
return -1;
}
if (pid == 0){
int top;
struct sigaction default_pipe;
top = max_open_files ();
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
/*
* reset sigpipe
*/
default_pipe.sa_handler = SIG_DFL;
sigemptyset (&default_pipe.sa_mask);
default_pipe.sa_flags = 0;
sigaction (SIGPIPE, &default_pipe, NULL);
for (i = 0; i < top; i++)
close (i);
/* Setup the file descriptor for the child */
/* stdin */
open ("/dev/null", O_APPEND);
/* stdout */
open ("/dev/null", O_RDONLY);
/* stderr */
open ("/dev/null", O_RDONLY);
pid = fork ();
if (pid == 0){
execl (shell, shell, "-c", command, (char *) 0);
/* See note below for why we use _exit () */
_exit (127); /* Exec error */
}
/* We need to use _exit instead of exit to avoid
* calling the atexit handlers (specifically the gdk atexit
* handler
*/
_exit (0);
}
waitpid (pid, &status, 0);
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
sigaction (SIGTSTP, &save_stop, NULL);
return WEXITSTATUS(status);
}
void
nautilus_gnome_open_terminal (const char *command)
{
char *terminal_path;
char *shell;
gboolean quote_all;
char *command_line;
quote_all = FALSE;
/* figure out whichever shell we are using */
shell = gnome_util_user_shell ();
/* Look up a well-known terminal app */
terminal_path = gnome_is_program_in_path ("gnome-terminal");
if (terminal_path != NULL) {
/* apparently gnome-terminal needs it's input nicely quoted and the other
* terminals don't
*/
quote_all = TRUE;
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("dtterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("nxterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("dtterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("color-xterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("rxvt");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("xterm");
}
if (terminal_path == NULL){
g_message (" Could not start a terminal ");
} else if (command){
if (quote_all) {
command_line = g_strconcat (terminal_path, " -e '", command, "'", NULL);
} else {
command_line = g_strconcat (terminal_path, " -e ", command, NULL);
}
nautilus_gnome_terminal_shell_execute (shell, command_line);
g_free (command_line);
} else {
nautilus_gnome_terminal_shell_execute (shell, terminal_path);
}
g_free (shell);
g_free (terminal_path);
}
......@@ -107,4 +107,6 @@ gboolean nautilus_art_irect_contains_irect (const ArtIRect
GtkButton *nautilus_gnome_dialog_get_button_by_index (GnomeDialog *dialog,
int index);
/* Open up a new terminal, optionally passing in a command to execute */
void nautilus_gnome_open_terminal (const char *command);
#endif /* NAUTILUS_GNOME_EXTENSIONS_H */
......@@ -162,7 +162,10 @@ create_titled_label (GtkBox *vbox, GtkWidget **title_widget, GtkWidget **label_t
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
/* There might be a cleaner way of packing the text labels closer together
* than using -2 here. The default is too far appart.
*/
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, -2);
gtk_widget_show (hbox);
gtk_widget_set_usize (hbox, LABEL_BOX_WIDTH, 0);
......@@ -190,9 +193,13 @@ dfos_xfer_progress_dialog_initialize (DFOSXferProgressDialog *dialog)
dialog->details = g_new0 (DFOSXferProgressDialogDetails, 1);
gnome_dialog = GNOME_DIALOG (dialog);
vbox = GTK_BOX (gnome_dialog->vbox);
/* This is evil but makes the dialog look less cramped. */
gtk_container_border_width (GTK_CONTAINER (vbox), 5);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, TRUE, TRUE, 3);
gtk_widget_show (hbox);
......
......@@ -25,11 +25,22 @@
*/
#include <config.h>
#include <sys/stat.h>
#include "nautilus-gnome-extensions.h"
#include <libart_lgpl/art_rgb.h>
#include <libart_lgpl/art_rect.h>
#include "nautilus-gdk-extensions.h"
#include <libgnome/gnome-util.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
void
nautilus_gnome_canvas_world_to_window_rectangle (GnomeCanvas *canvas,
......@@ -366,3 +377,168 @@ nautilus_gnome_canvas_set_scroll_region_left_justify (GnomeCanvas *canvas,
(canvas, x1, y1,
MAX (x2, x1 + width), MAX (y2, y1 + height));
}
/* Code from GMC, contains all the voodoo needed to start
* a terminal from the file manager nicely
*/
static int
max_open_files (void)
{
static int files;
if (files != 0) {
return files;
}
#ifdef HAVE_SYSCONF
files = sysconf (_SC_OPEN_MAX);
if (files != -1)
return files;
#endif
#ifdef OPEN_MAX
files = OPEN_MAX;
#else
files = 256;
#endif
return files;
}
static int
nautilus_gnome_terminal_shell_execute (const char *shell, const char *command)
{
struct sigaction ignore, save_intr, save_quit, save_stop;
int status, i;
int pid;
ignore.sa_handler = SIG_IGN;
sigemptyset (&ignore.sa_mask);
ignore.sa_flags = 0;
status = 0;
sigaction (SIGINT, &ignore, &save_intr);
sigaction (SIGQUIT, &ignore, &save_quit);
pid = fork ();
if (pid < 0){
return -1;
}
if (pid == 0){
int top;
struct sigaction default_pipe;
top = max_open_files ();
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
/*
* reset sigpipe
*/
default_pipe.sa_handler = SIG_DFL;
sigemptyset (&default_pipe.sa_mask);
default_pipe.sa_flags = 0;
sigaction (SIGPIPE, &default_pipe, NULL);
for (i = 0; i < top; i++)
close (i);
/* Setup the file descriptor for the child */
/* stdin */
open ("/dev/null", O_APPEND);
/* stdout */
open ("/dev/null", O_RDONLY);
/* stderr */
open ("/dev/null", O_RDONLY);
pid = fork ();
if (pid == 0){
execl (shell, shell, "-c", command, (char *) 0);
/* See note below for why we use _exit () */
_exit (127); /* Exec error */
}
/* We need to use _exit instead of exit to avoid
* calling the atexit handlers (specifically the gdk atexit
* handler
*/
_exit (0);
}
waitpid (pid, &status, 0);
sigaction (SIGINT, &save_intr, NULL);
sigaction (SIGQUIT, &save_quit, NULL);
sigaction (SIGTSTP, &save_stop, NULL);
return WEXITSTATUS(status);
}
void
nautilus_gnome_open_terminal (const char *command)
{
char *terminal_path;
char *shell;
gboolean quote_all;
char *command_line;
quote_all = FALSE;
/* figure out whichever shell we are using */
shell = gnome_util_user_shell ();
/* Look up a well-known terminal app */
terminal_path = gnome_is_program_in_path ("gnome-terminal");
if (terminal_path != NULL) {
/* apparently gnome-terminal needs it's input nicely quoted and the other
* terminals don't
*/
quote_all = TRUE;
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("dtterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("nxterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("dtterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("color-xterm");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("rxvt");
}
if (terminal_path == NULL) {
terminal_path = gnome_is_program_in_path ("xterm");
}
if (terminal_path == NULL){
g_message (" Could not start a terminal ");
} else if (command){
if (quote_all) {
command_line = g_strconcat (terminal_path, " -e '", command, "'", NULL);
} else {
command_line = g_strconcat (terminal_path, " -e ", command, NULL);
}
nautilus_gnome_terminal_shell_execute (shell, command_line);
g_free (command_line);
} else {
nautilus_gnome_terminal_shell_execute (shell, terminal_path);
}
g_free (shell);
g_free (terminal_path);
}
......@@ -107,4 +107,6 @@ gboolean nautilus_art_irect_contains_irect (const ArtIRect
GtkButton *nautilus_gnome_dialog_get_button_by_index (GnomeDialog *dialog,
int index);
/* Open up a new terminal, optionally passing in a command to execute */
void nautilus_gnome_open_terminal (const char *command);
#endif /* NAUTILUS_GNOME_EXTENSIONS_H */
......@@ -162,7 +162,10 @@ create_titled_label (GtkBox *vbox, GtkWidget **title_widget, GtkWidget **label_t
GtkWidget *hbox;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
/* There might be a cleaner way of packing the text labels closer together
* than using -2 here. The default is too far appart.
*/
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, -2);
gtk_widget_show (hbox);
gtk_widget_set_usize (hbox, LABEL_BOX_WIDTH, 0);
......@@ -190,9 +193,13 @@ dfos_xfer_progress_dialog_initialize (DFOSXferProgressDialog *dialog)
dialog->details = g_new0 (DFOSXferProgressDialogDetails, 1);
gnome_dialog = GNOME_DIALOG (dialog);
vbox = GTK_BOX (gnome_dialog->vbox);
/* This is evil but makes the dialog look less cramped. */
gtk_container_border_width (GTK_CONTAINER (vbox), 5);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (vbox, hbox, TRUE, TRUE, 3);
gtk_widget_show (hbox);
......
......@@ -40,6 +40,7 @@
#include <libgnomevfs/gnome-vfs.h>
#include <libnautilus-extensions/nautilus-directory-private.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <mntent.h>
#include <sys/ioctl.h>
......@@ -208,6 +209,13 @@ fm_desktop_icon_view_initialize (FMDesktopIconView *desktop_icon_view)
find_mount_devices (desktop_icon_view, _PATH_MNTTAB);
}
static void
new_terminal_menu_item_callback (GtkMenuItem *item, FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
nautilus_gnome_open_terminal (NULL);
}
static void
fm_desktop_icon_view_create_background_context_menu_items (FMDirectoryView *view, GtkMenu *menu)
{
......@@ -216,6 +224,8 @@ fm_desktop_icon_view_create_background_context_menu_items (FMDirectoryView *view
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (GTK_IS_MENU (menu));
fm_directory_view_add_menu_item (view, menu, _("New Terminal"), new_terminal_menu_item_callback,
TRUE);
NAUTILUS_CALL_PARENT_CLASS
(FM_DIRECTORY_VIEW_CLASS,
create_background_context_menu_items,
......
......@@ -628,6 +628,13 @@ bonobo_menu_new_folder_callback (BonoboUIHandler *ui_handler, gpointer user_data
fm_directory_view_new_folder (FM_DIRECTORY_VIEW (user_data));
}
static void
new_folder_menu_item_callback (GtkMenuItem *item, FMDirectoryView *directory_view)
{
g_assert (FM_IS_DIRECTORY_VIEW (directory_view));
fm_directory_view_new_folder (directory_view);
}
static void
bonobo_menu_open_properties_window_callback (BonoboUIHandler *ui_handler, gpointer user_data, const char *path)
{
......@@ -1009,7 +1016,6 @@ stop_loading_callback (NautilusView *nautilus_view,
fm_directory_view_stop (directory_view);
}
static void
done_loading (FMDirectoryView *view)
......@@ -1021,8 +1027,6 @@ done_loading (FMDirectoryView *view)
view->details->loading = FALSE;
}
static void
select_all_callback (GtkMenuItem *item, gpointer callback_data)
{
......@@ -2089,8 +2093,8 @@ append_selection_menu_subtree (FMDirectoryView *view,
GTK_WIDGET (child_menu));
}
static void
add_menu_item (FMDirectoryView *view, GtkMenu *menu, const char *label,
void
fm_directory_view_add_menu_item (FMDirectoryView *view, GtkMenu *menu, const char *label,
void (* activate_handler) (GtkMenuItem *, FMDirectoryView *),
gboolean sensitive)
{
......@@ -2106,12 +2110,10 @@ static void
fm_directory_view_real_create_background_context_menu_items (FMDirectoryView *view,
GtkMenu *menu)
{
append_gtk_menu_item_with_view (view,
menu,
NULL,
NAUTILUS_MENU_PATH_SELECT_ALL_ITEM,
select_all_callback,
NULL);
fm_directory_view_add_menu_item (view, menu, _("New Folder"), new_folder_menu_item_callback,
TRUE);
append_gtk_menu_item_with_view (view, menu, NULL,
NAUTILUS_MENU_PATH_SELECT_ALL_ITEM, select_all_callback, NULL);
/* FIXME bugzilla.eazel.com 1261:
* Need to think clearly about what items to include here.
* We want the list to be pretty short, but not degenerately short.
......@@ -2119,11 +2121,11 @@ fm_directory_view_real_create_background_context_menu_items (FMDirectoryView *vi
* (for the current location, not selection -- but would have to not
* include this item when there's a selection)? Add Bookmark? (same issue).
*/
add_menu_item (view, menu, _("Zoom In"), zoom_in_callback,
fm_directory_view_add_menu_item (view, menu, _("Zoom In"), zoom_in_callback,
fm_directory_view_can_zoom_in (view));
add_menu_item (view, menu, _("Zoom Out"), zoom_out_callback,
fm_directory_view_add_menu_item (view, menu, _("Zoom Out"), zoom_out_callback,
fm_directory_view_can_zoom_out (view));
add_menu_item (view, menu, _("Zoom to Default"), zoom_default_callback, TRUE);
fm_directory_view_add_menu_item (view, menu, _("Zoom to Default"), zoom_default_callback, TRUE);
append_gtk_menu_item_with_view (view,
menu,
NULL,
......@@ -2338,9 +2340,6 @@ fm_directory_view_real_create_selection_context_menu_items (FMDirectoryView *vie
append_gtk_menu_item_with_view (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN_IN_NEW_WINDOW,
open_in_new_window_callback, files);
append_gtk_menu_item_with_view (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_NEW_FOLDER,
bonobo_menu_new_folder_callback, view);
append_selection_menu_subtree (view, menu,
create_open_with_gtk_menu (view, files), files,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH);
......
......@@ -266,5 +266,10 @@ NautilusDirectory *fm_directory_view_get_model (FMDirectory
void fm_directory_view_pop_up_background_context_menu (FMDirectoryView *view);
void fm_directory_view_pop_up_selection_context_menu (FMDirectoryView *view);
void fm_directory_view_update_menus (FMDirectoryView *view);
void fm_directory_view_add_menu_item (FMDirectoryView *view,
GtkMenu *menu,
const char *label,
void (* activate_handler) (GtkMenuItem *, FMDirectoryView *),
gboolean sensitive);
#endif /* FM_DIRECTORY_VIEW_H */
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