Пример #1
0
static void
on_dialog_response(GtkDialog* dialog, gint response_id, gpointer user_data)
{
    QuickOpenPlugin* self = user_data;

    gtk_widget_hide(GTK_WIDGET(dialog));

    if (response_id == GTK_RESPONSE_ACCEPT)
    {
        GObject* object;

        object = quick_open_dialog_get_selected_object(self->dialog);
        if (!object)
            return;

        if (IANJUTA_IS_DOCUMENT(object))
        {
            ianjuta_document_manager_set_current_document(self->docman,
                IANJUTA_DOCUMENT(object), NULL);
        }
        else if (G_IS_FILE(object))
        {
            IAnjutaFileLoader* loader;

            loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (self)->shell,
                IAnjutaFileLoader, NULL);
            g_return_if_fail (loader != NULL);

            ianjuta_file_loader_load (loader, G_FILE(object), FALSE, NULL);
        }

        g_object_unref(object);
    }
}
/**
* ianjuta_document_manager_remove_document:
* @obj: Self
* @document: Document to close.
* @save_before: If true, saves the document before closing.
* @err: Error propagation and reporting.
*
* Closes and removes the given document. If @save_before is TRUE, also
* saves the document before closing.
*
* Return value: TRUE if the document was removed, else FALSE.
*/
gboolean
ianjuta_document_manager_remove_document (IAnjutaDocumentManager *obj, IAnjutaDocument *document,   gboolean save_before, GError **err)
{
	g_return_val_if_fail (IANJUTA_IS_DOCUMENT_MANAGER(obj), FALSE);
	g_return_val_if_fail ((document == NULL) ||IANJUTA_IS_DOCUMENT(document), FALSE);
	return IANJUTA_DOCUMENT_MANAGER_GET_IFACE (obj)->remove_document (obj, document, save_before, err);
}
/**
* ianjuta_document_manager_set_current_document:
* @obj: Self
* @document: the document to set as current.
* @err: Error propagation and reporting.
*
* Sets the given document as current document.
*/
void
ianjuta_document_manager_set_current_document (IAnjutaDocumentManager *obj, IAnjutaDocument *document, GError **err)
{
	g_return_if_fail (IANJUTA_IS_DOCUMENT_MANAGER(obj));
	g_return_if_fail ((document == NULL) ||IANJUTA_IS_DOCUMENT(document));
	IANJUTA_DOCUMENT_MANAGER_GET_IFACE (obj)->set_current_document (obj, document, err);
}
Пример #4
0
static void
anjuta_docman_page_init (AnjutaDocman *docman, IAnjutaDocument *doc,
						 GFile* file, AnjutaDocmanPage *page)
{
	GtkWidget *close_button;
	GtkWidget *close_pixmap;
	GtkWidget *label, *menu_label;
	GtkWidget *box, *menu_box;
	GtkWidget *event_hbox;
	GtkWidget *event_box;
	gint h, w;
	GdkColor color;
	const gchar *filename;
	gchar *ruri;

	g_return_if_fail (IANJUTA_IS_DOCUMENT (doc));

	gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);

	close_pixmap = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
	gtk_widget_show (close_pixmap);

	/* setup close button, zero out {x,y} thickness to get smallest possible size */
	close_button = gtk_button_new();
	gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
	gtk_container_add(GTK_CONTAINER(close_button), close_pixmap);
	gtk_button_set_relief(GTK_BUTTON(close_button), GTK_RELIEF_NONE);

	gtk_widget_set_name (close_button, "anjuta-tab-close-button");

	gtk_widget_set_size_request (close_button, w, h);
	gtk_widget_set_tooltip_text (close_button, _("Close file"));

	filename = ianjuta_document_get_filename (doc, NULL);
	label = gtk_label_new (filename);
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_widget_show (label);

	menu_label = gtk_label_new (filename);
	gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
	gtk_widget_show (menu_label);
	menu_box = gtk_hbox_new(FALSE, 2);

	color.red = 0;
	color.green = 0;
	color.blue = 0;

	gtk_widget_modify_fg (close_button, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg (close_button, GTK_STATE_INSENSITIVE, &color);
	gtk_widget_modify_fg (close_button, GTK_STATE_ACTIVE, &color);
	gtk_widget_modify_fg (close_button, GTK_STATE_PRELIGHT, &color);
	gtk_widget_modify_fg (close_button, GTK_STATE_SELECTED, &color);
	gtk_widget_show(close_button);

	box = gtk_hbox_new (FALSE, 2);
	/* create our layout/event boxes */
	event_box = gtk_event_box_new();
	gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);

	event_hbox = gtk_hbox_new (FALSE, 2);

	page->menu_icon = gtk_image_new();
	page->mime_icon = gtk_image_new();
	gtk_box_pack_start (GTK_BOX (event_hbox), page->mime_icon, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (menu_box), page->menu_icon, FALSE, FALSE, 0);
	if (file != NULL)
	{
		GdkPixbuf* pixbuf = anjuta_docman_get_pixbuf_for_file (file);
		if (pixbuf != NULL)
		{
			gtk_image_set_from_pixbuf (GTK_IMAGE (page->menu_icon), pixbuf);
			gtk_image_set_from_pixbuf (GTK_IMAGE (page->mime_icon), pixbuf);
			g_object_unref (pixbuf);
		}
		ruri = g_file_get_parse_name (file);
		if (ruri != NULL)
		{
			/* set the tab-tooltip */
			gchar *tip;
			tip = g_markup_printf_escaped ("<b>%s</b> %s", _("Path:"), ruri);
			gtk_widget_set_tooltip_markup (event_box, tip);

			g_free (ruri);
			g_free (tip);
		}
	}

	gtk_box_pack_start (GTK_BOX (event_hbox), label, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (event_hbox), close_button, FALSE, FALSE, 0);
	gtk_container_add (GTK_CONTAINER (event_box), event_hbox);

	/* setup the data hierarchy */
	g_object_set_data (G_OBJECT (box), "event_box", event_box);

	/* pack our top-level layout box */
	gtk_box_pack_start (GTK_BOX (box), event_box, TRUE, TRUE, 0);

	/* show the widgets of the tab */
	gtk_widget_show_all(box);

	/* menu box */
	gtk_box_pack_start (GTK_BOX (menu_box), menu_label, TRUE, TRUE, 0);
	gtk_widget_show_all (menu_box);

	/* main box */
	g_signal_connect (G_OBJECT (close_button), "clicked",
					  G_CALLBACK (on_notebook_page_close_button_click),
					  docman);
	g_signal_connect (G_OBJECT (close_button), "enter",
					  G_CALLBACK (on_notebook_page_close_button_enter),
					  page);
	g_signal_connect (G_OBJECT (close_button), "leave",
					  G_CALLBACK (on_notebook_page_close_button_leave),
					  page);
	g_signal_connect (G_OBJECT (box), "button-press-event",
					  G_CALLBACK (on_notebook_tab_btnpress),
					  docman);
	g_signal_connect (G_OBJECT (box), "button-release-event",
					  G_CALLBACK (on_notebook_tab_btnrelease),
					  docman);
	g_signal_connect (G_OBJECT (box), "event",
	                  G_CALLBACK (on_notebook_tab_double_click),
	                  docman);

	page->widget = GTK_WIDGET (doc);	/* this is the notebook-page child widget */
	page->doc = doc;
	page->box = box;
	page->close_image = close_pixmap;
	page->close_button = close_button;
	page->label = label;
	page->menu_box = menu_box;
	page->menu_label = menu_label;

	gtk_widget_show_all (page->widget);
}
Пример #5
0
gboolean
anjuta_docman_save_document_as (AnjutaDocman *docman, IAnjutaDocument *doc,
							  GtkWidget *parent_window)
{
	gchar* uri;
	GFile* file;
	const gchar* filename;
	GtkWidget *parent;
	GtkWidget *dialog;
	gint response;
	gboolean file_saved = TRUE;

	g_return_val_if_fail (ANJUTA_IS_DOCMAN (docman), FALSE);
	g_return_val_if_fail (IANJUTA_IS_DOCUMENT (doc), FALSE);

	if (parent_window)
	{
		parent = parent_window;
	}
	else
	{
		parent = gtk_widget_get_toplevel (GTK_WIDGET (docman));
	}

	dialog = create_file_save_dialog_gui (GTK_WINDOW (parent), docman);

	if ((file = ianjuta_file_get_file (IANJUTA_FILE (doc), NULL)) != NULL)
	{
		gchar* file_uri = g_file_get_uri (file);
		gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), file_uri);
		g_free (file_uri);
		g_object_unref (file);
	}
	else if ((filename = ianjuta_document_get_filename (doc, NULL)) != NULL)
		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
	else
		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "");

	response = gtk_dialog_run (GTK_DIALOG (dialog));
	if (response != GTK_RESPONSE_ACCEPT)
	{
		gtk_widget_destroy (dialog);
		return FALSE;
	}

	uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
	file = g_file_new_for_uri (uri);
	if (g_file_query_exists (file, NULL))
	{
		GtkWidget *msg_dialog;
		gchar* parse_uri = g_file_get_parse_name (file);
		msg_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
											 GTK_DIALOG_DESTROY_WITH_PARENT,
											 GTK_MESSAGE_QUESTION,
											 GTK_BUTTONS_NONE,
											 _("The file '%s' already exists.\n"
											 "Do you want to replace it with the"
											 " one you are saving?"),
											 parse_uri);
		g_free (parse_uri);
		gtk_dialog_add_button (GTK_DIALOG (msg_dialog),
							   GTK_STOCK_CANCEL,
							   GTK_RESPONSE_CANCEL);
		anjuta_util_dialog_add_button (GTK_DIALOG (msg_dialog),
								  _("_Replace"),
								  GTK_STOCK_REFRESH,
								  GTK_RESPONSE_YES);
		if (gtk_dialog_run (GTK_DIALOG (msg_dialog)) == GTK_RESPONSE_YES)
			ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (doc), file,
										  NULL);
		else
			file_saved = FALSE;
		gtk_widget_destroy (msg_dialog);
	}
	else
	{
		ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (doc), file, NULL);
	}

	if (g_settings_get_boolean (docman->priv->settings,
	                            EDITOR_TABS_ORDERING))
		anjuta_docman_order_tabs (docman);

	gtk_widget_destroy (dialog);
	g_free (uri);

	if (file_saved)
	{
		/* Update mime icons */
		AnjutaDocmanPage* page = anjuta_docman_get_page_for_document (docman, doc);
		GdkPixbuf* pixbuf = anjuta_docman_get_pixbuf_for_file (file);
		if (pixbuf)
		{
			gtk_image_set_from_pixbuf (GTK_IMAGE(page->menu_icon), pixbuf);
			gtk_image_set_from_pixbuf (GTK_IMAGE(page->mime_icon), pixbuf);
			g_object_unref (pixbuf);
		}
	}
	g_object_unref (file);

	return file_saved;
}
Пример #6
0
IAnjutaDocument *
anjuta_docman_get_document_for_file (AnjutaDocman *docman, GFile* file)
{
	IAnjutaDocument *file_doc = NULL;
	GList *node;

	g_return_val_if_fail (file != NULL, NULL);

	for (node = docman->priv->pages; node != NULL; node = g_list_next (node))
	{
		AnjutaDocmanPage *page;
		GFile* doc_file;

		page = (AnjutaDocmanPage *) node->data;

		if (page && page->widget && IANJUTA_IS_DOCUMENT (page->doc))
		{
			IAnjutaDocument *doc;

			doc = page->doc;
			doc_file = ianjuta_file_get_file (IANJUTA_FILE (doc), NULL);
			if (doc_file)
			{
				gchar *path;
				gchar *local_real_path = NULL;
				
				/* Try exact match first */
				if (g_file_equal (file, doc_file))
				{
					g_object_unref (doc_file);
					file_doc = doc;
					break;
				}

				/* Try a local file alias */
				path = g_file_get_path (file);
				if (path)
				{
					local_real_path = anjuta_util_get_real_path (path);
					if (local_real_path)
					{
						g_free (path);
					}
					else
					{
						local_real_path = path;
					}
				}
				else
				{
					continue;
				}
				
				if ((file_doc == NULL) && (local_real_path))
				{
					gchar *doc_path = g_file_get_path (doc_file);
					if (doc_path)
					{
						gchar *doc_real_path = anjuta_util_get_real_path (doc_path);
						if (doc_real_path)
						{
							g_free (doc_path);
						}
						else
						{
							doc_real_path = doc_path;
						}
						if ((strcmp (doc_real_path, local_real_path) == 0))
						{
							file_doc = doc;
						}
						g_free (doc_real_path);
					}
				}
				g_free (local_real_path);
				g_object_unref (doc_file);
			}
		}
	}

	return file_doc;
}
/**
 * ianjuta_document_can_undo:
 * @obj: Self
 * @err: Error propagation and reporting
 *
 * Can the editor undo the last operation?
 *
 * Returns: TRUE if editor can undo, else FALSE
 */
gboolean
ianjuta_document_can_undo (IAnjutaDocument *obj, GError **err)
{
	g_return_val_if_fail (IANJUTA_IS_DOCUMENT(obj), FALSE);
	return IANJUTA_DOCUMENT_GET_IFACE (obj)->can_undo (obj, err);
}
/**
 * ianjuta_document_begin_undo_action:
 * @obj: Self
 * @err: Error propagation and reporting
 *
 * Begins the mark of undoable action. Calls to this are stacked and
 * each must be ended with ianjuta_document_end_action().
 */
void
ianjuta_document_begin_undo_action (IAnjutaDocument *obj, GError **err)
{
	g_return_if_fail (IANJUTA_IS_DOCUMENT(obj));
	IANJUTA_DOCUMENT_GET_IFACE (obj)->begin_undo_action (obj, err);
}
/**
 * ianjuta_document_redo:
 * @obj: Self
 * @err: Error propagation and reporting
 *
 * Redo last undo operation
 */
void
ianjuta_document_redo (IAnjutaDocument *obj, GError **err)
{
	g_return_if_fail (IANJUTA_IS_DOCUMENT(obj));
	IANJUTA_DOCUMENT_GET_IFACE (obj)->redo (obj, err);
}
/**
 * ianjuta_document_get_filename:
 * @obj: Self
 * @err: Error propagation and reporting
 *
 * Allows obtaining of the filename the editor was loaded from.
 *
 * Return value: The name of the file. Not to be freed by caller.
 */
const gchar*
ianjuta_document_get_filename (IAnjutaDocument *obj, GError **err)
{
	g_return_val_if_fail (IANJUTA_IS_DOCUMENT(obj), NULL);
	return IANJUTA_DOCUMENT_GET_IFACE (obj)->get_filename (obj, err);
}