Esempio n. 1
0
def file_close_all(window, is_quitting):
    debug(DEBUG_COMMANDS)

    if window.get_state() & (WINDOW_STATE_SAVING | WINDOW_STATE_PRINTING
                             | WINDOW_STATE_SAVING_SESSION):
        return

    window.set_data(IS_CLOSING_ALL, True)
    window.set_data(IS_QUITTING, is_quitting)

    unsaved_docs = window.get_unsaved_documents()

    if len(unsaved_docs) == 0:
        # There is no document to save -> close all tabs
        window.close_all_tabs()

        if is_quitting:
            window.destroy()

        return

    if len(unsaved_docs) == 1:
        # There is only one unsaved document

        doc = unsaved_docs[0]
        tab = tab_get_from_document(doc)
        if tab == None:
            return

        window.set_active_tab(tab)

        dlg = close_confirmation_dialog_new_single(window, doc, False)
    else:
        dlg = close_confirmation_dialog_new(window, unsaved_docs, False)

    dlg.connect("response", close_confirmation_dialog_response_handler, window)
    dlg.show()
Esempio n. 2
0
def file_close_all(window, is_quitting):
	debug(DEBUG_COMMANDS)

	if window.get_state() & (WINDOW_STATE_SAVING | WINDOW_STATE_PRINTING | WINDOW_STATE_SAVING_SESSION):
		return
		
	window.set_data(IS_CLOSING_ALL, True)
	window.set_data(IS_QUITTING, is_quitting)
			   
	unsaved_docs = window.get_unsaved_documents()

	if len(unsaved_docs) == 0:
		# There is no document to save -> close all tabs
		window.close_all_tabs()

		if is_quitting:
			window.destroy()
		
		return
	
	if len(unsaved_docs) == 1:
		# There is only one unsaved document

		doc = unsaved_docs[0]
		tab = tab_get_from_document(doc)
		if tab == None:
			return

		window.set_active_tab(tab)
		
		dlg = close_confirmation_dialog_new_single(window, doc, False)
	else:
		dlg = close_confirmation_dialog_new(window, unsaved_docs, False)

	dlg.connect("response", close_confirmation_dialog_response_handler, window)
	dlg.show()
Esempio n. 3
0
def load_file_list(window, uris, encoding, line_pos, create):
	loaded_files = 0
	jump_to = True
	flash = True # Whether to flash a message in the statusbar
	
	debug(DEBUG_COMMANDS)

	if uris == None:
		return 0

	win_docs = window.get_documents()
	
	files_to_load = []
	
	for uri in uris:
		if not is_duplicated_uri(files_to_load, uri):
			tab = get_tab_from_uri(win_docs, uri)
			if tab != None:
				if uri == uris[0]:
					window.set_active_tab(tab)
					jump_to = False
					if line_pos > 0:
						doc = tab.get_document();
						view = tab.get_view();
						# document counts lines starting from 0
						document.goto_line(line_pos - 1)
						view.scroll_to_cursor()
						
				++loaded_files
			else:
				files_to_load.append(uris); # TODO: Or prepend?
	if files_to_load == None:
		return loaded_files
	
	
#	files_to_load = g_slist_reverse (files_to_load);
	tab = window.get_active_tab()
	if tab != None:
		doc = tab.get_document()
		
		if doc.is_untouched() and tab.get_state == TAB_STATE_NORMAL:
			uri = files_to_load.pop(0) # Removes the first element and returns it

			tab.load(uri, encoding, line_pos, create)

			jump_to = False;

			if len(files_to_load) == 0:
				# There is only a single file to load
				uri_for_display = utils.format_uri_for_display(uri)
				
				statusbar.flash_message(window.get_statusbar(), window._generic_message_cid,
				                        "Loading file '%s'\342\200\246" % uri_for_display)
				
				flash = False

			++loaded_files

	for uri_to_load in files_to_load:
		if uri_to_load == None:
			return 0
		
		tab = window.create_tab_from_uri(uri_to_load, encoding, line_pos, create, jump_to)
		
		if tab != None:
			jump_to = False
			++loaded_files
	
	if flash:
		if loaded_files == 1:
			if tab == None:
				return loaded_files
			
			doc = tab.get_document()
			
			uri_for_display = doc.get_uri_for_display()
			
#			gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
#						       window->priv->generic_message_cid,
#						       _("Loading file '%s'\342\200\246"),
#						       uri_for_display);
		else:
			pass
#			gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
#						       window->priv->generic_message_cid,
#						       ngettext("Loading %d file\342\200\246",
#								"Loading %d files\342\200\246",
#								loaded_files),
#						       loaded_files);

	return loaded_files
Esempio n. 4
0
def load_file_list(window, uris, encoding, line_pos, create):
    loaded_files = 0
    jump_to = True
    flash = True  # Whether to flash a message in the statusbar

    debug(DEBUG_COMMANDS)

    if uris == None:
        return 0

    win_docs = window.get_documents()

    files_to_load = []

    for uri in uris:
        if not is_duplicated_uri(files_to_load, uri):
            tab = get_tab_from_uri(win_docs, uri)
            if tab != None:
                if uri == uris[0]:
                    window.set_active_tab(tab)
                    jump_to = False
                    if line_pos > 0:
                        doc = tab.get_document()
                        view = tab.get_view()
                        # document counts lines starting from 0
                        document.goto_line(line_pos - 1)
                        view.scroll_to_cursor()

                ++loaded_files
            else:
                files_to_load.append(uris)
                # TODO: Or prepend?
    if files_to_load == None:
        return loaded_files

#	files_to_load = g_slist_reverse (files_to_load);
    tab = window.get_active_tab()
    if tab != None:
        doc = tab.get_document()

        if doc.is_untouched() and tab.get_state == TAB_STATE_NORMAL:
            uri = files_to_load.pop(
                0)  # Removes the first element and returns it

            tab.load(uri, encoding, line_pos, create)

            jump_to = False

            if len(files_to_load) == 0:
                # There is only a single file to load
                uri_for_display = utils.format_uri_for_display(uri)

                statusbar.flash_message(
                    window.get_statusbar(), window._generic_message_cid,
                    "Loading file '%s'\342\200\246" % uri_for_display)

                flash = False

            ++loaded_files

    for uri_to_load in files_to_load:
        if uri_to_load == None:
            return 0

        tab = window.create_tab_from_uri(uri_to_load, encoding, line_pos,
                                         create, jump_to)

        if tab != None:
            jump_to = False
            ++loaded_files

    if flash:
        if loaded_files == 1:
            if tab == None:
                return loaded_files

            doc = tab.get_document()

            uri_for_display = doc.get_uri_for_display()

#			gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
#						       window->priv->generic_message_cid,
#						       _("Loading file '%s'\342\200\246"),
#						       uri_for_display);
        else:
            pass
#			gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
#						       window->priv->generic_message_cid,
#						       ngettext("Loading %d file\342\200\246",
#								"Loading %d files\342\200\246",
#								loaded_files),
#						       loaded_files);

    return loaded_files