SF.net SVN: geany: [875] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Oct 9 16:09:07 UTC 2006


Revision: 875
          http://svn.sourceforge.net/geany/?rev=875&view=rev
Author:   ntrel
Date:     2006-10-09 09:08:53 -0700 (Mon, 09 Oct 2006)

Log Message:
-----------
Removed the GEANY_MAX_OPEN_FILES limit, using a dynamic array.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/dialogs.c
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/geany.h
    trunk/src/main.c
    trunk/src/prefs.c
    trunk/src/search.c
    trunk/src/ui_utils.c
    trunk/src/win32.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/ChangeLog	2006-10-09 16:08:53 UTC (rev 875)
@@ -1,3 +1,11 @@
+2006-10-09  Nick Treleaven  <nick.treleaven at btinternet.com>
+
+ * src/win32.c, src/geany.h, src/callbacks.c, src/search.c,
+   src/document.c, src/document.h, src/prefs.c, src/dialogs.c,
+   src/main.c, src/ui_utils.c:
+   Removed the GEANY_MAX_OPEN_FILES limit, using a dynamic array.
+
+
 2006-10-09  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * src/dialogs.c:

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/callbacks.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -91,6 +91,10 @@
 	filetypes_free_types();
 	styleset_free_styles();
 	templates_free_templates();
+	msgwin_finalize();
+	search_finalize();
+	document_finalize();
+
 	tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
 	g_strfreev(html_entities);
 	g_free(app->configdir);
@@ -114,9 +118,6 @@
 	}
 	g_queue_free(app->recent_queue);
 
-	msgwin_finalize();
-	search_finalize();
-
 	if (app->prefs_dialog && GTK_IS_WIDGET(app->prefs_dialog)) gtk_widget_destroy(app->prefs_dialog);
 	if (app->save_filesel && GTK_IS_WIDGET(app->save_filesel)) gtk_widget_destroy(app->save_filesel);
 	if (app->open_filesel && GTK_IS_WIDGET(app->open_filesel)) gtk_widget_destroy(app->open_filesel);
@@ -165,10 +166,10 @@
 
 	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) > 0)
 	{
-		gint i;
+		guint i;
 		gboolean has_dirty_editors = FALSE;
 
-		for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+		for (i = 0; i < doc_array->len; i++)
 		{
 			if (doc_list[i].is_valid && doc_list[i].changed)
 			{
@@ -830,21 +831,10 @@
 		flist = filelist;
 		while(flist != NULL)
 		{
-			if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) < GEANY_MAX_OPEN_FILES)
+			if (g_file_test((gchar*) flist->data, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
 			{
-				if (g_file_test((gchar*) flist->data, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
-				{
-					document_open_file(-1, (gchar*) flist->data, 0, ro, ft, NULL);
-				}
+				document_open_file(-1, (gchar*) flist->data, 0, ro, ft, NULL);
 			}
-			else
-			{
-				dialogs_show_error(
-		_("You have opened too many files. There is a limit of %d concurrent open files."),
-		GEANY_MAX_OPEN_FILES);
-				g_slist_foreach(flist, (GFunc)g_free, NULL);
-				break;
-			}
 			g_free(flist->data);
 			flist = flist->next;
 		}
@@ -1277,9 +1267,8 @@
 on_find_usage1_activate                (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-	gint i, pos, line = -1;
-	gint flags;
-	gint idx;
+	guint i;
+	gint pos, line = -1, flags, idx;
 	struct TextToFind ttf;
 	gchar *buffer, *short_file_name, *string, *search_text;
 
@@ -1299,7 +1288,7 @@
 		flags = SCFIND_MATCHCASE | SCFIND_WHOLEWORD;
 	}
 
-	for(i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+	for(i = 0; i < doc_array->len; i++)
 	{
 		if (doc_list[i].is_valid)
 		{

Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/dialogs.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -54,103 +54,91 @@
 /* This shows the file selection dialog to open a file. */
 void dialogs_show_open_file ()
 {
-	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) < GEANY_MAX_OPEN_FILES)
-	{
 #ifdef G_OS_WIN32
-		win32_show_file_dialog(TRUE);
+	win32_show_file_dialog(TRUE);
 #else /* X11, not win32: use GTK_FILE_CHOOSER */
+	gchar *initdir;
 
-		/* We use the same file selection widget each time, so first
-	   		of all we create it if it hasn't already been created. */
-		if (app->open_filesel == NULL)
-		{
-			GtkWidget *combo;
-			GtkWidget *viewbtn;
-			GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
-			gint i;
+	/* We use the same file selection widget each time, so first
+		of all we create it if it hasn't already been created. */
+	if (app->open_filesel == NULL)
+	{
+		GtkWidget *combo;
+		GtkWidget *viewbtn;
+		GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
+		gint i;
 
-			app->open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(app->window),
-					GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
+		app->open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(app->window),
+				GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
 
-			viewbtn = gtk_button_new_with_mnemonic(_("_View"));
-			gtk_tooltips_set_tip(tooltips, viewbtn,
-				_("Opens the file in read-only mode. If you choose more than one file to open, all files will be opened read-only."), NULL);
-			gtk_widget_show(viewbtn);
-			gtk_dialog_add_action_widget(GTK_DIALOG(app->open_filesel),
-				viewbtn, GTK_RESPONSE_APPLY);
-			gtk_dialog_add_buttons(GTK_DIALOG(app->open_filesel),
-				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
-			// set default Open, so pressing enter can open multiple files
-			gtk_dialog_set_default_response(GTK_DIALOG(app->open_filesel),
-				GTK_RESPONSE_ACCEPT);
+		viewbtn = gtk_button_new_with_mnemonic(_("_View"));
+		gtk_tooltips_set_tip(tooltips, viewbtn,
+			_("Opens the file in read-only mode. If you choose more than one file to open, all files will be opened read-only."), NULL);
+		gtk_widget_show(viewbtn);
+		gtk_dialog_add_action_widget(GTK_DIALOG(app->open_filesel),
+			viewbtn, GTK_RESPONSE_APPLY);
+		gtk_dialog_add_buttons(GTK_DIALOG(app->open_filesel),
+			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+			GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+		// set default Open, so pressing enter can open multiple files
+		gtk_dialog_set_default_response(GTK_DIALOG(app->open_filesel),
+			GTK_RESPONSE_ACCEPT);
 
-			gtk_widget_set_size_request(app->open_filesel, 520, 460);
-			gtk_window_set_modal(GTK_WINDOW(app->open_filesel), TRUE);
-			gtk_window_set_destroy_with_parent(GTK_WINDOW(app->open_filesel), TRUE);
-			gtk_window_set_skip_taskbar_hint(GTK_WINDOW(app->open_filesel), TRUE);
-			gtk_window_set_type_hint(GTK_WINDOW(app->open_filesel), GDK_WINDOW_TYPE_HINT_DIALOG);
-			gtk_window_set_transient_for(GTK_WINDOW(app->open_filesel), GTK_WINDOW(app->window));
-			gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(app->open_filesel), TRUE);
+		gtk_widget_set_size_request(app->open_filesel, 520, 460);
+		gtk_window_set_modal(GTK_WINDOW(app->open_filesel), TRUE);
+		gtk_window_set_destroy_with_parent(GTK_WINDOW(app->open_filesel), TRUE);
+		gtk_window_set_skip_taskbar_hint(GTK_WINDOW(app->open_filesel), TRUE);
+		gtk_window_set_type_hint(GTK_WINDOW(app->open_filesel), GDK_WINDOW_TYPE_HINT_DIALOG);
+		gtk_window_set_transient_for(GTK_WINDOW(app->open_filesel), GTK_WINDOW(app->window));
+		gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(app->open_filesel), TRUE);
 
-			// add checkboxes and filename entry
-			gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(app->open_filesel),
-				add_file_open_extra_widget());
-			combo = lookup_widget(app->open_filesel, "filetype_combo");
+		// add checkboxes and filename entry
+		gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(app->open_filesel),
+			add_file_open_extra_widget());
+		combo = lookup_widget(app->open_filesel, "filetype_combo");
 
-			// add FileFilters(start with "All Files")
-			gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
-						filetypes_create_file_filter(filetypes[GEANY_FILETYPES_ALL]));
-			for (i = 0; i < GEANY_MAX_FILE_TYPES - 1; i++)
+		// add FileFilters(start with "All Files")
+		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
+					filetypes_create_file_filter(filetypes[GEANY_FILETYPES_ALL]));
+		for (i = 0; i < GEANY_MAX_FILE_TYPES - 1; i++)
+		{
+			if (filetypes[i])
 			{
-				if (filetypes[i])
-				{
-					gtk_combo_box_append_text(GTK_COMBO_BOX(combo), filetypes[i]->title);
-					gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
-						filetypes_create_file_filter(filetypes[i]));
-				}
+				gtk_combo_box_append_text(GTK_COMBO_BOX(combo), filetypes[i]->title);
+				gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
+					filetypes_create_file_filter(filetypes[i]));
 			}
-			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Detect by file extension  "));
-			gtk_combo_box_set_active(GTK_COMBO_BOX(combo), GEANY_MAX_FILE_TYPES - 1);
+		}
+		gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Detect by file extension  "));
+		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), GEANY_MAX_FILE_TYPES - 1);
 
-			g_signal_connect((gpointer) app->open_filesel, "selection-changed",
-						G_CALLBACK(on_file_open_selection_changed), NULL);
-			g_signal_connect ((gpointer) app->open_filesel, "delete_event",
-						G_CALLBACK(gtk_widget_hide), NULL);
-			g_signal_connect((gpointer) app->open_filesel, "response",
-						G_CALLBACK(on_file_open_dialog_response), NULL);
+		g_signal_connect((gpointer) app->open_filesel, "selection-changed",
+					G_CALLBACK(on_file_open_selection_changed), NULL);
+		g_signal_connect ((gpointer) app->open_filesel, "delete_event",
+					G_CALLBACK(gtk_widget_hide), NULL);
+		g_signal_connect((gpointer) app->open_filesel, "response",
+					G_CALLBACK(on_file_open_dialog_response), NULL);
+	}
 
- 		}
+	// set dialog directory to the current file's directory, if present
+	initdir = utils_get_current_file_dir();
+	if (initdir != NULL)
+	{
+		gchar *locale_filename;
 
-		// set dialog directory to the current file's directory, if present
-		{
-			gchar *initdir = utils_get_current_file_dir();
+		locale_filename = utils_get_locale_from_utf8(initdir);
 
-			if (initdir != NULL)
-			{
-				gchar *locale_filename;
+		if (g_path_is_absolute(locale_filename))
+			gtk_file_chooser_set_current_folder(
+				GTK_FILE_CHOOSER(app->open_filesel), locale_filename);
 
-				locale_filename = utils_get_locale_from_utf8(initdir);
+		g_free(initdir);
+		g_free(locale_filename);
+	}
 
-				if (g_path_is_absolute(locale_filename))
-					gtk_file_chooser_set_current_folder(
-						GTK_FILE_CHOOSER(app->open_filesel), locale_filename);
-
-				g_free(initdir);
-				g_free(locale_filename);
-			}
-		}
-
-		gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(app->open_filesel));
-		gtk_widget_show(app->open_filesel);
+	gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(app->open_filesel));
+	gtk_widget_show(app->open_filesel);
 #endif
-	}
-	else
-	{
-		dialogs_show_error(
-		_("You have opened too many files. There is a limit of %d concurrent open files."),
-		GEANY_MAX_OPEN_FILES);
-	}
 }
 
 

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/document.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -59,6 +59,10 @@
 #include "vte.h"
 
 
+/* dynamic array of document elements to hold all information of the notebook tabs */
+GArray *doc_array;
+
+
 /* Returns -1 if no text found or the new range endpoint after replacing. */
 static gint
 document_replace_range(gint idx, const gchar *find_text, const gchar *replace_text,
@@ -74,7 +78,7 @@
 
 	if (! filename) return -1;
 
-	for(i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+	for(i = 0; i < doc_array->len; i++)
 	{
 		gchar *dl_fname = (is_tm_filename && doc_list[i].tm_file) ?
 							doc_list[i].tm_file->file_name : doc_list[i].file_name;
@@ -96,7 +100,7 @@
 
 	if (! sci) return -1;
 
-	for(i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+	for(i = 0; i < doc_array->len; i++)
 	{
 		if (doc_list[i].is_valid && doc_list[i].sci == sci) return i;
 	}
@@ -108,7 +112,7 @@
 gint document_get_n_idx(guint page_num)
 {
 	ScintillaObject *sci;
-	if (page_num >= GEANY_MAX_OPEN_FILES) return -1;
+	if (page_num >= doc_array->len) return -1;
 
 	sci = (ScintillaObject*)gtk_notebook_get_nth_page(
 				GTK_NOTEBOOK(app->notebook), page_num);
@@ -139,21 +143,15 @@
 }
 
 
-/* returns the next free place(i.e. index) in the document list
- * If there is for any reason no free place, -1 is returned
- */
-gint document_get_new_idx()
+void document_init_doclist()
 {
-	guint i;
+	doc_array = g_array_new(FALSE, FALSE, sizeof(document));
+}
 
-	for(i = 0; i < GEANY_MAX_OPEN_FILES; i++)
-	{
-		if (doc_list[i].sci == NULL)
-		{
-			return (gint) i;
-		}
-	}
-	return -1;
+
+void document_finalize()
+{
+	g_array_free(doc_array, TRUE);
 }
 
 
@@ -180,33 +178,6 @@
 }
 
 
-/* sets in all document structs the flag is_valid to FALSE and initializes some members to NULL,
- * to mark it uninitialized. The flag is_valid is set to TRUE in document_create_new_sci(). */
-void document_init_doclist()
-{
-	gint i;
-
-	for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
-	{
-		doc_list[i].is_valid = FALSE;
-		doc_list[i].has_tags = FALSE;
-		doc_list[i].use_auto_indention = app->pref_editor_use_auto_indention;
-		doc_list[i].line_breaking = app->pref_editor_line_breaking;
-		doc_list[i].readonly = FALSE;
-		doc_list[i].tag_store = NULL;
-		doc_list[i].tag_tree = NULL;
-		doc_list[i].file_name = NULL;
-		doc_list[i].file_type = NULL;
-		doc_list[i].tm_file = NULL;
-		doc_list[i].encoding = NULL;
-		doc_list[i].has_bom = FALSE;
-		doc_list[i].sci = NULL;
-		doc_list[i].undo_actions = NULL;
-		doc_list[i].redo_actions = NULL;
-	}
-}
-
-
 // Apply just the prefs that can change in the Preferences dialog
 void document_apply_update_prefs(ScintillaObject *sci)
 {
@@ -223,6 +194,45 @@
 }
 
 
+/* Sets is_valid to FALSE and initializes some members to NULL, to mark it uninitialized.
+ * The flag is_valid is set to TRUE in document_create_new_sci(). */
+static void init_doc_struct(document *new_doc)
+{
+	new_doc->is_valid = FALSE;
+	new_doc->has_tags = FALSE;
+	new_doc->use_auto_indention = app->pref_editor_use_auto_indention;
+	new_doc->line_breaking = app->pref_editor_line_breaking;
+	new_doc->readonly = FALSE;
+	new_doc->tag_store = NULL;
+	new_doc->tag_tree = NULL;
+	new_doc->file_name = NULL;
+	new_doc->file_type = NULL;
+	new_doc->tm_file = NULL;
+	new_doc->encoding = NULL;
+	new_doc->has_bom = FALSE;
+	new_doc->sci = NULL;
+	new_doc->undo_actions = NULL;
+	new_doc->redo_actions = NULL;
+}
+
+
+/* returns the next free place(i.e. index) in the document list,
+ * or -1 if the current doc_array is full */
+static gint document_get_new_idx()
+{
+	guint i;
+
+	for(i = 0; i < doc_array->len; i++)
+	{
+		if (doc_list[i].sci == NULL)
+		{
+			return (gint) i;
+		}
+	}
+	return -1;
+}
+
+
 /* creates a new tab in the notebook and does all related stuff
  * finally it returns the index of the created document */
 gint document_create_new_sci(const gchar *filename)
@@ -243,10 +253,15 @@
 	}
 
 	new_idx = document_get_new_idx();
-	if (new_idx == -1) return -1;
+	if (new_idx == -1)	// expand the array, no free places
+	{
+		document new_doc;
+		init_doc_struct(&new_doc);
+		new_idx = doc_array->len;
+		g_array_append_val(doc_array, new_doc);
+	}
+	this = &doc_list[new_idx];
 
-	this = &(doc_list[new_idx]);
-
 	/* SCI - Code */
 	sci = SCINTILLA(scintilla_new());
 	scintilla_set_id(sci, new_idx);
@@ -311,6 +326,7 @@
 	this->has_tags = FALSE;
 	this->is_valid = TRUE;
 
+	g_assert(doc_list[new_idx].sci == sci);
 	return new_idx;
 }
 
@@ -320,7 +336,7 @@
 {
 	gint idx = document_get_n_idx(page_num);
 
-	if (idx >= 0 && idx <= GEANY_MAX_OPEN_FILES)
+	if (DOC_IDX_VALID(idx))
 	{
 		if (doc_list[idx].changed && ! dialogs_show_unsaved_file(idx))
 		{
@@ -367,54 +383,39 @@
    current filename to NULL. */
 void document_new_file(filetype *ft)
 {
-	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) < GEANY_MAX_OPEN_FILES)
-	{
-		gint idx = document_create_new_sci(NULL);
-		gchar *template = document_prepare_template(ft);
+	gint idx = document_create_new_sci(NULL);
+	gchar *template = document_prepare_template(ft);
 
-		if (idx == -1)
-		{
-			dialogs_show_error(
-			_("You have opened too many files. There is a limit of %d concurrent open files."),
-			GEANY_MAX_OPEN_FILES);
-			return;
-		}
+	g_assert(idx != -1);
 
-		sci_clear_all(doc_list[idx].sci);
-		sci_set_text(doc_list[idx].sci, template);
-		g_free(template);
+	sci_clear_all(doc_list[idx].sci);
+	sci_set_text(doc_list[idx].sci, template);
+	g_free(template);
 
-		doc_list[idx].encoding = g_strdup(encodings[app->pref_editor_default_encoding].charset);
-		//document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft);
-		document_set_filetype(idx, ft);	// also clears taglist
-		if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci);
-		ui_set_window_title(idx);
-		ui_update_build_menu(idx);
-		doc_list[idx].mtime = time(NULL);
-		doc_list[idx].changed = FALSE;
-		document_set_text_changed(idx);
-		ui_document_show_hide(idx); //update the document menu
+	doc_list[idx].encoding = g_strdup(encodings[app->pref_editor_default_encoding].charset);
+	//document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft);
+	document_set_filetype(idx, ft);	// also clears taglist
+	if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci);
+	ui_set_window_title(idx);
+	ui_update_build_menu(idx);
+	doc_list[idx].mtime = time(NULL);
+	doc_list[idx].changed = FALSE;
+	document_set_text_changed(idx);
+	ui_document_show_hide(idx); //update the document menu
 #ifdef G_OS_WIN32
-		sci_set_eol_mode(doc_list[idx].sci, SC_EOL_CRLF);
+	sci_set_eol_mode(doc_list[idx].sci, SC_EOL_CRLF);
 #else
-		sci_set_eol_mode(doc_list[idx].sci, SC_EOL_LF);
+	sci_set_eol_mode(doc_list[idx].sci, SC_EOL_LF);
 #endif
-		sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0);
-		sci_empty_undo_buffer(doc_list[idx].sci);
-		sci_goto_pos(doc_list[idx].sci, 0, TRUE);
+	sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0);
+	sci_empty_undo_buffer(doc_list[idx].sci);
+	sci_goto_pos(doc_list[idx].sci, 0, TRUE);
 
-		// "the" SCI signal (connect after initial setup(i.e. adding text))
-		g_signal_connect((GtkWidget*) doc_list[idx].sci, "sci-notify",
-					G_CALLBACK(on_editor_notification), GINT_TO_POINTER(idx));
+	// "the" SCI signal (connect after initial setup(i.e. adding text))
+	g_signal_connect((GtkWidget*) doc_list[idx].sci, "sci-notify",
+				G_CALLBACK(on_editor_notification), GINT_TO_POINTER(idx));
 
-		msgwin_status_add(_("New file opened."));
-	}
-	else
-	{
-		dialogs_show_error(
-		_("You have opened too many files. There is a limit of %d concurrent open files."),
-							GEANY_MAX_OPEN_FILES);
-	}
+	msgwin_status_add(_("New file opened."));
 }
 
 
@@ -1182,7 +1183,7 @@
 						}
 					}
 				}
-				for (n = 0; n < GEANY_MAX_OPEN_FILES; n++)
+				for (n = 0; n < doc_array->len; n++)
 				{
 					if (doc_list[n].sci)
 					{

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/document.h	2006-10-09 16:08:53 UTC (rev 875)
@@ -35,10 +35,6 @@
 #include "filetypes.h"
 
 
-#define DOC_IDX_VALID(idx) \
-	((idx) >= 0 && (idx) < GEANY_MAX_OPEN_FILES && doc_list[idx].is_valid)
-
-
 /* structure for representing an open tab with all its related stuff. */
 typedef struct document
 {
@@ -68,11 +64,17 @@
 } document;
 
 
-/* array of document elements to hold all information of the notebook tabs */
-document doc_list[GEANY_MAX_OPEN_FILES];
+/* dynamic array of document elements to hold all information of the notebook tabs */
+extern GArray *doc_array;
 
+/* doc_list wraps doc_array so it can be used with C array syntax.
+ * Example: doc_list[0].sci = NULL; */
+#define doc_list ((document *)doc_array->data)
 
+#define DOC_IDX_VALID(idx) \
+	((idx) >= 0 && (guint)(idx) < doc_array->len && doc_list[idx].is_valid)
 
+
 /* returns the index of the notebook page which has the given filename */
 gint document_find_by_filename(const gchar*, gboolean is_tm_filename);
 
@@ -81,6 +83,9 @@
 gint document_find_by_sci(ScintillaObject*);
 
 
+/* returns the index of the given notebook page in the document list */
+gint document_get_n_idx(guint page_num);
+
 /* returns the index of the current notebook page in the document list */
 gint document_get_cur_idx();
 
@@ -88,23 +93,14 @@
 document *document_get_current();
 
 
-/* returns the index of the given notebook page in the document list */
-gint document_get_n_idx(guint);
+void document_init_doclist();
 
+void document_finalize();
 
-/* returns the next free place(i.e. index) in the document list
- * If there is for any reason no free place, -1 is returned */
-gint document_get_new_idx();
 
-
 void document_set_text_changed(gint);
 
 
-/* sets in all document structs the flag is_valid to FALSE and initializes some members to NULL,
- * to mark it uninitialized. The flag is_valid is set to TRUE in document_create_new_sci(). */
-void document_init_doclist();
-
-
 // Apply just the prefs that can change in the Preferences dialog
 void document_apply_update_prefs(ScintillaObject *sci);
 
@@ -114,9 +110,8 @@
 gint document_create_new_sci(const gchar*);
 
 
-/* removes the given notebook tab and clears the related entry in the document
- * list */
-gboolean document_remove(guint);
+/* removes the given notebook tab and clears the related entry in the document list */
+gboolean document_remove(guint page_num);
 
 
 /* This creates a new document, by clearing the text widget and setting the

Modified: trunk/src/geany.h
===================================================================
--- trunk/src/geany.h	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/geany.h	2006-10-09 16:08:53 UTC (rev 875)
@@ -38,7 +38,6 @@
 #define GEANY_FILEDEFS_SUBDIR			"filedefs"
 #define GEANY_CODENAME					"Kintaro"
 #define GEANY_HOMEPAGE					"http://geany.uvena.de/"
-#define GEANY_MAX_OPEN_FILES			25
 #define GEANY_SESSION_FILES				25
 #define GEANY_MAX_TAGS_COUNT			1000
 #define GEANY_CHECK_FILE_DELAY			30

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/main.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -567,25 +567,14 @@
 	app->opening_session_files = TRUE;
 	if (argc > 1)
 	{
-		gint i, opened = 0;
+		gint i;
 		for(i = 1; i < argc; i++)
 		{
 			if (argv[i] && g_file_test(argv[i], G_FILE_TEST_IS_REGULAR || G_FILE_TEST_IS_SYMLINK))
 			{
-				if (opened < GEANY_MAX_OPEN_FILES)
-				{
-					gchar *filename = get_argv_filename(argv[i]);
-					document_open_file(-1, filename, 0, FALSE, NULL, NULL);
-					g_free(filename);
-					opened++;
-				}
-				else
-				{
-					dialogs_show_error(
-			_("You have opened too many files. There is a limit of %d concurrent open files."),
-			GEANY_MAX_OPEN_FILES);
-					break;
-				}
+				gchar *filename = get_argv_filename(argv[i]);
+				document_open_file(-1, filename, 0, FALSE, NULL, NULL);
+				g_free(filename);
 			}
 		}
 	}

Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/prefs.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -366,7 +366,7 @@
 	if (response == GTK_RESPONSE_OK)
 	{
 		GtkWidget *widget;
-		gint i;
+		guint i;
 
 		// General settings
 		widget = lookup_widget(app->prefs_dialog, "spin_mru");
@@ -609,7 +609,7 @@
 		gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->treeview_notebook), app->tab_pos_sidebar);
 
 		// re-colourise all open documents, if tab width or long line settings have changed
-		for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+		for (i = 0; i < doc_array->len; i++)
 		{
 			if (doc_list[i].is_valid)
 			{
@@ -669,7 +669,7 @@
 void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
 {
 	const gchar *fontbtn = gtk_font_button_get_font_name(widget);
-	gint i;
+	guint i;
 
 	switch (GPOINTER_TO_INT(user_data))
 	{
@@ -678,7 +678,7 @@
 			if (strcmp(fontbtn, app->tagbar_font) == 0) break;
 			g_free(app->tagbar_font);
 			app->tagbar_font = g_strdup(fontbtn);
-			for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+			for (i = 0; i < doc_array->len; i++)
 			{
 				if (doc_list[i].is_valid && GTK_IS_WIDGET(doc_list[i].tag_tree))
 					gtk_widget_modify_font(doc_list[i].tag_tree,

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/search.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -729,8 +729,8 @@
 
 	if (search_in_all_buffers_re && response == GEANY_RESPONSE_REPLACE_ALL)
 	{
-		gint i;
-		for (i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+		guint i;
+		for (i = 0; i < doc_array->len; i++)
 		{
 			if (! doc_list[i].is_valid) continue;
 

Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/ui_utils.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -135,7 +135,8 @@
 
 void ui_set_editor_font(const gchar *font_name)
 {
-	gint i, size;
+	guint i;
+	gint size;
 	gchar *fname;
 	PangoFontDescription *font_desc;
 
@@ -153,7 +154,7 @@
 	size = pango_font_description_get_size(font_desc) / PANGO_SCALE;
 
 	/* We copy the current style, and update the font in all open tabs. */
-	for(i = 0; i < GEANY_MAX_OPEN_FILES; i++)
+	for(i = 0; i < doc_array->len; i++)
 	{
 		if (doc_list[i].sci)
 		{

Modified: trunk/src/win32.c
===================================================================
--- trunk/src/win32.c	2006-10-09 13:50:23 UTC (rev 874)
+++ trunk/src/win32.c	2006-10-09 16:08:53 UTC (rev 875)
@@ -145,16 +145,7 @@
 		x = of.nFileOffset - 1;
 		if (x != strlen(fname))
 		{	// open a single file
-			if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) >= GEANY_MAX_OPEN_FILES)
-			{
-				dialogs_show_error(
-			_("You have opened too many files. There is a limit of %d concurrent open files."),
-			GEANY_MAX_OPEN_FILES);
-			}
-			else
-			{
-				document_open_file(-1, fname, 0, of.Flags & OFN_READONLY, NULL, NULL);
-			}
+			document_open_file(-1, fname, 0, of.Flags & OFN_READONLY, NULL, NULL);
 		}
 		else
 		{	// open mutiple files
@@ -162,9 +153,7 @@
 			{
 				if (! fname[x])
 				{
-					if (! fname[x+1] &&	(
-						gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) < GEANY_MAX_OPEN_FILES))
-						break;
+					if (! fname[x+1]) break;
 
 					g_snprintf(file_name, 254, "%s\\%s", fname, fname + x + 1);
 					document_open_file(-1, file_name, 0, of.Flags & OFN_READONLY, NULL, NULL);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list