Esempio n. 1
0
/**
 * ephy_node_view_edit:
 * @view: an #EphyNodeView
 * @remove_if_cancelled: whether the edited node should be removed if editing is cancelled
 *
 * Edits the currently selected node in @view, the @remove_if_cancelled parameter
 * controls if the node should be removed if editing is cancelled.
 **/
void
ephy_node_view_edit (EphyNodeView *view, gboolean remove_if_cancelled)
{
	GtkTreePath *path;
	GtkTreeSelection *selection;
	GList *rows;
	GtkTreeModel *model;

	g_return_if_fail (view->priv->editable_renderer != NULL);

	selection = gtk_tree_view_get_selection
		(GTK_TREE_VIEW (view));
	rows = gtk_tree_selection_get_selected_rows (selection, &model);
	if (rows == NULL) return;

	path = rows->data;

	g_object_set (G_OBJECT (view->priv->editable_renderer),
		      "editable", TRUE,
		      NULL);

	gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
				  view->priv->editable_column,
				  TRUE);

	view->priv->edited_node = get_node_from_path (view, path);
	view->priv->remove_if_cancelled = remove_if_cancelled;

	g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
	g_list_free (rows);
}
Esempio n. 2
0
int rename_file(char* dest, char* file, char * new_name, int client_id){
	string local_old_path, server_old_path, local_new_path, server_new_path;
	string position, file_folder;
	string old_repo_path = calloc(1, MAX_PATH_LENGTH);
	string filename, newname, file_path, new_path;
	char old_file[MAX_PATH_LENGTH];
	char old_new_name[MAX_PATH_LENGTH];
	int version;
	struct dirent entry;
	struct dirent * result;
	DIR * old;
	local_old_path = append_to_path(dest, file);
	local_new_path = append_to_path(dest, new_name);
	server_old_path = append_to_path(REPOSITORY_PATH, file);
	server_new_path = append_to_path(REPOSITORY_PATH, new_name);
	if (!get_node_from_path(repository_tree, file)) {
		client_send("File not found in server", client_id);
		client_send(END_OF_TRANSMISSION, client_id);
		return NON_EXISTING_FILE;
	} 
	
	run_command(COMMAND_MV, local_old_path, local_new_path);
	run_command(COMMAND_MV, server_old_path, server_new_path);
	
	file_folder = remove_last_appended(file);
	old_repo_path = append_to_path(OLD_REPO_PATH, file_folder);
	
	if (!(old = opendir(old_repo_path))) {
		client_send("File renamed", client_id);
		client_send(END_OF_TRANSMISSION, client_id);
		return SUCCESS;
	}
	
	filename = get_last_path(file);
	newname = get_last_path(new_name);
	
	do {
		readdir_r(old, &entry, &result);
		if ( strncmp(entry.d_name, ".", 1) && strncmp(entry.d_name, "..", 2)){
			if (!strncmp(filename, entry.d_name, strlen(filename))) {
				position = strchr(entry.d_name, '-');
				if (position) {
					sscanf(position+1, "%d", &version);
					sprintf(old_new_name, "%s-%d", newname, version); 
					file_path = append_to_path(old_repo_path, entry.d_name);
					new_path = append_to_path(old_repo_path, old_new_name);
					run_command(COMMAND_MV, file_path, new_path);
				}
			}
		}
	} while ( result != NULL );

	repository_tree = (fstree_t)new_fstree();
	retrieve_tree(REPOSITORY_PATH, repository_tree->root);
	
	client_send("File renamed.", client_id);
	client_send(END_OF_TRANSMISSION, client_id);
}
Esempio n. 3
0
static void
check_node_is_drag_source (GtkTreeModel *model,
			   GtkTreePath *path,
			   GtkTreeIter *iter,
			   ForeachData *data)
{
	EphyNode *node;

	node = get_node_from_path (data->view, path);
	data->result = data->result &&
		       node != NULL &&
		       ephy_node_get_is_drag_source (node);
}
Esempio n. 4
0
static void
get_selection (GtkTreeModel *model,
	       GtkTreePath *path,
	       GtkTreeIter *iter,
	       gpointer *data)
{
	GList **list = data[0];
	EphyNodeView *view = EPHY_NODE_VIEW (data[1]);
	EphyNode *node;

	node = get_node_from_path (view, path);

	*list = g_list_prepend (*list, node);
}
Esempio n. 5
0
static void
drag_data_received_cb (GtkWidget *widget,
		       GdkDragContext *context,
		       int x,
		       int y,
		       GtkSelectionData *selection_data,
		       guint info,
		       guint32 time,
		       EphyNodeView *view)
{
	GtkTreeViewDropPosition pos;

	/* x and y here are valid only on drop ! */

	if ((gtk_selection_data_get_length (selection_data) <= 0) ||
	    (gtk_selection_data_get_data (selection_data) == NULL))
	{
		return;
	}	

	/* appease GtkTreeView by preventing its drag_data_receive
	* from being called */
	g_signal_stop_emission_by_name (view, "drag_data_received");

	if (!view->priv->have_drag_data)
	{
		view->priv->have_drag_data = TRUE;
		view->priv->drag_data = 
			gtk_selection_data_copy (selection_data);
	}

	if (view->priv->drop_occurred)
	{
		EphyNode *node;
		char **uris;
		gboolean success = FALSE;
		GtkTreePath *path;

		if (gtk_tree_view_get_dest_row_at_pos
			(GTK_TREE_VIEW (widget), x, y, &path, &pos) == FALSE)
		{
			return;
		}

		node = get_node_from_path (view, path);
		if (node == NULL) return;

		uris = gtk_selection_data_get_uris (selection_data);

		if (uris != NULL && ephy_node_get_is_drag_dest (node))
		{
			/* FIXME fill success */
			g_signal_emit (G_OBJECT (view),
				       ephy_node_view_signals[NODE_DROPPED], 0,
				       node, uris);
			g_strfreev (uris);

		}

		view->priv->drop_occurred = FALSE;
		free_drag_data (view);
		gtk_drag_finish (context, success, FALSE, time);

		if (path)
		{
			gtk_tree_path_free (path);
		}
	}
}
Esempio n. 6
0
static gboolean
drag_motion_cb (GtkWidget *widget,
		GdkDragContext *context,
		int x,
		int y,
		guint32 time,
		EphyNodeView *view)
{
	EphyNode *node;
	GdkAtom target;
	GtkTreePath *path;
	GtkTreeViewDropPosition pos;
	guint action = 0;
	int priority;

	gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
					   x, y, &path, &pos);
	
	if (!view->priv->have_drag_data)
	{
		get_drag_data (view, context, time);
	}

	target = gtk_drag_dest_find_target (widget, context, NULL);
	node = get_node_from_path (view, path);

	if (target != GDK_NONE && node != NULL)
	{
		priority = ephy_node_get_property_int
				(node, view->priv->priority_prop_id);

		if (priority != EPHY_NODE_VIEW_ALL_PRIORITY &&
		    priority != EPHY_NODE_VIEW_SPECIAL_PRIORITY &&
		    ephy_node_get_is_drag_source (node))
		{
			action = gdk_drag_context_get_suggested_action (context);
		}
	}
	
	if (action)
	{
		set_drag_dest_row (view, path);
	}
	else
	{
		clear_drag_dest_row (view);
	}
	
	if (path)
	{
		gtk_tree_path_free (path);
	}
	
	if (view->priv->scroll_id == 0)
	{
		view->priv->scroll_id = 
			g_timeout_add (150, 
				       scroll_timeout, 
				       GTK_TREE_VIEW (view));
	}

	gdk_drag_status (context, action, time);

	return TRUE;
}