Esempio n. 1
0
// Searches for an empty buffer, or one with the same name (preferred)
// If a suitable buffer is not found, it uses the current buffer
// Called from the LISTER PROCESS
DirBuffer *lister_buffer_find_empty(Lister *lister,char *path,struct DateStamp *stamp)
{
	DirBuffer *buffer,*first_empty=0,*first_unlocked=0;

#ifdef DEBUG
	if (lister) check_call("lister_buffer_find_empty",lister);
#endif

	// Check we're not showing special
	check_special_buffer(lister,1);

	// If current buffer is empty, use that one
	if (!(lister->cur_buffer->flags&DWF_VALID))
	{
		// Lock buffer
		buffer_lock(lister->cur_buffer,TRUE);

		// Free buffer
		buffer_freedir(lister->cur_buffer,1);

		// Unlock it
		buffer_unlock(lister->cur_buffer);
		return lister->cur_buffer;
	}

	// Lock buffer list
	lock_listlock(&GUI->buffer_list,TRUE);

	// Go through buffers in this list (backwards)
	for (buffer=(DirBuffer *)GUI->buffer_list.list.lh_TailPred;
		buffer->node.ln_Pred;
		buffer=(DirBuffer *)buffer->node.ln_Pred)
	{
		// See if this directory is available and matches our path
		if (path && stricmp(buffer->buf_Path,path)==0 &&
			(!stamp || CompareDates(&buffer->buf_VolumeDate,stamp)==0))
		{
			// Not locked, or in use by this lister?
			if (!buffer->buf_CurrentLister || buffer->buf_CurrentLister==lister)
			{
				// Store pointer
				first_empty=buffer;
				break;
			}
		}

		// If directory is empty, store pointer (if the first one)
		if (!buffer->buf_CurrentLister && !(buffer->flags&DWF_VALID) && !first_empty)
			first_empty=buffer;

		// First unlocked buffer?
		if (!buffer->buf_CurrentLister && !first_unlocked)
		{
			// Because buffers are moved to the head of the list whenever
			// they are accessed, this will point to the unlocked buffer
			// that was accessed the longest time ago
			first_unlocked=buffer;
		}
	}

	// If we found an empty one, use that one
	if (!(buffer=first_empty))
	{
		// Allocate a new buffer if we're allowed to
		if (GUI->buffer_count<environment->env->settings.max_buffer_count &&
			!(environment->env->settings.dir_flags&DIRFLAGS_DISABLE_CACHING))
		{
			// If this fails, use first unlocked
			buffer=lister_new_buffer(lister);
		}
	}

	// If nothing yet, use first unlocked buffer (if there is one)
	if (!buffer && !(buffer=first_unlocked))
	{
		// If not, re-use current buffer
		buffer=lister->cur_buffer;
	}

	// Lock buffer
	buffer_lock(buffer,TRUE);

	// Free buffer
	buffer_freedir(buffer,1);

	// Unlock buffer
	buffer_unlock(buffer);

	// Show buffer in lister
	lister_show_buffer(lister,buffer,0,1);

	// Unlock buffer list
	unlock_listlock(&GUI->buffer_list);

	// Return current buffer
	return lister->cur_buffer;
}
Esempio n. 2
0
// Initialise a new lister
IPC_StartupCode(lister_init, Lister *, lister, static)
{
	// Store IPC and lister pointers
	lister->ipc=ipc;
	ipc->userdata=lister;

	// Store IPC pointer in backdrop info
	lister->backdrop_info->ipc=ipc;

	// Path history list
	lister->path_history=Att_NewList(LISTF_LOCK);

	// Initialise reselection
	InitReselect(&lister->reselect);
	lister->abort_signal=-1;

	// Create message ports and signals
	if (!(lister->app_port=CreateMsgPort()) ||
		!(lister->timer_port=CreateMsgPort()) ||
		(lister->hot_name_bit=AllocSignal(-1))==-1 ||
		(lister->abort_signal=AllocSignal(-1))==-1)
		return 0;

	// Allocate some timers
	if (!(lister->busy_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->scroll_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->edit_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)) ||
		!(lister->foo_timer=AllocTimer(UNIT_VBLANK,lister->timer_port)))
		return 0;
	StartTimer(lister->foo_timer,5,0);

	// Create regions
	if (!(lister->title_region=NewRegion()) ||
		!(lister->refresh_extra=NewRegion()))
		return 0;

	// Lock buffer list
	lock_listlock(&GUI->buffer_list,TRUE);

	// Allocate initial buffer
	if (!(lister->cur_buffer=lister_get_empty_buffer()) &&
		!(lister->cur_buffer=lister_new_buffer(lister)))
		return 0;
	lister->cur_buffer->buf_CurrentLister=lister;

	// Unlock buffer list
	unlock_listlock(&GUI->buffer_list);

	// Allocate "special" buffer
	if (!(lister->special_buffer=buffer_new()))
		return 0;

	// Build popup menu
	lister_build_menu(lister);

	// Initialise flags
	lister->flags|=LISTERF_FIRST_TIME;
	lister->flags2|=LISTERF2_UNAVAILABLE;
	lister->tool_sel=-1;
	lister->toolbar_offset=0;

	// Fix priority
	lister->normal_pri=environment->env->settings.pri_lister[0];
	lister->busy_pri=environment->env->settings.pri_lister[1];
	SetTaskPri((struct Task *)lister->ipc->proc,lister->normal_pri);

	// Get font to use
	lister->lister_font.ta_Name=lister->font_name;
	lister->lister_font.ta_YSize=lister->font_size;
	lister->lister_font.ta_Flags=0;
	lister->lister_font.ta_Style=0;

	// Open font
	if ((lister->font=OpenDiskFont(&lister->lister_font)))
	{
		// Proportional	font?
		if (lister->font->tf_Flags&FPF_PROPORTIONAL)
			lister->more_flags|=LISTERF_PROP_FONT;

		// Set font in text area
		InitRastPort(&lister->text_area.rast);
		SetFont(&lister->text_area.rast,lister->font);
	}

	return 1;
}