Esempio n. 1
0
static void bmark_popup_menu_goto_lcb(GtkWidget * widget, gpointer user_data)
{
	Tbmark *b;
	GtkTextIter it;

	if (!user_data)
		return;
	b = get_current_bmark(BFWIN(user_data));
	if (!b)
		return;
	if (b->filepath && !b->doc) {
		/* check if that document _is_ open */
		Tdocument *tmpdoc;
		GList *doclist = return_allwindows_documentlist();
		tmpdoc = documentlist_return_document_from_filename(doclist, b->filepath);
		g_list_free(doclist);
		if (tmpdoc == NULL) {
			if (!g_file_test(b->filepath, G_FILE_TEST_EXISTS)) {
				gchar *string = g_strdup_printf(_("Could not find the file \"%s\"."), b->filepath);
				error_dialog(BFWIN(user_data)->main_window, string,
							 _("This bookmark is set in a file that no longer exists."));
				g_free(string);
				return;
			}
			tmpdoc = doc_new_with_file(BFWIN(user_data), b->filepath, FALSE, TRUE);
		}
		/* now I have to check all bookmarks */
		bmark_set_for_doc(tmpdoc);
	}

	if (b->doc) {
		GdkRectangle visirect;
		GtkTextIter visi_so, visi_eo;
		gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(b->doc->view),&visirect);
		gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(b->doc->view), &visi_so, visirect.x, visirect.y);
		gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(b->doc->view), &visi_eo, visirect.x + visirect.width, visirect.y + visirect.height);
		
		gtk_text_buffer_get_iter_at_mark(b->doc->buffer, &it, b->mark);
		gtk_text_buffer_place_cursor(b->doc->buffer, &it);

		if (!gtk_text_iter_in_range(&it,&visi_so,&visi_eo)) {
			DEBUG_MSG("bmark_popup_menu_goto_lcb, cursor NOT visible!\n");
			/* gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(b->doc->view), b->mark); */
			gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(b->doc->view),b->mark,0.0,
                                             TRUE,0.5,0.5);
		}
		if (b->doc != BFWIN(user_data)->current_document)
			switch_to_document_by_pointer(BFWIN(user_data), b->doc);
		gtk_widget_grab_focus(b->doc->view);
	}
}
Esempio n. 2
0
/**
 * msg_queue_check:
 *
 * checks the queue for any messages
 * this is called by the master program, usually by gtk_timeout_add()
 * the messages it will listen to are the types:
 * - MSG_QUEUE_ASK_ALIVE - we should respond with a type MSG_QUEUE_SEND_ALIVE
 * - MSG_QUEUE_OPENFILE - open a filename
 * - MSG_QUEUE_OPENPROJECT - open a filename as project
 * - MSG_QUEUE_OPENNEWWIN - open a new window
 */
static gboolean msg_queue_check(gint started_by_gtk_timeout)
{
	struct msgbuf {
		long mtype;
		char mtext[MSQ_QUEUE_SIZE];
	} msgp;
	gint retval;
	if (main_v->bfwinlist == NULL || BFWIN(main_v->bfwinlist->data)->documentlist == NULL) {
		DEBUG_MSG("msg_queue_check, no documentlist yet, so we do not continue\n");
		return TRUE;
	}

	if (msg_queue.msgid == -1) {
		return FALSE;
	}
	retval =	msgrcv(msg_queue.msgid, &msgp, MSQ_QUEUE_SIZE, -MSG_QUEUE_OPENFILE, IPC_NOWAIT);
	if (retval != -1) {
		DEBUG_MSG("msg_queue_check, found type %ld\n", msgp.mtype);
		if (msgp.mtype == MSG_QUEUE_ASK_ALIVE) {
			struct small_msgbuf {
				long mtype;
				char mtext[MSQ_QUEUE_SMALL_SIZE];
			} small_msgp;
			DEBUG_MSG("msg_queue_check, a keepalive is asked from %s, sending!\n", msgp.mtext);
			small_msgp.mtype = MSG_QUEUE_SEND_ALIVE;
			strncpy(small_msgp.mtext, msgp.mtext, MSQ_QUEUE_SMALL_SIZE - 1);
			msgsnd(msg_queue.msgid, (void *) &small_msgp, MSQ_QUEUE_SMALL_SIZE * sizeof(char),
				   IPC_NOWAIT);
		} else if (msgp.mtype == MSG_QUEUE_OPENFILE) {
			GList *lastlist = g_list_last(main_v->bfwinlist);
			gboolean delay_activate = TRUE;
			if (g_list_length(BFWIN(lastlist->data)->documentlist) < 2 && 
			       doc_is_empty_non_modified_and_nameless(BFWIN(lastlist->data)->current_document)) {
                       delay_activate = FALSE;
			}
			DEBUG_MSG("msg_queue_check, a filename %s is received\n", msgp.mtext);
			if (!doc_new_with_file(BFWIN(lastlist->data),msgp.mtext, delay_activate, FALSE)) {
				msg_queue.file_error_list = g_list_append(msg_queue.file_error_list, g_strdup(msgp.mtext));
			}
			msg_queue_check(0);	/* call myself again, there may have been multiple files */
			if (started_by_gtk_timeout) {
				if (msg_queue.file_error_list) {
					gchar *message, *tmp;
					tmp = stringlist_to_string(msg_queue.file_error_list, "\n");
					free_stringlist(msg_queue.file_error_list);
					msg_queue.file_error_list = NULL;
					message = g_strconcat(_("These files were not opened:\n"), tmp, NULL);
					g_free(tmp);
					warning_dialog(BFWIN(main_v->bfwinlist->data)->main_window,_("Unable to open file(s)\n"), message);
					g_free(message);
				}
/*				gtk_notebook_set_page(GTK_NOTEBOOK(main_v->notebook),g_list_length(main_v->documentlist) - 1);
				notebook_changed(-1);*/
			}
		} else if (msgp.mtype == MSG_QUEUE_OPENPROJECT) {
			GList *lastlist = g_list_last(main_v->bfwinlist);
			DEBUG_MSG("msg_queue_check, a project %s is received\n", msgp.mtext);
			project_open_from_file(BFWIN(lastlist->data), msgp.mtext);
			msg_queue_check(0);	/* call myself again, there may have been multiple projects */
		} else if (msgp.mtype == MSG_QUEUE_OPENNEWWIN) {
			/* now check if this is indeed send by another process
			if the message queue was dead during the startup of this process,
			it might be started by this very process */
			int otherpid = atoi(msgp.mtext);
			DEBUG_MSG("msg_queue_check, a new window is requested by PID=%d\n",otherpid);
			if (otherpid != (int) getpid()) {
				DEBUG_MSG("msg_queue_check, the PID is not ours, opening new window\n");
				gui_new_window(NULL, NULL);
			}
		}
#ifdef DEBUG
		 else {
		 	DEBUG_MSG("msg_queue_check, unknown message queue type %ld\n", msgp.mtype);
		 }
#endif
		
	} else {
#ifdef MSG_QUEUE_DEBUG
		DEBUG_MSG("msg_queue_check, found errno(%d)=%s\n", errno, g_strerror(errno));
#endif
	/*
	43 = Identifier removed
	*/
		if (errno == 22 || errno == 43) {
			DEBUG_MSG("msg_queue_check, re-opening message queue ?!?!?\n");
			/* the msg_queue was removed !?!?! */
			if (msg_queue_open()) {
				DEBUG_MSG("msg_queue_check, another process has opened the message_queue, stopping server\n");
				msg_queue.server = FALSE;
				return FALSE;
			}
		}
	}
	return TRUE;
}