2006-09-05 14:24:47 +00:00
|
|
|
/*
|
|
|
|
* ui_utils.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2006-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2006-09-05 14:24:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* User Interface general utility functions.
|
|
|
|
*/
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
#include "geany.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ui_utils.h"
|
2007-08-23 11:34:06 +00:00
|
|
|
#include "prefs.h"
|
2006-09-05 14:24:47 +00:00
|
|
|
#include "sciwrappers.h"
|
|
|
|
#include "document.h"
|
2007-08-15 15:37:21 +00:00
|
|
|
#include "filetypes.h"
|
2006-09-05 14:24:47 +00:00
|
|
|
#include "support.h"
|
|
|
|
#include "msgwindow.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "callbacks.h"
|
|
|
|
#include "encodings.h"
|
|
|
|
#include "images.c"
|
|
|
|
#include "treeviews.h"
|
2007-05-26 09:02:37 +00:00
|
|
|
#include "win32.h"
|
2007-05-28 15:24:21 +00:00
|
|
|
#include "project.h"
|
2007-05-29 16:30:54 +00:00
|
|
|
#include "editor.h"
|
2007-07-23 15:41:08 +00:00
|
|
|
#include "plugins.h"
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
UIPrefs ui_prefs;
|
|
|
|
UIWidgets ui_widgets;
|
|
|
|
|
2007-07-20 12:06:51 +00:00
|
|
|
static struct
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* widgets only sensitive when there is at least one document */
|
|
|
|
GtkWidget *document_buttons[45];
|
2007-07-20 12:06:51 +00:00
|
|
|
}
|
|
|
|
widgets;
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void update_recent_menu(void);
|
2006-09-09 14:36:15 +00:00
|
|
|
static void recent_file_loaded(const gchar *utf8_filename);
|
|
|
|
static void
|
|
|
|
recent_file_activate_cb (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* allow_override is TRUE if text can be ignored when another message has been set
|
|
|
|
* that didn't use allow_override and has not timed out. */
|
2006-11-25 16:33:38 +00:00
|
|
|
static void set_statusbar(const gchar *text, gboolean allow_override)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
static glong last_time = 0;
|
|
|
|
GTimeVal timeval;
|
|
|
|
const gint GEANY_STATUS_TIMEOUT = 1;
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
if (! prefs.statusbar_visible)
|
2008-02-27 13:17:29 +00:00
|
|
|
return; /* just do nothing if statusbar is not visible */
|
2007-10-24 10:52:48 +00:00
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
g_get_current_time(&timeval);
|
|
|
|
|
|
|
|
if (! allow_override)
|
|
|
|
{
|
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1);
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text);
|
|
|
|
last_time = timeval.tv_sec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (timeval.tv_sec > last_time + GEANY_STATUS_TIMEOUT)
|
|
|
|
{
|
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1);
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
/* Display text on the statusbar.
|
|
|
|
* log is whether the message should be recorded in the Status window. */
|
|
|
|
void ui_set_statusbar(gboolean log, const gchar *format, ...)
|
2006-11-25 16:33:38 +00:00
|
|
|
{
|
|
|
|
gchar string[512];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
g_vsnprintf(string, 512, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
if (! prefs.suppress_status_messages)
|
2007-08-05 11:03:44 +00:00
|
|
|
set_statusbar(string, FALSE);
|
2007-10-24 10:52:48 +00:00
|
|
|
|
|
|
|
if (log || prefs.suppress_status_messages)
|
|
|
|
msgwin_status_add("%s", string);
|
2006-11-25 16:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* updates the status bar document statistics */
|
2006-09-05 14:24:47 +00:00
|
|
|
void ui_update_statusbar(gint idx, gint pos)
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
if (! prefs.statusbar_visible)
|
2008-02-27 13:17:29 +00:00
|
|
|
return; /* just do nothing if statusbar is not visible */
|
2007-04-10 17:06:57 +00:00
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
if (idx == -1) idx = document_get_cur_idx();
|
|
|
|
|
2007-04-10 17:06:57 +00:00
|
|
|
if (DOC_IDX_VALID(idx))
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-10-17 12:27:07 +00:00
|
|
|
static GString *stats_str = NULL;
|
|
|
|
const gchar sp[] = " ";
|
|
|
|
guint line, col;
|
|
|
|
const gchar *cur_tag;
|
2008-04-11 15:39:44 +00:00
|
|
|
gchar *filetype_name;
|
|
|
|
|
2008-05-07 13:54:21 +00:00
|
|
|
/* workaround to make the name of filetype GEANY_FILETYPES_NONE translatable */
|
|
|
|
if (doc_list[idx].file_type == NULL || doc_list[idx].file_type->id == GEANY_FILETYPES_NONE)
|
2008-04-11 15:39:44 +00:00
|
|
|
filetype_name = _("None");
|
|
|
|
else
|
|
|
|
filetype_name = doc_list[idx].file_type->name;
|
2007-10-17 12:27:07 +00:00
|
|
|
|
|
|
|
if (stats_str == NULL)
|
|
|
|
stats_str = g_string_sized_new(120);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
if (pos == -1) pos = sci_get_current_position(doc_list[idx].sci);
|
|
|
|
line = sci_get_line_from_position(doc_list[idx].sci, pos);
|
2006-10-28 16:25:17 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Add temporary fix for sci infinite loop in Document::GetColumn(int)
|
|
|
|
* when current pos is beyond document end (can occur when removing
|
|
|
|
* blocks of selected lines especially esp. brace sections near end of file). */
|
2006-10-28 16:25:17 +00:00
|
|
|
if (pos <= sci_get_length(doc_list[idx].sci))
|
|
|
|
col = sci_get_col_from_position(doc_list[idx].sci, pos);
|
|
|
|
else
|
|
|
|
col = 0;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-10-17 12:27:07 +00:00
|
|
|
/* Status bar statistics: col = column, sel = selection. */
|
|
|
|
g_string_printf(stats_str, _("line: %d\t col: %d\t sel: %d\t "),
|
2006-12-21 20:47:31 +00:00
|
|
|
(line + 1), col,
|
2007-10-17 12:27:07 +00:00
|
|
|
sci_get_selected_text_length(doc_list[idx].sci) - 1);
|
|
|
|
|
|
|
|
g_string_append(stats_str,
|
2008-02-27 13:17:29 +00:00
|
|
|
/* RO = read-only */
|
|
|
|
(doc_list[idx].readonly) ? _("RO ") :
|
|
|
|
/* OVR = overwrite/overtype, INS = insert */
|
|
|
|
(sci_get_overtype(doc_list[idx].sci) ? _("OVR") : _("INS")));
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
|
|
|
g_string_append(stats_str,
|
2008-02-27 13:17:29 +00:00
|
|
|
(doc_list[idx].use_tabs) ? _("TAB") : _("SP ")); /* SP = space */
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
2008-04-09 22:08:23 +00:00
|
|
|
g_string_append_printf(stats_str, _("mode: %s"),
|
2008-05-15 13:43:29 +00:00
|
|
|
editor_get_eol_char_name(idx));
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
2008-04-09 22:08:23 +00:00
|
|
|
g_string_append_printf(stats_str, _("encoding: %s %s"),
|
2006-09-05 14:24:47 +00:00
|
|
|
(doc_list[idx].encoding) ? doc_list[idx].encoding : _("unknown"),
|
2007-01-07 16:22:41 +00:00
|
|
|
(encodings_is_unicode_charset(doc_list[idx].encoding)) ?
|
2008-02-27 13:17:29 +00:00
|
|
|
/* BOM = byte order mark */
|
|
|
|
((doc_list[idx].has_bom) ? _("(with BOM)") : "") : "");
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
2008-04-11 15:39:44 +00:00
|
|
|
g_string_append_printf(stats_str, _("filetype: %s"), filetype_name);
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
|
|
|
if (doc_list[idx].changed)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
g_string_append(stats_str, _("MOD")); /* MOD = modified */
|
2007-10-17 12:27:07 +00:00
|
|
|
g_string_append(stats_str, sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
utils_get_current_function(idx, &cur_tag);
|
2008-04-09 22:08:23 +00:00
|
|
|
g_string_append_printf(stats_str, _("scope: %s"),
|
2007-03-13 11:32:57 +00:00
|
|
|
cur_tag);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* can be overridden by status messages */
|
|
|
|
set_statusbar(stats_str->str, TRUE);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else /* no documents */
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
set_statusbar("", TRUE); /* can be overridden by status messages */
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This sets the window title according to the current filename. */
|
2007-03-09 13:52:26 +00:00
|
|
|
void ui_set_window_title(gint idx)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-05-28 15:24:21 +00:00
|
|
|
GString *str;
|
|
|
|
GeanyProject *project = app->project;
|
|
|
|
|
|
|
|
if (idx < 0)
|
|
|
|
idx = document_get_cur_idx();
|
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
if (idx >= 0)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-05-28 15:24:21 +00:00
|
|
|
g_string_append(str, doc_list[idx].changed ? "*" : "");
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
if (doc_list[idx].file_name == NULL)
|
2007-05-28 15:24:21 +00:00
|
|
|
g_string_append(str, DOC_FILENAME(idx));
|
2007-02-01 17:07:52 +00:00
|
|
|
else
|
|
|
|
{
|
2007-07-17 08:10:29 +00:00
|
|
|
gchar *base_name = g_path_get_basename(DOC_FILENAME(idx));
|
2007-03-09 13:52:26 +00:00
|
|
|
gchar *dirname = g_path_get_dirname(DOC_FILENAME(idx));
|
2007-02-01 17:07:52 +00:00
|
|
|
|
2007-07-17 08:10:29 +00:00
|
|
|
g_string_append(str, base_name);
|
2007-05-28 15:24:21 +00:00
|
|
|
g_string_append(str, " - ");
|
|
|
|
g_string_append(str, dirname ? dirname : "");
|
2007-07-17 08:10:29 +00:00
|
|
|
g_free(base_name);
|
2007-02-01 17:07:52 +00:00
|
|
|
g_free(dirname);
|
|
|
|
}
|
2007-05-28 15:24:21 +00:00
|
|
|
g_string_append(str, " - ");
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2007-05-28 15:24:21 +00:00
|
|
|
if (project)
|
|
|
|
{
|
|
|
|
g_string_append_c(str, '[');
|
|
|
|
g_string_append(str, project->name);
|
|
|
|
g_string_append(str, "] - ");
|
|
|
|
}
|
|
|
|
g_string_append(str, "Geany");
|
|
|
|
gtk_window_set_title(GTK_WINDOW(app->window), str->str);
|
|
|
|
g_string_free(str, TRUE);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_set_editor_font(const gchar *font_name)
|
|
|
|
{
|
2006-10-09 16:08:53 +00:00
|
|
|
guint i;
|
|
|
|
gint size;
|
2006-09-05 14:24:47 +00:00
|
|
|
gchar *fname;
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
|
|
|
|
g_return_if_fail(font_name != NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* do nothing if font has not changed */
|
2007-08-23 11:34:06 +00:00
|
|
|
if (prefs.editor_font != NULL)
|
|
|
|
if (strcmp(font_name, prefs.editor_font) == 0) return;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
g_free(prefs.editor_font);
|
|
|
|
prefs.editor_font = g_strdup(font_name);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
font_desc = pango_font_description_from_string(prefs.editor_font);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
fname = g_strdup_printf("!%s", pango_font_description_get_family(font_desc));
|
|
|
|
size = pango_font_description_get_size(font_desc) / PANGO_SCALE;
|
|
|
|
|
|
|
|
/* We copy the current style, and update the font in all open tabs. */
|
2006-10-09 16:08:53 +00:00
|
|
|
for(i = 0; i < doc_array->len; i++)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
if (doc_list[i].sci)
|
|
|
|
{
|
2008-05-15 13:43:29 +00:00
|
|
|
editor_set_font(i, fname, size);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pango_font_description_free(font_desc);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Font updated (%s)."), prefs.editor_font);
|
2006-09-05 14:24:47 +00:00
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_set_fullscreen(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
if (ui_prefs.fullscreen)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gtk_window_fullscreen(GTK_WINDOW(app->window));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(app->window));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
void ui_update_popup_reundo_items(gint idx)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable_undo;
|
|
|
|
gboolean enable_redo;
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
if (idx == -1)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
enable_undo = FALSE;
|
|
|
|
enable_redo = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-09 13:52:26 +00:00
|
|
|
enable_undo = document_can_undo(idx);
|
|
|
|
enable_redo = document_can_redo(idx);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* index 0 is the popup menu, 1 is the menubar, 2 is the toolbar */
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.undo_items[0], enable_undo);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.undo_items[1], enable_undo);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.undo_items[2], enable_undo);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.redo_items[0], enable_redo);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.redo_items[1], enable_redo);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.redo_items[2], enable_redo);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
void ui_update_popup_copy_items(gint idx)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable;
|
|
|
|
guint i;
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
if (idx == -1) enable = FALSE;
|
|
|
|
else enable = sci_can_copy(doc_list[idx].sci);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-09-12 16:25:19 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS(ui_widgets.popup_copy_items); i++)
|
2007-09-12 16:01:23 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.popup_copy_items[i], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_update_popup_goto_items(gboolean enable)
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.popup_goto_items[0], enable);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.popup_goto_items[1], enable);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.popup_goto_items[2], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_update_menu_copy_items(gint idx)
|
|
|
|
{
|
|
|
|
gboolean enable = FALSE;
|
|
|
|
guint i;
|
|
|
|
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(app->window));
|
|
|
|
|
|
|
|
if (IS_SCINTILLA(focusw))
|
|
|
|
enable = (idx == -1) ? FALSE : sci_can_copy(doc_list[idx].sci);
|
|
|
|
else
|
|
|
|
if (GTK_IS_EDITABLE(focusw))
|
|
|
|
enable = gtk_editable_get_selection_bounds(GTK_EDITABLE(focusw), NULL, NULL);
|
|
|
|
else
|
|
|
|
if (GTK_IS_TEXT_VIEW(focusw))
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(
|
|
|
|
GTK_TEXT_VIEW(focusw));
|
|
|
|
enable = gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2007-09-12 16:25:19 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS(ui_widgets.menu_copy_items); i++)
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.menu_copy_items[i], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_update_insert_include_item(gint idx, gint item)
|
|
|
|
{
|
|
|
|
gboolean enable = FALSE;
|
|
|
|
|
|
|
|
if (idx == -1 || doc_list[idx].file_type == NULL) enable = FALSE;
|
|
|
|
else if (doc_list[idx].file_type->id == GEANY_FILETYPES_C ||
|
|
|
|
doc_list[idx].file_type->id == GEANY_FILETYPES_CPP)
|
|
|
|
{
|
|
|
|
enable = TRUE;
|
|
|
|
}
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.menu_insert_include_items[item], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_update_fold_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-11-29 18:08:20 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "menu_fold_all1"), editor_prefs.folding);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "menu_unfold_all1"), editor_prefs.folding);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separator22"), editor_prefs.folding);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void insert_include_items(GtkMenu *me, GtkMenu *mp, gchar **includes, gchar *label)
|
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
GtkWidget *tmp_menu;
|
|
|
|
GtkWidget *tmp_popup;
|
|
|
|
GtkWidget *edit_menu, *edit_menu_item;
|
|
|
|
GtkWidget *popup_menu, *popup_menu_item;
|
|
|
|
|
|
|
|
edit_menu = gtk_menu_new();
|
|
|
|
popup_menu = gtk_menu_new();
|
|
|
|
edit_menu_item = gtk_menu_item_new_with_label(label);
|
|
|
|
popup_menu_item = gtk_menu_item_new_with_label(label);
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit_menu_item), edit_menu);
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(popup_menu_item), popup_menu);
|
|
|
|
|
|
|
|
while (includes[i] != NULL)
|
|
|
|
{
|
|
|
|
tmp_menu = gtk_menu_item_new_with_label(includes[i]);
|
|
|
|
tmp_popup = gtk_menu_item_new_with_label(includes[i]);
|
|
|
|
gtk_container_add(GTK_CONTAINER(edit_menu), tmp_menu);
|
|
|
|
gtk_container_add(GTK_CONTAINER(popup_menu), tmp_popup);
|
2006-12-17 19:31:32 +00:00
|
|
|
g_signal_connect((gpointer) tmp_menu, "activate",
|
|
|
|
G_CALLBACK(on_menu_insert_include_activate), (gpointer) includes[i]);
|
|
|
|
g_signal_connect((gpointer) tmp_popup, "activate",
|
|
|
|
G_CALLBACK(on_insert_include_activate), (gpointer) includes[i]);
|
2006-09-05 14:24:47 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
gtk_widget_show_all(edit_menu_item);
|
|
|
|
gtk_widget_show_all(popup_menu_item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(me), edit_menu_item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(mp), popup_menu_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_create_insert_menu_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_include2_menu"));
|
|
|
|
GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_include1_menu"));
|
|
|
|
GtkWidget *blank;
|
|
|
|
const gchar *c_includes_stdlib[] = {
|
|
|
|
"assert.h", "ctype.h", "errno.h", "float.h", "limits.h", "locale.h", "math.h", "setjmp.h",
|
|
|
|
"signal.h", "stdarg.h", "stddef.h", "stdio.h", "stdlib.h", "string.h", "time.h", NULL
|
|
|
|
};
|
|
|
|
const gchar *c_includes_c99[] = {
|
|
|
|
"complex.h", "fenv.h", "inttypes.h", "iso646.h", "stdbool.h", "stdint.h",
|
|
|
|
"tgmath.h", "wchar.h", "wctype.h", NULL
|
|
|
|
};
|
|
|
|
const gchar *c_includes_cpp[] = {
|
|
|
|
"cstdio", "cstring", "cctype", "cmath", "ctime", "cstdlib", "cstdarg", NULL
|
|
|
|
};
|
|
|
|
const gchar *c_includes_cppstdlib[] = {
|
|
|
|
"iostream", "fstream", "iomanip", "sstream", "exception", "stdexcept",
|
|
|
|
"memory", "locale", NULL
|
|
|
|
};
|
|
|
|
const gchar *c_includes_stl[] = {
|
|
|
|
"bitset", "dequev", "list", "map", "set", "queue", "stack", "vector", "algorithm",
|
|
|
|
"iterator", "functional", "string", "complex", "valarray", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
blank = gtk_menu_item_new_with_label("#include \"...\"");
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_edit), blank);
|
|
|
|
gtk_widget_show(blank);
|
2006-12-17 19:31:32 +00:00
|
|
|
g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_menu_insert_include_activate),
|
2006-09-05 14:24:47 +00:00
|
|
|
(gpointer) "blank");
|
|
|
|
blank = gtk_separator_menu_item_new ();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_edit), blank);
|
|
|
|
gtk_widget_show(blank);
|
|
|
|
|
|
|
|
blank = gtk_menu_item_new_with_label("#include \"...\"");
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_popup), blank);
|
|
|
|
gtk_widget_show(blank);
|
|
|
|
g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate),
|
|
|
|
(gpointer) "blank");
|
|
|
|
blank = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_popup), blank);
|
|
|
|
gtk_widget_show(blank);
|
|
|
|
|
|
|
|
insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stdlib, _("C Standard Library"));
|
|
|
|
insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_c99, _("ISO C99"));
|
|
|
|
insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cpp, _("C++ (C Standard Library)"));
|
|
|
|
insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cppstdlib, _("C++ Standard Library"));
|
|
|
|
insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stl, _("C++ STL"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void insert_date_items(GtkMenu *me, GtkMenu *mp, gchar *label)
|
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
|
2007-10-13 09:35:34 +00:00
|
|
|
item = gtk_menu_item_new_with_mnemonic(label);
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(me), item);
|
|
|
|
gtk_widget_show(item);
|
2006-12-17 19:31:32 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_menu_insert_date_activate), label);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-10-13 09:35:34 +00:00
|
|
|
item = gtk_menu_item_new_with_mnemonic(label);
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(mp), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_create_insert_date_menu_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_date1_menu"));
|
|
|
|
GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_date2_menu"));
|
|
|
|
GtkWidget *item;
|
2006-12-12 12:12:20 +00:00
|
|
|
gchar *str;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy"));
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy"));
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd"));
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_edit), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_popup), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy hh:mm:ss"));
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy hh:mm:ss"));
|
|
|
|
insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd hh:mm:ss"));
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_edit), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu_popup), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
|
2007-10-13 09:35:34 +00:00
|
|
|
str = _("_Use Custom Date Format");
|
|
|
|
item = gtk_menu_item_new_with_mnemonic(str);
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(menu_edit), item);
|
|
|
|
gtk_widget_show(item);
|
2006-12-17 19:31:32 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_menu_insert_date_activate),
|
2006-12-12 12:12:20 +00:00
|
|
|
str);
|
2006-09-05 14:24:47 +00:00
|
|
|
g_object_set_data_full(G_OBJECT(app->window), "insert_date_custom1", gtk_widget_ref(item),
|
|
|
|
(GDestroyNotify)gtk_widget_unref);
|
|
|
|
|
2007-10-13 09:35:34 +00:00
|
|
|
item = gtk_menu_item_new_with_mnemonic(str);
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(menu_popup), item);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate),
|
2006-12-12 12:12:20 +00:00
|
|
|
str);
|
2006-09-05 14:24:47 +00:00
|
|
|
g_object_set_data_full(G_OBJECT(app->popup_menu), "insert_date_custom2", gtk_widget_ref(item),
|
|
|
|
(GDestroyNotify)gtk_widget_unref);
|
|
|
|
|
2007-10-13 09:35:34 +00:00
|
|
|
insert_date_items(menu_edit, menu_popup, _("_Set Custom Date Format"));
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_save_buttons_toggle(gboolean enable)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
gboolean dirty_tabs = FALSE;
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.save_buttons[0], enable);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.save_buttons[1], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* save all menu item and tool button */
|
2008-03-24 13:23:01 +00:00
|
|
|
for (i = 0; i < doc_array->len; i++)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-03-23 16:43:01 +00:00
|
|
|
/* check whether there are files where changes were made and if there are some,
|
2008-02-27 13:17:29 +00:00
|
|
|
* we need the save all button / item */
|
2008-03-24 13:23:01 +00:00
|
|
|
if (doc_list[i].is_valid && doc_list[i].changed)
|
2008-03-23 16:43:01 +00:00
|
|
|
{
|
2006-09-05 14:24:47 +00:00
|
|
|
dirty_tabs = TRUE;
|
2008-03-23 16:43:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
2008-03-23 16:43:01 +00:00
|
|
|
gtk_widget_set_sensitive(ui_widgets.save_buttons[2], dirty_tabs);
|
|
|
|
gtk_widget_set_sensitive(ui_widgets.save_buttons[3], dirty_tabs);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void init_document_widgets(void)
|
2007-07-20 12:06:51 +00:00
|
|
|
{
|
|
|
|
/* Cache the document-sensitive widgets so we don't have to keep looking them up
|
|
|
|
* when using ui_document_buttons_update(). */
|
|
|
|
widgets.document_buttons[0] = lookup_widget(app->window, "menu_close1");
|
|
|
|
widgets.document_buttons[1] = lookup_widget(app->window, "toolbutton15");
|
|
|
|
widgets.document_buttons[2] = lookup_widget(app->window, "menu_change_font1");
|
|
|
|
widgets.document_buttons[3] = lookup_widget(app->window, "entry1");
|
|
|
|
widgets.document_buttons[4] = lookup_widget(app->window, "toolbutton18");
|
|
|
|
widgets.document_buttons[5] = lookup_widget(app->window, "toolbutton20");
|
|
|
|
widgets.document_buttons[6] = lookup_widget(app->window, "toolbutton21");
|
|
|
|
widgets.document_buttons[7] = lookup_widget(app->window, "menu_close_all1");
|
|
|
|
widgets.document_buttons[8] = lookup_widget(app->window, "menu_save_all1");
|
|
|
|
widgets.document_buttons[9] = lookup_widget(app->window, "toolbutton22");
|
2008-02-27 13:17:29 +00:00
|
|
|
widgets.document_buttons[10] = lookup_widget(app->window, "toolbutton13"); /* compile_button */
|
2007-07-20 12:06:51 +00:00
|
|
|
widgets.document_buttons[11] = lookup_widget(app->window, "menu_save_as1");
|
|
|
|
widgets.document_buttons[12] = lookup_widget(app->window, "toolbutton23");
|
|
|
|
widgets.document_buttons[13] = lookup_widget(app->window, "menu_count_words1");
|
|
|
|
widgets.document_buttons[14] = lookup_widget(app->window, "menu_build1");
|
|
|
|
widgets.document_buttons[15] = lookup_widget(app->window, "add_comments1");
|
2008-02-12 12:04:21 +00:00
|
|
|
widgets.document_buttons[16] = lookup_widget(app->window, "menu_paste1");
|
|
|
|
widgets.document_buttons[17] = lookup_widget(app->window, "menu_undo2");
|
|
|
|
widgets.document_buttons[18] = lookup_widget(app->window, "preferences2");
|
|
|
|
widgets.document_buttons[19] = lookup_widget(app->window, "menu_reload1");
|
|
|
|
widgets.document_buttons[20] = lookup_widget(app->window, "menu_document1");
|
|
|
|
widgets.document_buttons[21] = lookup_widget(app->window, "menu_markers_margin1");
|
|
|
|
widgets.document_buttons[22] = lookup_widget(app->window, "menu_linenumber_margin1");
|
|
|
|
widgets.document_buttons[23] = lookup_widget(app->window, "menu_choose_color1");
|
|
|
|
widgets.document_buttons[24] = lookup_widget(app->window, "menu_zoom_in1");
|
|
|
|
widgets.document_buttons[25] = lookup_widget(app->window, "menu_zoom_out1");
|
|
|
|
widgets.document_buttons[26] = lookup_widget(app->window, "normal_size1");
|
|
|
|
widgets.document_buttons[27] = lookup_widget(app->window, "toolbutton24");
|
|
|
|
widgets.document_buttons[28] = lookup_widget(app->window, "toolbutton25");
|
|
|
|
widgets.document_buttons[29] = lookup_widget(app->window, "entry_goto_line");
|
|
|
|
widgets.document_buttons[30] = lookup_widget(app->window, "treeview6");
|
|
|
|
widgets.document_buttons[31] = lookup_widget(app->window, "print1");
|
|
|
|
widgets.document_buttons[32] = lookup_widget(app->window, "menu_reload_as1");
|
|
|
|
widgets.document_buttons[33] = lookup_widget(app->window, "menu_select_all1");
|
|
|
|
widgets.document_buttons[34] = lookup_widget(app->window, "insert_date1");
|
|
|
|
widgets.document_buttons[35] = lookup_widget(app->window, "menu_format1");
|
|
|
|
widgets.document_buttons[36] = lookup_widget(app->window, "menu_open_selected_file1");
|
|
|
|
widgets.document_buttons[37] = lookup_widget(app->window, "page_setup1");
|
|
|
|
widgets.document_buttons[38] = lookup_widget(app->window, "find1");
|
|
|
|
widgets.document_buttons[39] = lookup_widget(app->window, "find_next1");
|
|
|
|
widgets.document_buttons[40] = lookup_widget(app->window, "find_previous1");
|
|
|
|
widgets.document_buttons[41] = lookup_widget(app->window, "replace1");
|
|
|
|
widgets.document_buttons[42] = lookup_widget(app->window, "find_nextsel1");
|
|
|
|
widgets.document_buttons[43] = lookup_widget(app->window, "find_prevsel1");
|
|
|
|
widgets.document_buttons[44] = lookup_widget(app->window, "go_to_line1");
|
2007-07-20 12:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_document_buttons_update(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) ? TRUE : FALSE;
|
|
|
|
|
2007-07-20 12:06:51 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS(widgets.document_buttons); i++)
|
|
|
|
gtk_widget_set_sensitive(widgets.document_buttons[i], enable);
|
2007-07-23 15:41:08 +00:00
|
|
|
|
2007-09-03 18:19:27 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
2007-07-23 15:41:08 +00:00
|
|
|
plugins_update_document_sensitive(enable);
|
2007-09-03 18:19:27 +00:00
|
|
|
#endif
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_widget_show_hide(GtkWidget *widget, gboolean show)
|
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
gtk_widget_show(widget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_sidebar_show_hide(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* check that there are no other notebook pages before hiding the sidebar completely
|
|
|
|
* other pages could be e.g. the file browser plugin */
|
2008-01-23 14:12:08 +00:00
|
|
|
if (! prefs.sidebar_openfiles_visible && ! prefs.sidebar_symbol_visible &&
|
|
|
|
gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->treeview_notebook)) <= 2)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_prefs.sidebar_visible = FALSE;
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
widget = lookup_widget(app->window, "menu_show_sidebar1");
|
2007-08-23 11:34:06 +00:00
|
|
|
if (ui_prefs.sidebar_visible != gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
app->ignore_callback = TRUE;
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), ui_prefs.sidebar_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
app->ignore_callback = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(app->treeview_notebook, ui_prefs.sidebar_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
ui_widget_show_hide(gtk_notebook_get_nth_page(
|
2007-08-23 11:34:06 +00:00
|
|
|
GTK_NOTEBOOK(app->treeview_notebook), 0), prefs.sidebar_symbol_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
ui_widget_show_hide(gtk_notebook_get_nth_page(
|
2007-08-23 11:34:06 +00:00
|
|
|
GTK_NOTEBOOK(app->treeview_notebook), 1), prefs.sidebar_openfiles_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_document_show_hide(gint idx)
|
|
|
|
{
|
|
|
|
gchar *widget_name;
|
2007-10-17 12:27:07 +00:00
|
|
|
GtkWidget *item;
|
2007-03-08 18:02:08 +00:00
|
|
|
|
|
|
|
if (idx == -1)
|
|
|
|
idx = document_get_cur_idx();
|
|
|
|
|
|
|
|
if (! DOC_IDX_VALID(idx))
|
|
|
|
return;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
app->ignore_callback = TRUE;
|
|
|
|
|
|
|
|
gtk_check_menu_item_set_active(
|
2008-05-09 14:17:25 +00:00
|
|
|
GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_line_wrapping1")),
|
2007-08-24 16:20:33 +00:00
|
|
|
doc_list[idx].line_wrapping);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-05-09 12:13:29 +00:00
|
|
|
gtk_check_menu_item_set_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "line_breaking1")),
|
|
|
|
doc_list[idx].line_breaking);
|
|
|
|
|
2007-10-17 12:27:07 +00:00
|
|
|
item = lookup_widget(app->window, "menu_use_auto_indentation1");
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
|
|
|
|
doc_list[idx].auto_indent);
|
|
|
|
gtk_widget_set_sensitive(item, editor_prefs.indent_mode != INDENT_NONE);
|
|
|
|
|
|
|
|
item = lookup_widget(app->window,
|
|
|
|
doc_list[idx].use_tabs ? "tabs1" : "spaces1");
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_check_menu_item_set_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "set_file_readonly1")),
|
|
|
|
doc_list[idx].readonly);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
|
|
|
item = lookup_widget(app->window, "menu_write_unicode_bom1");
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
|
|
|
|
doc_list[idx].has_bom);
|
|
|
|
gtk_widget_set_sensitive(item, encodings_is_unicode_charset(doc_list[idx].encoding));
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
switch (sci_get_eol_mode(doc_list[idx].sci))
|
|
|
|
{
|
|
|
|
case SC_EOL_CR: widget_name = "cr"; break;
|
|
|
|
case SC_EOL_LF: widget_name = "lf"; break;
|
|
|
|
default: widget_name = "crlf"; break;
|
|
|
|
}
|
2007-10-17 12:27:07 +00:00
|
|
|
gtk_check_menu_item_set_active(
|
|
|
|
GTK_CHECK_MENU_ITEM(lookup_widget(app->window, widget_name)), TRUE);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
encodings_select_radio_item(doc_list[idx].encoding);
|
|
|
|
filetypes_select_radio_item(doc_list[idx].file_type);
|
|
|
|
|
|
|
|
app->ignore_callback = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_update_toolbar_icons(GtkIconSize size)
|
|
|
|
{
|
|
|
|
GtkWidget *button_image = NULL;
|
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
GtkWidget *oldwidget = NULL;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* destroy old widget */
|
2006-09-05 14:24:47 +00:00
|
|
|
widget = lookup_widget(app->window, "toolbutton22");
|
|
|
|
oldwidget = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(widget));
|
|
|
|
if (oldwidget && GTK_IS_WIDGET(oldwidget)) gtk_widget_destroy(oldwidget);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create new widget */
|
2006-09-05 14:24:47 +00:00
|
|
|
button_image = ui_new_image_from_inline(GEANY_IMAGE_SAVE_ALL, FALSE);
|
|
|
|
gtk_widget_show(button_image);
|
|
|
|
gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(widget), button_image);
|
|
|
|
|
|
|
|
gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_update_toolbar_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* show toolbar */
|
2006-09-05 14:24:47 +00:00
|
|
|
GtkWidget *widget = lookup_widget(app->window, "menu_show_toolbar1");
|
2007-08-23 11:34:06 +00:00
|
|
|
if (prefs.toolbar_visible && ! gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* will be changed by the toggled callback */
|
|
|
|
prefs.toolbar_visible = ! prefs.toolbar_visible;
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE);
|
|
|
|
}
|
2007-08-23 11:34:06 +00:00
|
|
|
else if (! prefs.toolbar_visible && gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* will be changed by the toggled callback */
|
|
|
|
prefs.toolbar_visible = ! prefs.toolbar_visible;
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), FALSE);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* fileops */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "menutoolbutton1"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton9"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton10"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton22"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton23"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton15"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem7"), prefs.toolbar_show_fileops);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem2"), prefs.toolbar_show_fileops);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* search */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "entry1"), prefs.toolbar_show_search);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton18"), prefs.toolbar_show_search);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem5"), prefs.toolbar_show_search);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* goto line */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "entry_goto_line"), prefs.toolbar_show_goto);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton25"), prefs.toolbar_show_goto);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem8"), prefs.toolbar_show_goto);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* compile */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton13"), prefs.toolbar_show_compile);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton26"), prefs.toolbar_show_compile);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem6"), prefs.toolbar_show_compile);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* colour */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton24"), prefs.toolbar_show_colour);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem3"), prefs.toolbar_show_colour);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* zoom */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton20"), prefs.toolbar_show_zoom);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton21"), prefs.toolbar_show_zoom);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem4"), prefs.toolbar_show_zoom);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* indent */
|
2007-12-16 16:54:47 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_indent_dec"), prefs.toolbar_show_indent);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_indent_inc"), prefs.toolbar_show_indent);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem11"), prefs.toolbar_show_indent);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* undo */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_undo"), prefs.toolbar_show_undo);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_redo"), prefs.toolbar_show_undo);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem9"), prefs.toolbar_show_undo);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* navigation */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_back"), prefs.toolbar_show_navigation);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton_forward"), prefs.toolbar_show_navigation);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem10"), prefs.toolbar_show_navigation);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* quit */
|
2007-08-23 11:34:06 +00:00
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "toolbutton19"), prefs.toolbar_show_quit);
|
|
|
|
ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem8"), prefs.toolbar_show_quit);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Note: remember to unref the pixbuf once an image or window has added a reference. */
|
2006-09-05 14:24:47 +00:00
|
|
|
GdkPixbuf *ui_new_pixbuf_from_inline(gint img, gboolean small_img)
|
|
|
|
{
|
|
|
|
switch(img)
|
|
|
|
{
|
|
|
|
case GEANY_IMAGE_SMALL_CROSS: return gdk_pixbuf_new_from_inline(-1, close_small_inline, FALSE, NULL); break;
|
|
|
|
case GEANY_IMAGE_LOGO: return gdk_pixbuf_new_from_inline(-1, aladin_inline, FALSE, NULL); break;
|
|
|
|
case GEANY_IMAGE_SAVE_ALL:
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
if ((prefs.toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL),
|
|
|
|
16, 16, GDK_INTERP_HYPER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GEANY_IMAGE_NEW_ARROW:
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
if ((prefs.toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL),
|
|
|
|
16, 16, GDK_INTERP_HYPER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/*return gtk_image_new_from_pixbuf(pixbuf);*/
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *ui_new_image_from_inline(gint img, gboolean small_img)
|
|
|
|
{
|
2006-12-13 15:18:49 +00:00
|
|
|
GtkWidget *wid;
|
|
|
|
GdkPixbuf *pb;
|
|
|
|
|
|
|
|
pb = ui_new_pixbuf_from_inline(img, small_img);
|
|
|
|
wid = gtk_image_new_from_pixbuf(pb);
|
2008-02-27 13:17:29 +00:00
|
|
|
g_object_unref(pb); /* the image doesn't adopt our reference, so remove our ref. */
|
2006-12-13 15:18:49 +00:00
|
|
|
return wid;
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_create_recent_menu(void)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
|
|
|
GtkWidget *tmp;
|
|
|
|
guint i;
|
|
|
|
gchar *filename;
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
if (g_queue_get_length(ui_prefs.recent_queue) > 0)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
2007-05-25 14:42:43 +00:00
|
|
|
gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(
|
2007-08-23 11:34:06 +00:00
|
|
|
lookup_widget(app->window, "toolbutton9")), ui_widgets.recent_files_toolbar);
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
for (i = 0; i < MIN(prefs.mru_length, g_queue_get_length(ui_prefs.recent_queue)); i++)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
filename = g_queue_peek_nth(ui_prefs.recent_queue, i);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create menu item for the recent files menu in the menu bar */
|
2006-09-09 14:36:15 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(ui_widgets.recent_files_menubar), tmp);
|
2006-12-01 18:44:35 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create menu item for the recent files menu in the toolbar bar */
|
2006-12-01 18:44:35 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(ui_widgets.recent_files_toolbar), tmp);
|
2006-09-09 14:36:15 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
2006-09-21 09:55:50 +00:00
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
recent_file_activate_cb (GtkMenuItem *menuitem,
|
2006-09-21 09:55:50 +00:00
|
|
|
G_GNUC_UNUSED gpointer user_data)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
2008-05-13 17:18:14 +00:00
|
|
|
gchar *utf8_filename = ui_menu_item_get_text(menuitem);
|
2006-09-21 09:55:50 +00:00
|
|
|
gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
|
2006-09-09 14:36:15 +00:00
|
|
|
|
2007-09-11 15:21:11 +00:00
|
|
|
if (document_open_file(locale_filename, FALSE, NULL, NULL) > -1)
|
2006-09-21 09:55:50 +00:00
|
|
|
recent_file_loaded(utf8_filename);
|
2006-09-09 14:36:15 +00:00
|
|
|
|
|
|
|
g_free(locale_filename);
|
2006-09-21 09:55:50 +00:00
|
|
|
g_free(utf8_filename);
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_add_recent_file(const gchar *utf8_filename)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
if (g_queue_find_custom(ui_prefs.recent_queue, utf8_filename, (GCompareFunc) strcmp) == NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-10-13 10:41:38 +00:00
|
|
|
#if GTK_CHECK_VERSION(2, 10, 0)
|
|
|
|
GtkRecentManager *manager = gtk_recent_manager_get_default();
|
|
|
|
gchar *uri = g_filename_to_uri(utf8_filename, NULL, NULL);
|
|
|
|
if (uri != NULL)
|
|
|
|
{
|
|
|
|
gtk_recent_manager_add_item(manager, uri);
|
|
|
|
g_free(uri);
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-23 11:34:06 +00:00
|
|
|
g_queue_push_head(ui_prefs.recent_queue, g_strdup(utf8_filename));
|
|
|
|
if (g_queue_get_length(ui_prefs.recent_queue) > prefs.mru_length)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
g_free(g_queue_pop_tail(ui_prefs.recent_queue));
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2006-09-09 14:36:15 +00:00
|
|
|
update_recent_menu();
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else recent_file_loaded(utf8_filename); /* filename already in recent list */
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Returns: newly allocated string with the UTF-8 menu text. */
|
2008-05-13 17:18:14 +00:00
|
|
|
gchar *ui_menu_item_get_text(GtkMenuItem *menu_item)
|
2006-09-17 21:53:47 +00:00
|
|
|
{
|
|
|
|
const gchar *text = NULL;
|
|
|
|
|
2006-12-01 18:44:35 +00:00
|
|
|
if (GTK_BIN(menu_item)->child)
|
2006-09-17 21:53:47 +00:00
|
|
|
{
|
2006-12-01 18:44:35 +00:00
|
|
|
GtkWidget *child = GTK_BIN(menu_item)->child;
|
2006-09-17 21:53:47 +00:00
|
|
|
|
2006-12-01 18:44:35 +00:00
|
|
|
if (GTK_IS_LABEL(child))
|
2006-09-17 21:53:47 +00:00
|
|
|
text = gtk_label_get_text(GTK_LABEL(child));
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* GTK owns text so it's much safer to return a copy of it in case the memory is reallocated */
|
2006-09-21 09:55:50 +00:00
|
|
|
return g_strdup(text);
|
2006-09-17 21:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-01 18:44:35 +00:00
|
|
|
static gint find_recent_file_item(gconstpointer list_data, gconstpointer user_data)
|
|
|
|
{
|
2008-05-13 17:18:14 +00:00
|
|
|
gchar *menu_text = ui_menu_item_get_text(GTK_MENU_ITEM(list_data));
|
2006-12-01 18:44:35 +00:00
|
|
|
gint result;
|
|
|
|
|
2006-12-07 16:09:45 +00:00
|
|
|
if (utils_str_equal(menu_text, user_data))
|
2006-12-01 18:44:35 +00:00
|
|
|
result = 0;
|
|
|
|
else
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
g_free(menu_text);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-09 14:36:15 +00:00
|
|
|
static void recent_file_loaded(const gchar *utf8_filename)
|
|
|
|
{
|
2006-09-17 21:53:47 +00:00
|
|
|
GList *item, *children;
|
|
|
|
void *data;
|
2006-12-01 18:44:35 +00:00
|
|
|
GtkWidget *tmp;
|
2006-09-09 14:36:15 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* first reorder the queue */
|
2007-08-23 11:34:06 +00:00
|
|
|
item = g_queue_find_custom(ui_prefs.recent_queue, utf8_filename, (GCompareFunc) strcmp);
|
2006-09-17 21:53:47 +00:00
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
2006-09-09 14:36:15 +00:00
|
|
|
data = item->data;
|
2007-08-23 11:34:06 +00:00
|
|
|
g_queue_remove(ui_prefs.recent_queue, data);
|
|
|
|
g_queue_push_head(ui_prefs.recent_queue, data);
|
2006-09-09 14:36:15 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* remove the old menuitem for the filename */
|
2007-08-23 11:34:06 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(ui_widgets.recent_files_menubar));
|
2006-12-01 18:44:35 +00:00
|
|
|
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
|
|
|
|
if (item != NULL) gtk_widget_destroy(GTK_WIDGET(item->data));
|
2006-09-17 21:53:47 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(ui_widgets.recent_files_toolbar));
|
2006-12-01 18:44:35 +00:00
|
|
|
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
|
|
|
|
if (item != NULL) gtk_widget_destroy(GTK_WIDGET(item->data));
|
2006-09-17 21:53:47 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* now prepend a new menuitem for the filename,
|
|
|
|
* first for the recent files menu in the menu bar */
|
2006-09-17 21:53:47 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(utf8_filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(ui_widgets.recent_files_menubar), tmp);
|
2006-12-01 18:44:35 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* then for the recent files menu in the tool bar */
|
2006-12-01 18:44:35 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(utf8_filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(ui_widgets.recent_files_toolbar), tmp);
|
2006-09-17 21:53:47 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
2006-09-21 09:55:50 +00:00
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void update_recent_menu(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *tmp;
|
2007-05-25 14:42:43 +00:00
|
|
|
static GtkMenuToolButton *menu = NULL;
|
2006-09-05 14:24:47 +00:00
|
|
|
gchar *filename;
|
2006-12-01 18:44:35 +00:00
|
|
|
GList *children, *item;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2007-05-25 14:42:43 +00:00
|
|
|
if (menu == NULL)
|
|
|
|
menu = GTK_MENU_TOOL_BUTTON(lookup_widget(app->window, "toolbutton9"));
|
|
|
|
|
|
|
|
if (gtk_menu_tool_button_get_menu(menu) == NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_tool_button_set_menu(menu, ui_widgets.recent_files_toolbar);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* clean the MRU list before adding an item (menubar) */
|
2007-08-23 11:34:06 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(ui_widgets.recent_files_menubar));
|
|
|
|
if (g_list_length(children) > prefs.mru_length - 1)
|
2006-12-01 18:44:35 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
item = g_list_nth(children, prefs.mru_length - 1);
|
2006-12-01 18:44:35 +00:00
|
|
|
while (item != NULL)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
|
|
|
|
item = g_list_next(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* clean the MRU list before adding an item (toolbar) */
|
2007-08-23 11:34:06 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(ui_widgets.recent_files_toolbar));
|
|
|
|
if (g_list_length(children) > prefs.mru_length - 1)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
item = g_list_nth(children, prefs.mru_length - 1);
|
2006-09-05 14:24:47 +00:00
|
|
|
while (item != NULL)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
|
|
|
|
item = g_list_next(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
filename = g_queue_peek_head(ui_prefs.recent_queue);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create item for the menu bar menu */
|
2006-09-05 14:24:47 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(ui_widgets.recent_files_menubar), tmp);
|
2006-12-01 18:44:35 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create item for the tool bar menu */
|
2006-12-01 18:44:35 +00:00
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(ui_widgets.recent_files_toolbar), tmp);
|
2006-09-05 14:24:47 +00:00
|
|
|
g_signal_connect((gpointer) tmp, "activate",
|
2006-09-21 09:55:50 +00:00
|
|
|
G_CALLBACK(recent_file_activate_cb), NULL);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_show_markers_margin(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook));
|
|
|
|
|
|
|
|
for(i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
idx = document_get_n_idx(i);
|
2007-08-23 11:34:06 +00:00
|
|
|
sci_set_symbol_margin(doc_list[idx].sci, editor_prefs.show_markers_margin);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_show_linenumber_margin(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook));
|
|
|
|
|
|
|
|
for(i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
idx = document_get_n_idx(i);
|
2007-08-23 11:34:06 +00:00
|
|
|
sci_set_line_numbers(doc_list[idx].sci, editor_prefs.show_linenumber_margin, 0);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-24 11:11:06 +00:00
|
|
|
/* Creates a GNOME HIG style frame (with no border and indented child alignment).
|
|
|
|
* Returns the frame widget, setting the alignment container for packing child widgets */
|
|
|
|
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment)
|
2006-09-15 14:25:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label, *align;
|
|
|
|
GtkWidget *frame = gtk_frame_new (NULL);
|
|
|
|
gchar *label_markup;
|
|
|
|
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
|
|
|
|
|
|
|
|
align = gtk_alignment_new (0.5, 0.5, 1, 1);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), align);
|
2006-10-04 19:14:57 +00:00
|
|
|
gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
|
2006-09-15 14:25:42 +00:00
|
|
|
|
|
|
|
label_markup = g_strconcat("<b>", label_text, "</b>", NULL);
|
|
|
|
label = gtk_label_new (label_markup);
|
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
|
|
|
g_free(label_markup);
|
|
|
|
|
2006-11-24 11:11:06 +00:00
|
|
|
*alignment = align;
|
|
|
|
return frame;
|
2006-09-15 14:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 14:56:05 +00:00
|
|
|
const gint BUTTON_BOX_BORDER = 5;
|
|
|
|
|
2007-04-29 12:03:25 +00:00
|
|
|
/* Convenience function for getting a fixed border for dialogs that doesn't
|
|
|
|
* increase the button box border.
|
|
|
|
* dialog is the parent container for the vbox.
|
|
|
|
* Returns: the vbox. */
|
2006-10-22 14:56:05 +00:00
|
|
|
GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 12); /* need child vbox to set a separate border. */
|
2006-10-22 14:56:05 +00:00
|
|
|
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), BUTTON_BOX_BORDER);
|
|
|
|
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
|
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-01 15:26:41 +00:00
|
|
|
/* Create a GtkButton with custom text and a stock image, aligned like
|
|
|
|
* gtk_button_new_from_stock */
|
|
|
|
GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text)
|
|
|
|
{
|
|
|
|
GtkWidget *image, *label, *align, *hbox, *button;
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 2);
|
|
|
|
image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON);
|
|
|
|
label = gtk_label_new_with_mnemonic(text);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
button = gtk_button_new();
|
|
|
|
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
|
|
|
|
gtk_container_add(GTK_CONTAINER(align), hbox);
|
|
|
|
gtk_container_add(GTK_CONTAINER(button), align);
|
2006-12-08 16:21:52 +00:00
|
|
|
gtk_widget_show_all(align);
|
2006-11-01 15:26:41 +00:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_to_size_group(GtkWidget *widget, gpointer size_group)
|
|
|
|
{
|
|
|
|
g_return_if_fail(GTK_IS_SIZE_GROUP(size_group));
|
|
|
|
gtk_size_group_add_widget(GTK_SIZE_GROUP(size_group), widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copies the spacing and layout of the master GtkHButtonBox and synchronises
|
|
|
|
* the width of each button box's children.
|
|
|
|
* Should be called after all child widgets have been packed. */
|
|
|
|
void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy)
|
|
|
|
{
|
|
|
|
GtkSizeGroup *size_group;
|
|
|
|
|
|
|
|
/* set_spacing is deprecated but there seems to be no alternative,
|
|
|
|
* GTK 2.6 defaults to no spacing, unlike dialog button box */
|
|
|
|
gtk_button_box_set_spacing(copy, 10);
|
|
|
|
gtk_button_box_set_layout(copy, gtk_button_box_get_layout(master));
|
|
|
|
|
|
|
|
/* now we need to put the widest widget from each button box in a size group,
|
|
|
|
* but we don't know the width before they are drawn, and for different label
|
|
|
|
* translations the widest widget can vary, so we just add all widgets. */
|
|
|
|
size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
gtk_container_foreach(GTK_CONTAINER(master), add_to_size_group, size_group);
|
|
|
|
gtk_container_foreach(GTK_CONTAINER(copy), add_to_size_group, size_group);
|
|
|
|
g_object_unref(size_group);
|
|
|
|
}
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2006-11-15 15:57:23 +00:00
|
|
|
/* Prepends the active text to the drop down list, unless the first element in
|
|
|
|
* the list is identical, ensuring there are <= history_len elements. */
|
|
|
|
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text)
|
|
|
|
{
|
|
|
|
const gint history_len = 30;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *combo_text;
|
|
|
|
gboolean equal = FALSE;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model(combo);
|
|
|
|
if (gtk_tree_model_get_iter_first(model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, 0, &combo_text, -1);
|
2006-12-07 16:09:45 +00:00
|
|
|
equal = utils_str_equal(combo_text, text);
|
2006-11-15 15:57:23 +00:00
|
|
|
g_free(combo_text);
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
if (equal) return; /* don't prepend duplicate */
|
2006-11-15 15:57:23 +00:00
|
|
|
|
|
|
|
gtk_combo_box_prepend_text(combo, text);
|
2006-12-01 18:44:35 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* limit history */
|
2006-11-15 15:57:23 +00:00
|
|
|
path = gtk_tree_path_new_from_indices(history_len, -1);
|
|
|
|
if (gtk_tree_model_get_iter(model, &iter, path))
|
|
|
|
{
|
|
|
|
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
|
|
|
|
}
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
|
|
|
|
2006-12-05 10:37:36 +00:00
|
|
|
|
|
|
|
/* Changes the color of the notebook tab text and open files items according to
|
|
|
|
* document status. */
|
|
|
|
void ui_update_tab_status(gint idx)
|
|
|
|
{
|
2008-05-15 13:43:29 +00:00
|
|
|
GdkColor *color = document_get_status_color(idx);
|
2006-12-05 10:37:36 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* NULL color will reset to default */
|
2006-12-30 11:49:47 +00:00
|
|
|
gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_NORMAL, color);
|
|
|
|
gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_ACTIVE, color);
|
2007-01-06 17:16:43 +00:00
|
|
|
gtk_widget_modify_fg(doc_list[idx].tabmenu_label, GTK_STATE_NORMAL, color);
|
|
|
|
gtk_widget_modify_fg(doc_list[idx].tabmenu_label, GTK_STATE_ACTIVE, color);
|
2006-12-05 10:37:36 +00:00
|
|
|
|
|
|
|
treeviews_openfiles_update(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
/* Returns FALSE if the treeview has items but no matching next item. */
|
|
|
|
gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *treesel;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
treesel = gtk_tree_view_get_selection(treeview);
|
|
|
|
if (gtk_tree_selection_get_selected(treesel, &model, &iter))
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get the next selected item */
|
2006-12-08 15:50:10 +00:00
|
|
|
if (! gtk_tree_model_iter_next(model, &iter))
|
2008-02-27 13:17:29 +00:00
|
|
|
return FALSE; /* no more items */
|
2006-12-08 15:50:10 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else /* no selection */
|
2006-12-08 15:50:10 +00:00
|
|
|
{
|
|
|
|
if (! gtk_tree_model_get_iter_first(model, &iter))
|
2008-02-27 13:17:29 +00:00
|
|
|
return TRUE; /* no items */
|
2006-12-08 15:50:10 +00:00
|
|
|
}
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
gtk_tree_selection_select_iter(treesel, &iter);
|
|
|
|
if (cb())
|
2008-02-27 13:17:29 +00:00
|
|
|
break; /* found next message */
|
2006-12-08 15:50:10 +00:00
|
|
|
|
|
|
|
if (! gtk_tree_model_iter_next(model, &iter))
|
2008-02-27 13:17:29 +00:00
|
|
|
return FALSE; /* no more items */
|
2006-12-08 15:50:10 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* scroll item in view */
|
2007-08-23 11:34:06 +00:00
|
|
|
if (ui_prefs.msgwindow_visible)
|
2007-02-17 16:52:52 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_model_get_path(
|
|
|
|
gtk_tree_view_get_model(treeview), &iter);
|
|
|
|
|
|
|
|
gtk_tree_view_scroll_to_cell(treeview, path, NULL, TRUE, 0.5, 0.5);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
2006-12-08 15:50:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-13 15:18:49 +00:00
|
|
|
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str)
|
|
|
|
{
|
|
|
|
PangoFontDescription *pfd;
|
|
|
|
|
|
|
|
pfd = pango_font_description_from_string(str);
|
|
|
|
gtk_widget_modify_font(wid, pfd);
|
|
|
|
pango_font_description_free(pfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 12:03:25 +00:00
|
|
|
/* Creates a GtkHBox with entry packed into it and an open button which runs a
|
|
|
|
* file chooser, replacing entry text if successful.
|
|
|
|
* entry can be the child of an unparented widget, such as GtkComboBoxEntry.
|
2007-05-11 16:34:18 +00:00
|
|
|
* See ui_setup_open_button_callback() for details. */
|
|
|
|
GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry)
|
2007-04-29 12:03:25 +00:00
|
|
|
{
|
|
|
|
GtkWidget *vbox, *dirbtn, *openimg, *hbox, *path_entry;
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 6);
|
|
|
|
path_entry = GTK_WIDGET(entry);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* prevent path_entry being vertically stretched to the height of dirbtn */
|
2007-04-29 12:03:25 +00:00
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
2008-02-27 13:17:29 +00:00
|
|
|
if (gtk_widget_get_parent(path_entry)) /* entry->parent may be a GtkComboBoxEntry */
|
2007-04-29 12:03:25 +00:00
|
|
|
{
|
|
|
|
GtkWidget *parent = gtk_widget_get_parent(path_entry);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), parent, TRUE, FALSE, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), path_entry, TRUE, FALSE, 0);
|
|
|
|
|
|
|
|
dirbtn = gtk_button_new();
|
|
|
|
openimg = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_container_add(GTK_CONTAINER(dirbtn), openimg);
|
2007-05-11 16:34:18 +00:00
|
|
|
ui_setup_open_button_callback(dirbtn, title, action, entry);
|
2007-04-29 12:03:25 +00:00
|
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), dirbtn, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_end(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
|
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data);
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup a GtkButton to run a GtkFileChooser, setting entry text if successful.
|
2007-05-11 16:34:18 +00:00
|
|
|
* title can be NULL.
|
2007-04-29 12:03:25 +00:00
|
|
|
* action is the file chooser mode to use. */
|
2007-05-11 16:34:18 +00:00
|
|
|
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
|
|
|
|
GtkFileChooserAction action, GtkEntry *entry)
|
2007-04-29 12:03:25 +00:00
|
|
|
{
|
|
|
|
GtkWidget *path_entry = GTK_WIDGET(entry);
|
|
|
|
|
2007-05-11 16:34:18 +00:00
|
|
|
if (title)
|
|
|
|
g_object_set_data_full(G_OBJECT(open_btn), "title",
|
|
|
|
g_strdup(title), (GDestroyNotify) g_free);
|
2007-04-29 12:03:25 +00:00
|
|
|
g_object_set_data(G_OBJECT(open_btn), "action", (gpointer) action);
|
2007-05-11 16:34:18 +00:00
|
|
|
g_object_set_data_full(G_OBJECT(open_btn), "entry",
|
|
|
|
gtk_widget_ref(path_entry), (GDestroyNotify) gtk_widget_unref);
|
2007-04-29 12:03:25 +00:00
|
|
|
g_signal_connect(G_OBJECT(open_btn), "clicked",
|
|
|
|
G_CALLBACK(ui_path_box_open_clicked), open_btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-11 16:34:18 +00:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
static gchar *run_file_chooser(const gchar *title, GtkFileChooserAction action,
|
|
|
|
const gchar *utf8_path)
|
2007-04-29 12:03:25 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog = gtk_file_chooser_dialog_new(title,
|
|
|
|
GTK_WINDOW(app->window), action,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
|
|
|
|
gchar *locale_path;
|
2007-05-11 16:34:18 +00:00
|
|
|
gchar *ret_path = NULL;
|
2007-04-29 12:03:25 +00:00
|
|
|
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialog");
|
2007-04-29 12:03:25 +00:00
|
|
|
locale_path = utils_get_locale_from_utf8(utf8_path);
|
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
|
|
{
|
|
|
|
if (g_path_is_absolute(locale_path) && g_file_test(locale_path, G_FILE_TEST_IS_DIR))
|
|
|
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
|
|
|
|
}
|
|
|
|
g_free(locale_path);
|
|
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
2007-05-11 16:34:18 +00:00
|
|
|
gchar *dir_locale;
|
|
|
|
|
2007-04-29 12:03:25 +00:00
|
|
|
dir_locale = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
|
2007-05-11 16:34:18 +00:00
|
|
|
ret_path = utils_get_utf8_from_locale(dir_locale);
|
2007-04-29 12:03:25 +00:00
|
|
|
g_free(dir_locale);
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(dialog);
|
2007-05-11 16:34:18 +00:00
|
|
|
return ret_path;
|
2007-04-29 12:03:25 +00:00
|
|
|
}
|
2007-05-11 16:34:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *path_box = GTK_WIDGET(user_data);
|
|
|
|
GtkFileChooserAction action =
|
|
|
|
(GtkFileChooserAction) g_object_get_data(G_OBJECT(path_box), "action");
|
|
|
|
GtkEntry *entry =
|
|
|
|
(GtkEntry *) g_object_get_data(G_OBJECT(path_box), "entry");
|
|
|
|
const gchar *title = g_object_get_data(G_OBJECT(path_box), "title");
|
|
|
|
gchar *utf8_path;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* TODO: extend for other actions */
|
2007-05-11 16:34:18 +00:00
|
|
|
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
|
|
|
|
|
|
|
if (title == NULL)
|
|
|
|
title = (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ?
|
|
|
|
_("Select Folder") : _("Select File");
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2007-12-07 16:31:38 +00:00
|
|
|
utf8_path = win32_show_project_folder_dialog(ui_widgets.prefs_dialog, title,
|
2007-05-11 16:34:18 +00:00
|
|
|
gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
|
|
#else
|
|
|
|
utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (utf8_path != NULL)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), utf8_path);
|
|
|
|
g_free(utf8_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-29 12:03:25 +00:00
|
|
|
|
2007-05-04 16:59:00 +00:00
|
|
|
void ui_statusbar_showhide(gboolean state)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* handle statusbar visibility */
|
2007-05-04 16:59:00 +00:00
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
gtk_widget_show(app->statusbar);
|
|
|
|
ui_update_statusbar(-1, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_widget_hide(app->statusbar);
|
|
|
|
}
|
2007-07-13 15:54:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Pack all GtkWidgets passed after the row argument into a table, using
|
|
|
|
* one widget per cell. The first widget is not expanded, as this is usually
|
|
|
|
* a label. */
|
|
|
|
void ui_table_add_row(GtkTable *table, gint row, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gint i;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
va_start(args, row);
|
|
|
|
for (i = 0; (widget = va_arg(args, GtkWidget*), widget != NULL); i++)
|
|
|
|
{
|
|
|
|
gint options = (i == 0) ? GTK_FILL : GTK_EXPAND | GTK_FILL;
|
|
|
|
|
|
|
|
gtk_table_attach(GTK_TABLE(table), widget, i, i + 1, row, row + 1,
|
|
|
|
options, 0, 0, 0);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_init(void)
|
2007-07-20 12:06:51 +00:00
|
|
|
{
|
|
|
|
init_document_widgets();
|
|
|
|
}
|