2006-09-05 14:24:47 +00:00
|
|
|
/*
|
|
|
|
* ui_utils.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2012-06-18 01:13:05 +02:00
|
|
|
* Copyright 2006-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
|
|
|
* Copyright 2011-2012 Matthew Brush <mbrush(at)codebrainz(dot)ca>
|
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.
|
|
|
|
*
|
2012-08-24 19:25:57 +02:00
|
|
|
* 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.
|
2006-09-05 14:24:47 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-28 17:25:09 +00:00
|
|
|
/** @file ui_utils.h
|
2007-02-24 11:41:56 +00:00
|
|
|
* User Interface general utility functions.
|
|
|
|
*/
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
#include "geany.h"
|
|
|
|
|
2011-09-24 14:34:05 -07:00
|
|
|
#include "support.h"
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
#include <string.h>
|
2010-05-10 17:21:13 +00:00
|
|
|
#include <ctype.h>
|
2010-03-07 19:33:15 +00:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
#include "ui_utils.h"
|
2011-12-10 16:14:11 -08:00
|
|
|
#include "dialogs.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"
|
2008-06-02 15:31:59 +00:00
|
|
|
#include "documentprivate.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"
|
2009-09-28 11:16:59 +00:00
|
|
|
#include "sidebar.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"
|
2008-07-08 16:30:37 +00:00
|
|
|
#include "symbols.h"
|
2008-12-06 11:10:06 +00:00
|
|
|
#include "toolbar.h"
|
2009-06-20 16:51:32 +00:00
|
|
|
#include "geanymenubuttonaction.h"
|
2010-06-17 12:35:17 +00:00
|
|
|
#include "main.h"
|
2010-07-09 17:15:16 +00:00
|
|
|
#include "stash.h"
|
|
|
|
#include "keyfile.h"
|
2012-09-15 13:52:49 +02:00
|
|
|
#include "gtkcompat.h"
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
|
2013-04-14 17:08:09 -07:00
|
|
|
#define DEFAULT_STATUSBAR_TEMPLATE N_(\
|
|
|
|
"line: %l / %L\t " \
|
|
|
|
"col: %c\t " \
|
|
|
|
"sel: %s\t " \
|
|
|
|
"%w %t %m" \
|
|
|
|
"mode: %M " \
|
|
|
|
"encoding: %e " \
|
|
|
|
"filetype: %f " \
|
|
|
|
"scope: %S")
|
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
GeanyInterfacePrefs interface_prefs;
|
2008-05-22 14:41:28 +00:00
|
|
|
GeanyMainWidgets main_widgets;
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
UIPrefs ui_prefs;
|
|
|
|
UIWidgets ui_widgets;
|
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
static GtkBuilder *builder = NULL;
|
|
|
|
static GtkWidget* window1 = NULL;
|
|
|
|
static GtkWidget* toolbar_popup_menu1 = NULL;
|
|
|
|
static GtkWidget* edit_menu1 = NULL;
|
|
|
|
static GtkWidget* prefs_dialog = NULL;
|
|
|
|
static GtkWidget* project_dialog = NULL;
|
2011-10-14 20:12:06 -07:00
|
|
|
|
2007-07-20 12:06:51 +00:00
|
|
|
static struct
|
|
|
|
{
|
2009-06-20 16:51:32 +00:00
|
|
|
/* pointers to widgets only sensitive when there is at least one document, the pointers can
|
|
|
|
* also be GtkAction objects, so check each pointer before using it */
|
2008-07-17 16:28:16 +00:00
|
|
|
GPtrArray *document_buttons;
|
|
|
|
GtkWidget *menu_insert_include_items[2];
|
2010-11-08 12:35:50 +00:00
|
|
|
GtkWidget *popup_goto_items[4];
|
2008-07-17 16:28:16 +00:00
|
|
|
GtkWidget *popup_copy_items[3];
|
|
|
|
GtkWidget *menu_copy_items[3];
|
|
|
|
GtkWidget *redo_items[3];
|
|
|
|
GtkWidget *undo_items[3];
|
|
|
|
GtkWidget *save_buttons[4];
|
2008-11-26 13:15:53 +00:00
|
|
|
GtkWidget *config_files_menu;
|
2007-07-20 12:06:51 +00:00
|
|
|
}
|
|
|
|
widgets;
|
|
|
|
|
2009-04-07 22:09:23 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RECENT_FILE_FILE,
|
|
|
|
RECENT_FILE_PROJECT
|
|
|
|
};
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-04-07 22:09:23 +00:00
|
|
|
gint type;
|
2009-04-05 14:14:29 +00:00
|
|
|
GQueue *recent_queue;
|
|
|
|
GtkWidget *menubar;
|
|
|
|
GtkWidget *toolbar;
|
|
|
|
void (*activate_cb)(GtkMenuItem *, gpointer);
|
|
|
|
} GeanyRecentFiles;
|
|
|
|
|
2007-07-20 12:06:51 +00:00
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static void update_recent_menu(GeanyRecentFiles *grf);
|
|
|
|
static void recent_file_loaded(const gchar *utf8_filename, GeanyRecentFiles *grf);
|
2008-12-06 11:10:06 +00:00
|
|
|
static void recent_file_activate_cb(GtkMenuItem *menuitem, gpointer user_data);
|
2009-04-05 14:14:29 +00:00
|
|
|
static void recent_project_activate_cb(GtkMenuItem *menuitem, gpointer user_data);
|
2009-01-27 20:19:43 +00:00
|
|
|
static GtkWidget *progress_bar_create(void);
|
2008-12-06 11:10:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* simple wrapper for gtk_widget_set_sensitive() to allow widget being NULL */
|
|
|
|
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set)
|
|
|
|
{
|
2009-04-15 22:47:33 +00:00
|
|
|
if (widget != NULL)
|
2008-12-06 11:10:06 +00:00
|
|
|
gtk_widget_set_sensitive(widget, set);
|
|
|
|
}
|
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
|
|
|
{
|
2012-12-02 18:03:14 +01:00
|
|
|
static guint id = 0;
|
2006-09-05 14:24:47 +00:00
|
|
|
static glong last_time = 0;
|
|
|
|
GTimeVal timeval;
|
|
|
|
const gint GEANY_STATUS_TIMEOUT = 1;
|
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
if (! interface_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
|
|
|
|
2012-12-02 18:03:14 +01:00
|
|
|
if (id == 0)
|
|
|
|
id = gtk_statusbar_get_context_id(GTK_STATUSBAR(ui_widgets.statusbar), "geany-main");
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
g_get_current_time(&timeval);
|
|
|
|
|
|
|
|
if (! allow_override)
|
|
|
|
{
|
2012-12-02 18:03:14 +01:00
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(ui_widgets.statusbar), id);
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(ui_widgets.statusbar), id, text);
|
2006-09-05 14:24:47 +00:00
|
|
|
last_time = timeval.tv_sec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (timeval.tv_sec > last_time + GEANY_STATUS_TIMEOUT)
|
|
|
|
{
|
2012-12-02 18:03:14 +01:00
|
|
|
gtk_statusbar_pop(GTK_STATUSBAR(ui_widgets.statusbar), id);
|
|
|
|
gtk_statusbar_push(GTK_STATUSBAR(ui_widgets.statusbar), id, text);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Displays text on the statusbar.
|
2008-07-24 12:01:30 +00:00
|
|
|
* @param log Whether the message should be recorded in the Status window.
|
|
|
|
* @param format A @c printf -style string. */
|
2007-10-24 10:52:48 +00:00
|
|
|
void ui_set_statusbar(gboolean log, const gchar *format, ...)
|
2006-11-25 16:33:38 +00:00
|
|
|
{
|
2010-04-25 17:42:01 +00:00
|
|
|
gchar *string;
|
2006-11-25 16:33:38 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2010-04-25 17:42:01 +00:00
|
|
|
string = g_strdup_vprintf(format, args);
|
2006-11-25 16:33:38 +00:00
|
|
|
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);
|
2010-04-25 17:42:01 +00:00
|
|
|
|
|
|
|
g_free(string);
|
2006-11-25 16:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-29 12:11:21 +00:00
|
|
|
/* note: some comments below are for translators */
|
2013-04-14 17:08:09 -07:00
|
|
|
static gchar *create_statusbar_statistics(GeanyDocument *doc,
|
|
|
|
guint line, guint col, guint pos)
|
2010-06-29 12:11:21 +00:00
|
|
|
{
|
|
|
|
const gchar *cur_tag;
|
|
|
|
const gchar *fmt;
|
|
|
|
const gchar *expos; /* % expansion position */
|
|
|
|
const gchar sp[] = " ";
|
2013-04-14 17:08:09 -07:00
|
|
|
GString *stats_str;
|
2012-04-22 17:31:38 +01:00
|
|
|
ScintillaObject *sci = doc->editor->sci;
|
2010-06-29 12:11:21 +00:00
|
|
|
|
2013-08-11 14:10:57 +01:00
|
|
|
if (!EMPTY(ui_prefs.statusbar_template))
|
2013-04-14 17:08:09 -07:00
|
|
|
fmt = ui_prefs.statusbar_template;
|
|
|
|
else
|
|
|
|
fmt = _(DEFAULT_STATUSBAR_TEMPLATE);
|
|
|
|
|
|
|
|
stats_str = g_string_sized_new(120);
|
2010-06-29 12:11:21 +00:00
|
|
|
|
|
|
|
while ((expos = strchr(fmt, '%')) != NULL)
|
|
|
|
{
|
|
|
|
/* append leading text before % char */
|
|
|
|
g_string_append_len(stats_str, fmt, expos - fmt);
|
|
|
|
|
|
|
|
switch (*++expos)
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
g_string_append_printf(stats_str, "%d", line + 1);
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
g_string_append_printf(stats_str, "%d",
|
|
|
|
sci_get_line_count(doc->editor->sci));
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
g_string_append_printf(stats_str, "%d", col);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
g_string_append_printf(stats_str, "%d", col + 1);
|
|
|
|
break;
|
2013-04-14 17:08:09 -07:00
|
|
|
case 'p':
|
|
|
|
g_string_append_printf(stats_str, "%u", pos);
|
|
|
|
break;
|
2010-06-29 12:11:21 +00:00
|
|
|
case 's':
|
2012-04-22 17:31:38 +01:00
|
|
|
{
|
|
|
|
gint len = sci_get_selected_text_length(sci) - 1;
|
|
|
|
/* check if whole lines are selected */
|
|
|
|
if (!len || sci_get_col_from_position(sci,
|
|
|
|
sci_get_selection_start(sci)) != 0 ||
|
|
|
|
sci_get_col_from_position(sci,
|
|
|
|
sci_get_selection_end(sci)) != 0)
|
|
|
|
g_string_append_printf(stats_str, "%d", len);
|
|
|
|
else /* L = lines */
|
|
|
|
g_string_append_printf(stats_str, _("%dL"),
|
|
|
|
sci_get_lines_selected(doc->editor->sci) - 1);
|
2010-06-29 12:11:21 +00:00
|
|
|
break;
|
2012-04-22 17:31:38 +01:00
|
|
|
}
|
2010-06-29 12:11:21 +00:00
|
|
|
case 'w':
|
|
|
|
/* RO = read-only */
|
|
|
|
g_string_append(stats_str, (doc->readonly) ? _("RO ") :
|
|
|
|
/* OVR = overwrite/overtype, INS = insert */
|
|
|
|
(sci_get_overtype(doc->editor->sci) ? _("OVR") : _("INS")));
|
|
|
|
break;
|
|
|
|
case 'r':
|
2010-06-29 15:44:41 +00:00
|
|
|
if (doc->readonly)
|
|
|
|
{
|
|
|
|
g_string_append(stats_str, _("RO ")); /* RO = read-only */
|
|
|
|
g_string_append(stats_str, sp + 1);
|
|
|
|
}
|
2010-06-29 12:11:21 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
{
|
|
|
|
switch (editor_get_indent_prefs(doc->editor)->type)
|
|
|
|
{
|
|
|
|
case GEANY_INDENT_TYPE_TABS:
|
|
|
|
g_string_append(stats_str, _("TAB"));
|
|
|
|
break;
|
|
|
|
case GEANY_INDENT_TYPE_SPACES: /* SP = space */
|
|
|
|
g_string_append(stats_str, _("SP"));
|
|
|
|
break;
|
|
|
|
case GEANY_INDENT_TYPE_BOTH: /* T/S = tabs and spaces */
|
|
|
|
g_string_append(stats_str, _("T/S"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'm':
|
|
|
|
if (doc->changed)
|
|
|
|
{
|
2010-06-29 15:44:41 +00:00
|
|
|
g_string_append(stats_str, _("MOD")); /* MOD = modified */
|
2010-06-29 12:11:21 +00:00
|
|
|
g_string_append(stats_str, sp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
g_string_append(stats_str, editor_get_eol_char_name(doc->editor));
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
g_string_append(stats_str,
|
|
|
|
doc->encoding ? doc->encoding : _("unknown"));
|
|
|
|
if (encodings_is_unicode_charset(doc->encoding) && (doc->has_bom))
|
2010-06-29 15:44:41 +00:00
|
|
|
{
|
|
|
|
g_string_append_c(stats_str, ' ');
|
2010-06-29 12:11:21 +00:00
|
|
|
g_string_append(stats_str, _("(with BOM)")); /* BOM = byte order mark */
|
2010-06-29 15:44:41 +00:00
|
|
|
}
|
2010-06-29 12:11:21 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2010-11-04 18:06:09 +00:00
|
|
|
g_string_append(stats_str, filetypes_get_display_name(doc->file_type));
|
2010-06-29 12:11:21 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2012-09-17 22:51:36 +02:00
|
|
|
symbols_get_current_scope(doc, &cur_tag);
|
2010-06-29 12:11:21 +00:00
|
|
|
g_string_append(stats_str, cur_tag);
|
|
|
|
break;
|
2013-04-14 17:08:09 -07:00
|
|
|
case 'Y':
|
|
|
|
g_string_append_c(stats_str, ' ');
|
|
|
|
g_string_append_printf(stats_str, "%d",
|
|
|
|
sci_get_style_at(doc->editor->sci, pos));
|
|
|
|
break;
|
2010-06-29 12:11:21 +00:00
|
|
|
default:
|
|
|
|
g_string_append_len(stats_str, expos, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip past %c chars */
|
|
|
|
if (*expos)
|
|
|
|
fmt = expos + 1;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* add any remaining text */
|
|
|
|
g_string_append(stats_str, fmt);
|
2013-04-14 17:08:09 -07:00
|
|
|
|
|
|
|
return g_string_free(stats_str, FALSE);
|
2010-06-29 12:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-25 16:33:38 +00:00
|
|
|
/* updates the status bar document statistics */
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_statusbar(GeanyDocument *doc, gint pos)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
if (! interface_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
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc == NULL)
|
2008-06-15 13:35:48 +00:00
|
|
|
doc = document_get_current();
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc != NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-10-17 12:27:07 +00:00
|
|
|
guint line, col;
|
2013-04-14 17:08:09 -07:00
|
|
|
gchar *stats_str;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2009-04-05 21:07:40 +00:00
|
|
|
if (pos == -1)
|
|
|
|
pos = sci_get_current_position(doc->editor->sci);
|
2008-07-14 11:13:54 +00:00
|
|
|
line = sci_get_line_from_position(doc->editor->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). */
|
2008-07-14 11:13:54 +00:00
|
|
|
if (pos <= sci_get_length(doc->editor->sci))
|
|
|
|
col = sci_get_col_from_position(doc->editor->sci, pos);
|
2006-10-28 16:25:17 +00:00
|
|
|
else
|
|
|
|
col = 0;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2013-04-14 17:08:09 -07:00
|
|
|
stats_str = create_statusbar_statistics(doc, line, col, pos);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* can be overridden by status messages */
|
2013-04-14 17:08:09 -07:00
|
|
|
set_statusbar(stats_str, TRUE);
|
|
|
|
g_free(stats_str);
|
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. */
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_set_window_title(GeanyDocument *doc)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2007-05-28 15:24:21 +00:00
|
|
|
GString *str;
|
|
|
|
GeanyProject *project = app->project;
|
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
doc = document_get_current();
|
2007-05-28 15:24:21 +00:00
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc != NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
g_string_append(str, doc->changed ? "*" : "");
|
2007-05-28 15:24:21 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc->file_name == NULL)
|
2008-06-15 13:35:48 +00:00
|
|
|
g_string_append(str, DOC_FILENAME(doc));
|
2007-02-01 17:07:52 +00:00
|
|
|
else
|
|
|
|
{
|
2009-04-21 20:53:23 +00:00
|
|
|
gchar *short_name = document_get_basename_for_display(doc, 30);
|
2008-06-15 13:35:48 +00:00
|
|
|
gchar *dirname = g_path_get_dirname(DOC_FILENAME(doc));
|
2007-02-01 17:07:52 +00:00
|
|
|
|
2009-04-21 20:53:23 +00:00
|
|
|
g_string_append(str, short_name);
|
2007-05-28 15:24:21 +00:00
|
|
|
g_string_append(str, " - ");
|
|
|
|
g_string_append(str, dirname ? dirname : "");
|
2009-04-21 20:53:23 +00:00
|
|
|
g_free(short_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");
|
2010-06-17 12:35:17 +00:00
|
|
|
if (cl_options.new_instance)
|
|
|
|
{
|
|
|
|
g_string_append(str, _(" (new instance)"));
|
|
|
|
}
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_window_set_title(GTK_WINDOW(main_widgets.window), str->str);
|
2007-05-28 15:24:21 +00:00
|
|
|
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;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_if_fail(font_name != NULL);
|
2008-07-11 17:09:01 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* do nothing if font has not changed */
|
2008-05-16 12:08:39 +00:00
|
|
|
if (interface_prefs.editor_font != NULL)
|
2009-04-05 21:07:40 +00:00
|
|
|
if (strcmp(font_name, interface_prefs.editor_font) == 0)
|
|
|
|
return;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
g_free(interface_prefs.editor_font);
|
|
|
|
interface_prefs.editor_font = g_strdup(font_name);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
/* We copy the current style, and update the font in all open tabs. */
|
2008-07-11 17:09:01 +00:00
|
|
|
for (i = 0; i < documents_array->len; i++)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-07-11 14:11:53 +00:00
|
|
|
if (documents[i]->editor)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-07-11 17:09:01 +00:00
|
|
|
editor_set_font(documents[i]->editor, interface_prefs.editor_font);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Font updated (%s)."), interface_prefs.editor_font);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_window_fullscreen(GTK_WINDOW(main_widgets.window));
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(main_widgets.window));
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_popup_reundo_items(GeanyDocument *doc)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable_undo;
|
|
|
|
gboolean enable_redo;
|
2008-12-06 11:10:06 +00:00
|
|
|
guint i, len;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc == NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
enable_undo = FALSE;
|
|
|
|
enable_redo = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
enable_undo = document_can_undo(doc);
|
|
|
|
enable_redo = document_can_redo(doc);
|
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 */
|
2008-12-06 11:10:06 +00:00
|
|
|
len = G_N_ELEMENTS(widgets.undo_items);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
ui_widget_set_sensitive(widgets.undo_items[i], enable_undo);
|
|
|
|
}
|
|
|
|
len = G_N_ELEMENTS(widgets.redo_items);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
2009-05-28 20:22:12 +00:00
|
|
|
ui_widget_set_sensitive(widgets.redo_items[i], enable_redo);
|
2008-12-06 11:10:06 +00:00
|
|
|
}
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_popup_copy_items(GeanyDocument *doc)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable;
|
2008-12-06 11:10:06 +00:00
|
|
|
guint i, len;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
enable = FALSE;
|
|
|
|
else
|
2008-09-17 18:02:55 +00:00
|
|
|
enable = sci_has_selection(doc->editor->sci);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
len = G_N_ELEMENTS(widgets.popup_copy_items);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
ui_widget_set_sensitive(widgets.popup_copy_items[i], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_update_popup_goto_items(gboolean enable)
|
|
|
|
{
|
2008-12-06 11:10:06 +00:00
|
|
|
guint i, len;
|
|
|
|
len = G_N_ELEMENTS(widgets.popup_goto_items);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
ui_widget_set_sensitive(widgets.popup_goto_items[i], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_menu_copy_items(GeanyDocument *doc)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable = FALSE;
|
2008-12-06 11:10:06 +00:00
|
|
|
guint i, len;
|
2008-05-22 14:41:28 +00:00
|
|
|
GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
if (IS_SCINTILLA(focusw))
|
2008-09-17 18:02:55 +00:00
|
|
|
enable = (doc == NULL) ? FALSE : sci_has_selection(doc->editor->sci);
|
2006-09-05 14:24:47 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
len = G_N_ELEMENTS(widgets.menu_copy_items);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
ui_widget_set_sensitive(widgets.menu_copy_items[i], enable);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_insert_include_item(GeanyDocument *doc, gint item)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
gboolean enable = FALSE;
|
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc == NULL || doc->file_type == NULL)
|
2008-06-15 13:35:48 +00:00
|
|
|
enable = FALSE;
|
2009-04-15 22:47:33 +00:00
|
|
|
else if (doc->file_type->id == GEANY_FILETYPES_C || doc->file_type->id == GEANY_FILETYPES_CPP)
|
2006-09-05 14:24:47 +00:00
|
|
|
enable = TRUE;
|
2009-04-15 22:47:33 +00:00
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
ui_widget_set_sensitive(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
|
|
|
{
|
2008-12-18 21:21:53 +00:00
|
|
|
ui_widget_show_hide(ui_lookup_widget(main_widgets.window, "menu_fold_all1"), editor_prefs.folding);
|
|
|
|
ui_widget_show_hide(ui_lookup_widget(main_widgets.window, "menu_unfold_all1"), editor_prefs.folding);
|
|
|
|
ui_widget_show_hide(ui_lookup_widget(main_widgets.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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(tmp_menu, "activate",
|
2006-12-17 19:31:32 +00:00
|
|
|
G_CALLBACK(on_menu_insert_include_activate), (gpointer) includes[i]);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(tmp_popup, "activate",
|
2006-12-17 19:31:32 +00:00
|
|
|
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
|
|
|
{
|
2008-12-18 21:21:53 +00:00
|
|
|
GtkMenu *menu_edit = GTK_MENU(ui_lookup_widget(main_widgets.window, "insert_include2_menu"));
|
|
|
|
GtkMenu *menu_popup = GTK_MENU(ui_lookup_widget(main_widgets.editor_menu, "insert_include1_menu"));
|
2006-09-05 14:24:47 +00:00
|
|
|
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[] = {
|
2014-02-27 14:33:45 +01:00
|
|
|
"bitset", "deque", "list", "map", "set", "queue", "stack", "vector", "algorithm",
|
2006-09-05 14:24:47 +00:00
|
|
|
"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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(blank, "activate", G_CALLBACK(on_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_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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(item, "activate", G_CALLBACK(on_insert_date_activate), label);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_create_insert_date_menu_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-12-18 21:21:53 +00:00
|
|
|
GtkMenu *menu_edit = GTK_MENU(ui_lookup_widget(main_widgets.window, "insert_date1_menu"));
|
|
|
|
GtkMenu *menu_popup = GTK_MENU(ui_lookup_widget(main_widgets.editor_menu, "insert_date2_menu"));
|
2006-09-05 14:24:47 +00:00
|
|
|
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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(item, "activate", G_CALLBACK(on_menu_insert_date_activate), str);
|
2010-06-23 16:57:28 +00:00
|
|
|
ui_hookup_widget(main_widgets.window, item, "insert_date_custom1");
|
2006-09-05 14:24:47 +00:00
|
|
|
|
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);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(item, "activate", G_CALLBACK(on_insert_date_activate), str);
|
2010-06-23 16:57:28 +00:00
|
|
|
ui_hookup_widget(main_widgets.editor_menu, item, "insert_date_custom2");
|
2006-09-05 14:24:47 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-01-28 17:01:32 +00:00
|
|
|
if (ui_prefs.allow_always_save)
|
2011-11-02 00:04:35 +01:00
|
|
|
enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
|
2009-01-28 17:01:32 +00:00
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
ui_widget_set_sensitive(widgets.save_buttons[0], enable);
|
|
|
|
ui_widget_set_sensitive(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-05-29 17:00:54 +00:00
|
|
|
for (i = 0; i < documents_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-06-18 14:18:26 +00:00
|
|
|
if (documents[i]->is_valid && documents[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-12-06 11:10:06 +00:00
|
|
|
ui_widget_set_sensitive(widgets.save_buttons[2], dirty_tabs);
|
|
|
|
ui_widget_set_sensitive(widgets.save_buttons[3], dirty_tabs);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-30 11:49:39 +00:00
|
|
|
#define add_doc_widget(widget_name) \
|
2008-12-18 21:21:53 +00:00
|
|
|
g_ptr_array_add(widgets.document_buttons, ui_lookup_widget(main_widgets.window, widget_name))
|
2008-06-30 11:49:39 +00:00
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
#define add_doc_toolitem(widget_name) \
|
2009-06-20 16:51:32 +00:00
|
|
|
g_ptr_array_add(widgets.document_buttons, toolbar_get_action_by_name(widget_name))
|
2008-12-06 11:10:06 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void init_document_widgets(void)
|
2007-07-20 12:06:51 +00:00
|
|
|
{
|
2008-06-30 15:15:02 +00:00
|
|
|
widgets.document_buttons = g_ptr_array_new();
|
2008-06-30 11:49:39 +00:00
|
|
|
|
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(). */
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("menu_close1");
|
|
|
|
add_doc_widget("close_other_documents1");
|
|
|
|
add_doc_widget("menu_change_font1");
|
|
|
|
add_doc_widget("menu_close_all1");
|
2009-01-28 17:01:32 +00:00
|
|
|
add_doc_widget("menu_save1");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("menu_save_all1");
|
|
|
|
add_doc_widget("menu_save_as1");
|
|
|
|
add_doc_widget("menu_count_words1");
|
|
|
|
add_doc_widget("menu_build1");
|
|
|
|
add_doc_widget("add_comments1");
|
|
|
|
add_doc_widget("menu_paste1");
|
|
|
|
add_doc_widget("menu_undo2");
|
|
|
|
add_doc_widget("preferences2");
|
|
|
|
add_doc_widget("menu_reload1");
|
|
|
|
add_doc_widget("menu_document1");
|
|
|
|
add_doc_widget("menu_choose_color1");
|
2013-04-27 11:42:04 -07:00
|
|
|
add_doc_widget("menu_color_schemes");
|
|
|
|
add_doc_widget("menu_markers_margin1");
|
|
|
|
add_doc_widget("menu_linenumber_margin1");
|
|
|
|
add_doc_widget("menu_show_white_space1");
|
|
|
|
add_doc_widget("menu_show_line_endings1");
|
|
|
|
add_doc_widget("menu_show_indentation_guides1");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("menu_zoom_in1");
|
|
|
|
add_doc_widget("menu_zoom_out1");
|
|
|
|
add_doc_widget("normal_size1");
|
|
|
|
add_doc_widget("treeview6");
|
|
|
|
add_doc_widget("print1");
|
|
|
|
add_doc_widget("menu_reload_as1");
|
|
|
|
add_doc_widget("menu_select_all1");
|
|
|
|
add_doc_widget("insert_date1");
|
2011-09-16 21:44:11 +00:00
|
|
|
add_doc_widget("insert_alternative_white_space1");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("menu_format1");
|
2009-10-28 11:06:31 +00:00
|
|
|
add_doc_widget("commands2");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("menu_open_selected_file1");
|
|
|
|
add_doc_widget("page_setup1");
|
|
|
|
add_doc_widget("find1");
|
|
|
|
add_doc_widget("find_next1");
|
|
|
|
add_doc_widget("find_previous1");
|
2011-09-16 21:44:11 +00:00
|
|
|
add_doc_widget("go_to_next_marker1");
|
|
|
|
add_doc_widget("go_to_previous_marker1");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("replace1");
|
|
|
|
add_doc_widget("find_nextsel1");
|
|
|
|
add_doc_widget("find_prevsel1");
|
2010-09-09 11:58:55 +00:00
|
|
|
add_doc_widget("find_usage1");
|
|
|
|
add_doc_widget("find_document_usage1");
|
2011-09-16 21:44:11 +00:00
|
|
|
add_doc_widget("mark_all1");
|
2008-06-30 11:49:39 +00:00
|
|
|
add_doc_widget("go_to_line1");
|
2010-09-09 11:58:55 +00:00
|
|
|
add_doc_widget("goto_tag_definition1");
|
|
|
|
add_doc_widget("goto_tag_declaration1");
|
2011-09-16 21:44:11 +00:00
|
|
|
add_doc_widget("reset_indentation1");
|
2008-12-06 11:10:06 +00:00
|
|
|
add_doc_toolitem("Close");
|
2008-12-09 20:31:38 +00:00
|
|
|
add_doc_toolitem("CloseAll");
|
2008-12-06 11:10:06 +00:00
|
|
|
add_doc_toolitem("Search");
|
|
|
|
add_doc_toolitem("SearchEntry");
|
|
|
|
add_doc_toolitem("ZoomIn");
|
|
|
|
add_doc_toolitem("ZoomOut");
|
|
|
|
add_doc_toolitem("Indent");
|
|
|
|
add_doc_toolitem("UnIndent");
|
|
|
|
add_doc_toolitem("Cut");
|
|
|
|
add_doc_toolitem("Copy");
|
|
|
|
add_doc_toolitem("Paste");
|
|
|
|
add_doc_toolitem("Delete");
|
2009-01-28 17:01:32 +00:00
|
|
|
add_doc_toolitem("Save");
|
2011-01-10 13:35:29 +00:00
|
|
|
add_doc_toolitem("SaveAs");
|
2008-12-06 11:10:06 +00:00
|
|
|
add_doc_toolitem("SaveAll");
|
|
|
|
add_doc_toolitem("Compile");
|
|
|
|
add_doc_toolitem("Run");
|
|
|
|
add_doc_toolitem("Reload");
|
|
|
|
add_doc_toolitem("Color");
|
|
|
|
add_doc_toolitem("Goto");
|
|
|
|
add_doc_toolitem("GotoEntry");
|
2010-05-22 19:39:14 +00:00
|
|
|
add_doc_toolitem("Replace");
|
|
|
|
add_doc_toolitem("Print");
|
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;
|
2011-11-02 00:04:35 +01:00
|
|
|
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-06-30 11:49:39 +00:00
|
|
|
for (i = 0; i < widgets.document_buttons->len; i++)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = g_ptr_array_index(widgets.document_buttons, i);
|
2009-06-20 16:51:32 +00:00
|
|
|
if (GTK_IS_ACTION(widget))
|
|
|
|
gtk_action_set_sensitive(GTK_ACTION(widget), enable);
|
|
|
|
else
|
|
|
|
ui_widget_set_sensitive(widget, enable);
|
2008-06-30 11:49:39 +00:00
|
|
|
}
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-14 14:49:41 +00:00
|
|
|
static void on_doc_sensitive_widget_destroy(GtkWidget *widget, G_GNUC_UNUSED gpointer user_data)
|
|
|
|
{
|
|
|
|
g_ptr_array_remove_fast(widgets.document_buttons, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Adds a widget to the list of widgets that should be set sensitive/insensitive
|
2008-10-14 14:49:41 +00:00
|
|
|
* when some documents are present/no documents are open.
|
|
|
|
* It will be removed when the widget is destroyed.
|
2009-01-30 18:53:23 +00:00
|
|
|
* @param widget The widget to add.
|
|
|
|
*
|
|
|
|
* @since 0.15
|
|
|
|
**/
|
2008-10-14 14:49:41 +00:00
|
|
|
void ui_add_document_sensitive(GtkWidget *widget)
|
|
|
|
{
|
2011-11-02 00:04:35 +01:00
|
|
|
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0;
|
2008-10-15 12:19:24 +00:00
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
ui_widget_set_sensitive(widget, enable);
|
2008-10-15 12:19:24 +00:00
|
|
|
|
2008-10-14 14:49:41 +00:00
|
|
|
g_ptr_array_add(widgets.document_buttons, widget);
|
|
|
|
g_signal_connect(widget, "destroy", G_CALLBACK(on_doc_sensitive_widget_destroy), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-05-16 12:08:39 +00:00
|
|
|
if (! interface_prefs.sidebar_openfiles_visible && ! interface_prefs.sidebar_symbol_visible &&
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.sidebar_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
|
|
|
}
|
|
|
|
|
2008-12-18 21:21:53 +00:00
|
|
|
widget = ui_lookup_widget(main_widgets.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
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
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);
|
2008-05-22 14:41:28 +00:00
|
|
|
ignore_callback = FALSE;
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
ui_widget_show_hide(main_widgets.sidebar_notebook, ui_prefs.sidebar_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
ui_widget_show_hide(gtk_notebook_get_nth_page(
|
2009-04-27 19:30:29 +00:00
|
|
|
GTK_NOTEBOOK(main_widgets.sidebar_notebook), 0), interface_prefs.sidebar_symbol_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
ui_widget_show_hide(gtk_notebook_get_nth_page(
|
2009-04-27 19:30:29 +00:00
|
|
|
GTK_NOTEBOOK(main_widgets.sidebar_notebook), 1), interface_prefs.sidebar_openfiles_visible);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_document_show_hide(GeanyDocument *doc)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2010-04-25 17:43:39 +00:00
|
|
|
const gchar *widget_name;
|
2007-10-17 12:27:07 +00:00
|
|
|
GtkWidget *item;
|
2008-08-04 14:07:49 +00:00
|
|
|
const GeanyIndentPrefs *iprefs;
|
2007-03-08 18:02:08 +00:00
|
|
|
|
2014-01-18 15:12:22 +01:00
|
|
|
g_return_if_fail(doc == NULL || doc->is_valid);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
doc = document_get_current();
|
2007-03-08 18:02:08 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (doc == NULL)
|
2007-03-08 18:02:08 +00:00
|
|
|
return;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
ignore_callback = TRUE;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
|
|
|
gtk_check_menu_item_set_active(
|
2008-12-18 21:21:53 +00:00
|
|
|
GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_line_wrapping1")),
|
2008-07-08 16:30:37 +00:00
|
|
|
doc->editor->line_wrapping);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-05-09 12:13:29 +00:00
|
|
|
gtk_check_menu_item_set_active(
|
2008-12-18 21:21:53 +00:00
|
|
|
GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "line_breaking1")),
|
2008-07-08 16:30:37 +00:00
|
|
|
doc->editor->line_breaking);
|
2008-05-09 12:13:29 +00:00
|
|
|
|
2008-08-04 14:07:49 +00:00
|
|
|
iprefs = editor_get_indent_prefs(doc->editor);
|
|
|
|
|
2008-12-18 21:21:53 +00:00
|
|
|
item = ui_lookup_widget(main_widgets.window, "menu_use_auto_indentation1");
|
2008-07-08 16:30:37 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->editor->auto_indent);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-08-04 14:07:49 +00:00
|
|
|
switch (iprefs->type)
|
|
|
|
{
|
|
|
|
case GEANY_INDENT_TYPE_SPACES:
|
|
|
|
widget_name = "spaces1"; break;
|
|
|
|
case GEANY_INDENT_TYPE_TABS:
|
|
|
|
widget_name = "tabs1"; break;
|
|
|
|
case GEANY_INDENT_TYPE_BOTH:
|
2008-08-17 14:20:30 +00:00
|
|
|
default:
|
2008-08-04 14:07:49 +00:00
|
|
|
widget_name = "tabs_and_spaces1"; break;
|
|
|
|
}
|
2008-12-18 21:21:53 +00:00
|
|
|
item = ui_lookup_widget(main_widgets.window, widget_name);
|
2007-10-17 12:27:07 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
|
|
|
|
|
2010-09-14 15:01:29 +00:00
|
|
|
if (iprefs->width >= 1 && iprefs->width <= 8)
|
|
|
|
{
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf("indent_width_%d", iprefs->width);
|
|
|
|
item = ui_lookup_widget(main_widgets.window, name);
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
|
2006-09-05 14:24:47 +00:00
|
|
|
gtk_check_menu_item_set_active(
|
2008-12-18 21:21:53 +00:00
|
|
|
GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "set_file_readonly1")),
|
2008-06-15 13:35:48 +00:00
|
|
|
doc->readonly);
|
2007-10-17 12:27:07 +00:00
|
|
|
|
2008-12-18 21:21:53 +00:00
|
|
|
item = ui_lookup_widget(main_widgets.window, "menu_write_unicode_bom1");
|
2008-06-15 13:35:48 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->has_bom);
|
2008-12-06 11:10:06 +00:00
|
|
|
ui_widget_set_sensitive(item, encodings_is_unicode_charset(doc->encoding));
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-07-14 11:13:54 +00:00
|
|
|
switch (sci_get_eol_mode(doc->editor->sci))
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
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(
|
2008-12-18 21:21:53 +00:00
|
|
|
GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, widget_name)), TRUE);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
encodings_select_radio_item(doc->encoding);
|
|
|
|
filetypes_select_radio_item(doc->file_type);
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
ignore_callback = FALSE;
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 14:05:50 +00:00
|
|
|
void ui_set_search_entry_background(GtkWidget *widget, gboolean success)
|
|
|
|
{
|
2012-09-29 20:18:19 +02:00
|
|
|
gtk_widget_set_name(widget, success ? NULL : "geany-search-entry-no-match");
|
2009-02-27 14:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static void recent_create_menu(GeanyRecentFiles *grf)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
|
|
|
GtkWidget *tmp;
|
2008-12-06 16:57:52 +00:00
|
|
|
guint i, len;
|
2006-09-09 14:36:15 +00:00
|
|
|
gchar *filename;
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
len = MIN(file_prefs.mru_length, g_queue_get_length(grf->recent_queue));
|
2008-12-06 16:57:52 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
filename = g_queue_peek_nth(grf->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);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(grf->menubar), tmp);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2008-12-06 11:10:06 +00:00
|
|
|
/* create menu item for the recent files menu in the toolbar */
|
2009-04-05 14:14:29 +00:00
|
|
|
if (grf->toolbar != NULL)
|
2008-12-06 11:10:06 +00:00
|
|
|
{
|
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(grf->toolbar), tmp);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2008-12-06 11:10:06 +00:00
|
|
|
}
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static GeanyRecentFiles *recent_get_recent_files(void)
|
|
|
|
{
|
2009-04-07 22:09:23 +00:00
|
|
|
static GeanyRecentFiles grf = { RECENT_FILE_FILE, NULL, NULL, NULL, NULL };
|
2009-04-05 14:14:29 +00:00
|
|
|
|
2009-04-05 21:07:40 +00:00
|
|
|
if (G_UNLIKELY(grf.recent_queue == NULL))
|
2009-04-05 14:14:29 +00:00
|
|
|
{
|
|
|
|
grf.recent_queue = ui_prefs.recent_queue;
|
|
|
|
grf.menubar = ui_widgets.recent_files_menu_menubar;
|
2009-06-20 16:51:32 +00:00
|
|
|
grf.toolbar = geany_menu_button_action_get_menu(GEANY_MENU_BUTTON_ACTION(
|
|
|
|
toolbar_get_action_by_name("Open")));
|
2009-04-05 14:14:29 +00:00
|
|
|
grf.activate_cb = recent_file_activate_cb;
|
|
|
|
}
|
|
|
|
return &grf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GeanyRecentFiles *recent_get_recent_projects(void)
|
|
|
|
{
|
2009-04-07 22:09:23 +00:00
|
|
|
static GeanyRecentFiles grf = { RECENT_FILE_PROJECT, NULL, NULL, NULL, NULL };
|
2009-04-05 14:14:29 +00:00
|
|
|
|
2009-04-05 21:07:40 +00:00
|
|
|
if (G_UNLIKELY(grf.recent_queue == NULL))
|
2009-04-05 14:14:29 +00:00
|
|
|
{
|
|
|
|
grf.recent_queue = ui_prefs.recent_projects_queue;
|
|
|
|
grf.menubar = ui_widgets.recent_projects_menu_menubar;
|
|
|
|
grf.toolbar = NULL;
|
|
|
|
grf.activate_cb = recent_project_activate_cb;
|
|
|
|
}
|
|
|
|
return &grf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_create_recent_menus(void)
|
|
|
|
{
|
|
|
|
recent_create_menu(recent_get_recent_files());
|
|
|
|
recent_create_menu(recent_get_recent_projects());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-06 16:57:52 +00:00
|
|
|
static void recent_file_activate_cb(GtkMenuItem *menuitem, 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
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (document_open_file(locale_filename, FALSE, NULL, NULL) != NULL)
|
2009-04-05 14:14:29 +00:00
|
|
|
recent_file_loaded(utf8_filename, recent_get_recent_files());
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static void recent_project_activate_cb(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
gchar *utf8_filename = ui_menu_item_get_text(menuitem);
|
|
|
|
gchar *locale_filename = utils_get_locale_from_utf8(utf8_filename);
|
|
|
|
|
|
|
|
if (project_ask_close() && project_load_file_with_session(locale_filename))
|
|
|
|
recent_file_loaded(utf8_filename, recent_get_recent_projects());
|
|
|
|
|
|
|
|
g_free(locale_filename);
|
|
|
|
g_free(utf8_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-03 20:45:52 +01:00
|
|
|
static void add_recent_file(const gchar *utf8_filename, GeanyRecentFiles *grf,
|
|
|
|
const GtkRecentData *rdata)
|
2009-04-05 14:14:29 +00:00
|
|
|
{
|
|
|
|
if (g_queue_find_custom(grf->recent_queue, utf8_filename, (GCompareFunc) strcmp) == NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2011-10-28 10:25:58 -07:00
|
|
|
|
2011-11-03 20:45:52 +01:00
|
|
|
if (grf->type == RECENT_FILE_FILE && rdata)
|
2007-10-13 10:41:38 +00:00
|
|
|
{
|
2009-04-07 22:09:23 +00:00
|
|
|
GtkRecentManager *manager = gtk_recent_manager_get_default();
|
|
|
|
gchar *uri = g_filename_to_uri(utf8_filename, NULL, NULL);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (uri != NULL)
|
2009-04-07 22:09:23 +00:00
|
|
|
{
|
2011-11-03 20:45:52 +01:00
|
|
|
gtk_recent_manager_add_full(manager, uri, rdata);
|
2009-04-07 22:09:23 +00:00
|
|
|
g_free(uri);
|
|
|
|
}
|
2007-10-13 10:41:38 +00:00
|
|
|
}
|
2011-10-28 10:25:58 -07:00
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
g_queue_push_head(grf->recent_queue, g_strdup(utf8_filename));
|
|
|
|
if (g_queue_get_length(grf->recent_queue) > file_prefs.mru_length)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
g_free(g_queue_pop_tail(grf->recent_queue));
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2009-04-05 14:14:29 +00:00
|
|
|
update_recent_menu(grf);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2009-04-05 14:14:29 +00:00
|
|
|
/* filename already in recent list */
|
|
|
|
else
|
|
|
|
recent_file_loaded(utf8_filename, grf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-03 20:45:52 +01:00
|
|
|
void ui_add_recent_document(GeanyDocument *doc)
|
2009-04-05 14:14:29 +00:00
|
|
|
{
|
2011-11-03 20:45:52 +01:00
|
|
|
/* what are the groups for actually? */
|
|
|
|
static const gchar *groups[2] = {
|
|
|
|
"geany",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
GtkRecentData rdata;
|
|
|
|
|
|
|
|
/* Prepare the data for gtk_recent_manager_add_full() */
|
|
|
|
rdata.display_name = NULL;
|
|
|
|
rdata.description = NULL;
|
|
|
|
rdata.mime_type = doc->file_type->mime_type;
|
|
|
|
/* if we ain't got no mime-type, fallback to plain text */
|
|
|
|
if (! rdata.mime_type)
|
|
|
|
rdata.mime_type = (gchar *) "text/plain";
|
|
|
|
rdata.app_name = (gchar *) "geany";
|
|
|
|
rdata.app_exec = (gchar *) "geany %u";
|
|
|
|
rdata.groups = (gchar **) groups;
|
|
|
|
rdata.is_private = FALSE;
|
|
|
|
|
|
|
|
add_recent_file(doc->file_name, recent_get_recent_files(), &rdata);
|
2009-04-05 14:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ui_add_recent_project_file(const gchar *utf8_filename)
|
|
|
|
{
|
2011-11-03 20:45:52 +01:00
|
|
|
add_recent_file(utf8_filename, recent_get_recent_projects(), NULL);
|
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;
|
|
|
|
|
2011-10-11 21:30:28 -07:00
|
|
|
if (gtk_bin_get_child(GTK_BIN(menu_item)))
|
2006-09-17 21:53:47 +00:00
|
|
|
{
|
2011-10-11 21:30:28 -07:00
|
|
|
GtkWidget *child = gtk_bin_get_child(GTK_BIN(menu_item));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static void recent_file_loaded(const gchar *utf8_filename, GeanyRecentFiles *grf)
|
2006-09-09 14:36:15 +00:00
|
|
|
{
|
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 */
|
2009-04-05 14:14:29 +00:00
|
|
|
item = g_queue_find_custom(grf->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;
|
2009-04-05 14:14:29 +00:00
|
|
|
g_queue_remove(grf->recent_queue, data);
|
|
|
|
g_queue_push_head(grf->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 */
|
2009-04-05 14:14:29 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(grf->menubar));
|
2006-12-01 18:44:35 +00:00
|
|
|
item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
|
2008-12-06 11:10:06 +00:00
|
|
|
if (item != NULL)
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(item->data));
|
2009-10-12 16:31:38 +00:00
|
|
|
g_list_free(children);
|
2006-09-17 21:53:47 +00:00
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
if (grf->toolbar != NULL)
|
2008-12-06 11:10:06 +00:00
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(grf->toolbar));
|
2008-12-06 11:10:06 +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));
|
2009-10-12 16:31:38 +00:00
|
|
|
g_list_free(children);
|
2008-12-06 11:10:06 +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);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(grf->menubar), tmp);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* then for the recent files menu in the tool bar */
|
2009-04-05 14:14:29 +00:00
|
|
|
if (grf->toolbar != NULL)
|
2008-12-06 11:10:06 +00:00
|
|
|
{
|
|
|
|
tmp = gtk_menu_item_new_with_label(utf8_filename);
|
|
|
|
gtk_widget_show(tmp);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(grf->toolbar), tmp);
|
2008-12-06 16:57:52 +00:00
|
|
|
/* this is a bit ugly, but we need to use gtk_container_add(). Using
|
|
|
|
* gtk_menu_shell_prepend() doesn't emit GtkContainer's "add" signal which we need in
|
|
|
|
* GeanyMenubuttonAction */
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_menu_reorder_child(GTK_MENU(grf->toolbar), tmp, 0);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2008-12-06 11:10:06 +00:00
|
|
|
}
|
2006-09-09 14:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
static void update_recent_menu(GeanyRecentFiles *grf)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
|
|
|
GtkWidget *tmp;
|
|
|
|
gchar *filename;
|
2006-12-01 18:44:35 +00:00
|
|
|
GList *children, *item;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2009-04-05 14:14:29 +00:00
|
|
|
filename = g_queue_peek_head(grf->recent_queue);
|
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) */
|
2009-04-05 14:14:29 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(grf->menubar));
|
2008-05-16 12:08:39 +00:00
|
|
|
if (g_list_length(children) > file_prefs.mru_length - 1)
|
2006-12-01 18:44:35 +00:00
|
|
|
{
|
2008-05-16 12:08:39 +00:00
|
|
|
item = g_list_nth(children, file_prefs.mru_length - 1);
|
2006-12-01 18:44:35 +00:00
|
|
|
while (item != NULL)
|
|
|
|
{
|
2008-12-06 11:10:06 +00:00
|
|
|
if (GTK_IS_MENU_ITEM(item->data))
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(item->data));
|
2006-12-01 18:44:35 +00:00
|
|
|
item = g_list_next(item);
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 16:31:38 +00:00
|
|
|
g_list_free(children);
|
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
/* create item for the menu bar menu */
|
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(grf->menubar), tmp);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2006-12-01 18:44:35 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* clean the MRU list before adding an item (toolbar) */
|
2009-04-05 14:14:29 +00:00
|
|
|
if (grf->toolbar != NULL)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2009-04-05 14:14:29 +00:00
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(grf->toolbar));
|
2008-12-06 11:10:06 +00:00
|
|
|
if (g_list_length(children) > file_prefs.mru_length - 1)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-12-06 11:10:06 +00:00
|
|
|
item = g_list_nth(children, file_prefs.mru_length - 1);
|
|
|
|
while (item != NULL)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM(item->data))
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(item->data));
|
|
|
|
item = g_list_next(item);
|
|
|
|
}
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
2009-10-12 16:31:38 +00:00
|
|
|
g_list_free(children);
|
|
|
|
|
2008-12-06 11:10:06 +00:00
|
|
|
/* create item for the tool bar menu */
|
|
|
|
tmp = gtk_menu_item_new_with_label(filename);
|
|
|
|
gtk_widget_show(tmp);
|
2009-04-05 14:14:29 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(grf->toolbar), tmp);
|
|
|
|
gtk_menu_reorder_child(GTK_MENU(grf->toolbar), tmp, 0);
|
|
|
|
g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-07 19:12:08 +00:00
|
|
|
void ui_toggle_editor_features(GeanyUIEditorFeatures feature)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2011-10-30 22:52:29 +01:00
|
|
|
guint i;
|
2006-09-05 14:24:47 +00:00
|
|
|
|
2011-10-30 22:52:29 +01:00
|
|
|
foreach_document (i)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2011-10-30 22:52:29 +01:00
|
|
|
GeanyDocument *doc = documents[i];
|
2008-12-07 19:12:08 +00:00
|
|
|
|
|
|
|
switch (feature)
|
|
|
|
{
|
|
|
|
case GEANY_EDITOR_SHOW_MARKERS_MARGIN:
|
|
|
|
sci_set_symbol_margin(doc->editor->sci, editor_prefs.show_markers_margin);
|
|
|
|
break;
|
|
|
|
case GEANY_EDITOR_SHOW_LINE_NUMBERS:
|
|
|
|
sci_set_line_numbers(doc->editor->sci, editor_prefs.show_linenumber_margin, 0);
|
|
|
|
break;
|
|
|
|
case GEANY_EDITOR_SHOW_WHITE_SPACE:
|
|
|
|
sci_set_visible_white_spaces(doc->editor->sci, editor_prefs.show_white_space);
|
|
|
|
break;
|
|
|
|
case GEANY_EDITOR_SHOW_LINE_ENDINGS:
|
|
|
|
sci_set_visible_eols(doc->editor->sci, editor_prefs.show_line_endings);
|
|
|
|
break;
|
|
|
|
case GEANY_EDITOR_SHOW_INDENTATION_GUIDES:
|
|
|
|
editor_set_indentation_guides(doc->editor);
|
|
|
|
break;
|
|
|
|
}
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-07 19:12:08 +00:00
|
|
|
void ui_update_view_editor_menu_items(void)
|
2006-09-05 14:24:47 +00:00
|
|
|
{
|
2008-12-07 19:12:08 +00:00
|
|
|
ignore_callback = TRUE;
|
2008-12-18 21:21:53 +00:00
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_markers_margin1")), editor_prefs.show_markers_margin);
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_linenumber_margin1")), editor_prefs.show_linenumber_margin);
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_white_space1")), editor_prefs.show_white_space);
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_line_endings1")), editor_prefs.show_line_endings);
|
|
|
|
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "menu_show_indentation_guides1")), editor_prefs.show_indent_guide);
|
2008-12-07 19:12:08 +00:00
|
|
|
ignore_callback = FALSE;
|
2006-09-05 14:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-24 12:01:30 +00:00
|
|
|
/** Creates a GNOME HIG-style frame (with no border and indented child alignment).
|
|
|
|
* @param label_text The label text.
|
|
|
|
* @param alignment An address to store the alignment widget pointer.
|
|
|
|
* @return The frame widget, setting the alignment container for packing child widgets. */
|
2006-11-24 11:11:06 +00:00
|
|
|
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment)
|
2006-09-15 14:25:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label, *align;
|
2009-09-21 16:21:03 +00:00
|
|
|
GtkWidget *frame = gtk_frame_new(NULL);
|
2006-09-15 14:25:42 +00:00
|
|
|
|
2009-09-21 16:21:03 +00:00
|
|
|
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
|
2006-09-15 14:25:42 +00:00
|
|
|
|
2009-09-21 16:21:03 +00:00
|
|
|
align = gtk_alignment_new(0.5, 0.5, 1, 1);
|
|
|
|
gtk_container_add(GTK_CONTAINER(frame), align);
|
|
|
|
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 0, 12, 0);
|
2006-09-15 14:25:42 +00:00
|
|
|
|
2009-09-21 16:21:03 +00:00
|
|
|
label = ui_label_new_bold(label_text);
|
|
|
|
gtk_frame_set_label_widget(GTK_FRAME(frame), label);
|
2006-09-15 14:25:42 +00:00
|
|
|
|
2006-11-24 11:11:06 +00:00
|
|
|
*alignment = align;
|
|
|
|
return frame;
|
2006-09-15 14:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Makes a fixed border for dialogs without increasing the button box border.
|
2008-07-24 12:01:30 +00:00
|
|
|
* @param dialog The parent container for the @c GtkVBox.
|
|
|
|
* @return The packed @c GtkVBox. */
|
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
|
|
|
|
2009-10-21 11:59:33 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
|
2012-09-16 00:18:58 +02:00
|
|
|
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, TRUE, TRUE, 0);
|
2006-10-22 14:56:05 +00:00
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-12 14:26:04 +01:00
|
|
|
static GtkWidget *dialog_get_widget_for_response(GtkDialog *dialog, gint response_id)
|
|
|
|
{
|
|
|
|
#if GTK_CHECK_VERSION(2, 20, 0)
|
|
|
|
return gtk_dialog_get_widget_for_response(dialog, response_id);
|
|
|
|
#else /* GTK < 2.20 */
|
|
|
|
/* base logic stolen from GTK */
|
|
|
|
GtkWidget *action_area = gtk_dialog_get_action_area(dialog);
|
|
|
|
GtkWidget *widget = NULL;
|
|
|
|
GList *children, *node;
|
|
|
|
|
|
|
|
children = gtk_container_get_children(GTK_CONTAINER(action_area));
|
|
|
|
for (node = children; node && ! widget; node = node->next)
|
|
|
|
{
|
|
|
|
if (gtk_dialog_get_response_for_widget(dialog, node->data) == response_id)
|
|
|
|
widget = node->data;
|
|
|
|
}
|
|
|
|
g_list_free(children);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-07 22:09:40 +01:00
|
|
|
/* Reorders a dialog's buttons
|
|
|
|
* @param dialog A dialog
|
|
|
|
* @param response First response ID to reorder
|
|
|
|
* @param ... more response IDs, terminated by -1
|
|
|
|
*
|
|
|
|
* Like gtk_dialog_set_alternative_button_order(), but reorders the default
|
|
|
|
* buttons layout, not the alternative one. This is useful if you e.g. added a
|
|
|
|
* button to a dialog which already had some and need yours not to be on the
|
|
|
|
* end.
|
|
|
|
*/
|
|
|
|
/* Heavily based on gtk_dialog_set_alternative_button_order().
|
|
|
|
* This relies on the action area to be a GtkBox, but although not documented
|
|
|
|
* the API expose it to be a GtkHButtonBox though GtkBuilder, so it should be
|
|
|
|
* fine */
|
|
|
|
void ui_dialog_set_primary_button_order(GtkDialog *dialog, gint response, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
GtkWidget *action_area = gtk_dialog_get_action_area(dialog);
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
va_start(ap, response);
|
|
|
|
for (position = 0; response != -1; position++)
|
|
|
|
{
|
2014-03-12 14:26:04 +01:00
|
|
|
GtkWidget *child = dialog_get_widget_for_response(dialog, response);
|
2014-03-07 22:09:40 +01:00
|
|
|
if (child)
|
|
|
|
gtk_box_reorder_child(GTK_BOX(action_area), child, position);
|
|
|
|
else
|
|
|
|
g_warning("%s: no child button with response id %d.", G_STRFUNC, response);
|
|
|
|
|
|
|
|
response = va_arg(ap, gint);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 11:23:22 +00:00
|
|
|
/** Creates a @c GtkButton with custom text and a stock image similar to
|
2008-07-24 12:01:30 +00:00
|
|
|
* @c gtk_button_new_from_stock().
|
|
|
|
* @param stock_id A @c GTK_STOCK_NAME string.
|
|
|
|
* @param text Button label text, can include mnemonics.
|
|
|
|
* @return The new @c GtkButton.
|
|
|
|
*/
|
2006-11-01 15:26:41 +00:00
|
|
|
GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text)
|
|
|
|
{
|
2010-03-12 11:23:22 +00:00
|
|
|
GtkWidget *image, *button;
|
2006-11-01 15:26:41 +00:00
|
|
|
|
2010-03-12 11:23:22 +00:00
|
|
|
button = gtk_button_new_with_mnemonic(text);
|
|
|
|
gtk_widget_show(button);
|
2006-11-01 15:26:41 +00:00
|
|
|
image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON);
|
2010-03-12 11:23:22 +00:00
|
|
|
gtk_button_set_image(GTK_BUTTON(button), image);
|
|
|
|
/* note: image is shown by gtk */
|
2006-11-01 15:26:41 +00:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Creates a @c GtkImageMenuItem with a stock image and a custom label.
|
2008-11-21 13:34:58 +00:00
|
|
|
* @param stock_id Stock image ID, e.g. @c GTK_STOCK_OPEN.
|
|
|
|
* @param label Menu item label, can include mnemonics.
|
2009-01-30 18:53:23 +00:00
|
|
|
* @return The new @c GtkImageMenuItem.
|
|
|
|
*
|
|
|
|
* @since 0.16
|
|
|
|
*/
|
2008-11-21 13:34:58 +00:00
|
|
|
GtkWidget *
|
|
|
|
ui_image_menu_item_new(const gchar *stock_id, const gchar *label)
|
|
|
|
{
|
|
|
|
GtkWidget *item = gtk_image_menu_item_new_with_mnemonic(label);
|
|
|
|
GtkWidget *image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_MENU);
|
|
|
|
|
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
|
|
|
|
gtk_widget_show(image);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-10 17:44:14 +00:00
|
|
|
static void entry_clear_icon_release_cb(GtkEntry *entry, gint icon_pos,
|
|
|
|
GdkEvent *event, gpointer data)
|
2009-01-27 19:31:45 +00:00
|
|
|
{
|
2009-04-15 22:47:33 +00:00
|
|
|
if (event->button.button == 1 && icon_pos == 1)
|
2009-01-27 19:31:45 +00:00
|
|
|
{
|
|
|
|
gtk_entry_set_text(entry, "");
|
2009-09-17 18:08:21 +00:00
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(entry));
|
2009-01-27 19:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Adds a small clear icon to the right end of the passed @a entry.
|
2009-01-27 19:31:45 +00:00
|
|
|
* A callback to clear the contents of the GtkEntry is automatically added.
|
|
|
|
*
|
|
|
|
* @param entry The GtkEntry object to which the icon should be attached.
|
2009-01-30 18:53:23 +00:00
|
|
|
*
|
|
|
|
* @since 0.16
|
2009-01-27 19:31:45 +00:00
|
|
|
*/
|
2009-09-21 16:46:16 +00:00
|
|
|
void ui_entry_add_clear_icon(GtkEntry *entry)
|
2009-01-27 19:31:45 +00:00
|
|
|
{
|
2012-06-04 14:18:49 -07:00
|
|
|
g_object_set(entry, "secondary-icon-stock", GTK_STOCK_CLEAR,
|
|
|
|
"secondary-icon-activatable", TRUE, NULL);
|
2011-10-28 10:25:58 -07:00
|
|
|
g_signal_connect(entry, "icon-release", G_CALLBACK(entry_clear_icon_release_cb), NULL);
|
2009-01-27 19:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-24 16:51:02 +00:00
|
|
|
/* Adds a :activate-backwards signal emitted by default when <Shift>Return is pressed */
|
|
|
|
void ui_entry_add_activate_backward_signal(GtkEntry *entry)
|
|
|
|
{
|
|
|
|
static gboolean installed = FALSE;
|
|
|
|
|
|
|
|
g_return_if_fail(GTK_IS_ENTRY(entry));
|
|
|
|
|
|
|
|
if (G_UNLIKELY(! installed))
|
|
|
|
{
|
|
|
|
GtkBindingSet *binding_set;
|
|
|
|
|
|
|
|
installed = TRUE;
|
|
|
|
|
|
|
|
/* try to handle the unexpected case where GTK would already have installed the signal */
|
|
|
|
if (g_signal_lookup("activate-backward", G_TYPE_FROM_INSTANCE(entry)))
|
|
|
|
{
|
|
|
|
g_warning("Signal GtkEntry:activate-backward is unexpectedly already installed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_new("activate-backward", G_TYPE_FROM_INSTANCE(entry),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
binding_set = gtk_binding_set_by_class(GTK_ENTRY_GET_CLASS(entry));
|
|
|
|
gtk_binding_entry_add_signal(binding_set, GDK_Return, GDK_SHIFT_MASK, "activate-backward", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-01 15:26:41 +00:00
|
|
|
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;
|
|
|
|
|
2008-10-22 15:36:45 +00:00
|
|
|
gtk_box_set_spacing(GTK_BOX(copy), 10);
|
2006-11-01 15:26:41 +00:00
|
|
|
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
|
|
|
|
2010-06-17 17:28:28 +00:00
|
|
|
static gboolean tree_model_find_text(GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter, gint column, const gchar *text)
|
|
|
|
{
|
|
|
|
gchar *combo_text;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_first(model, iter))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, iter, 0, &combo_text, -1);
|
|
|
|
found = utils_str_equal(combo_text, text);
|
|
|
|
g_free(combo_text);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next(model, iter));
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-18 12:20:15 +00:00
|
|
|
/** Prepends @a text to the drop down list, removing a duplicate element in
|
|
|
|
* the list if found. Also ensures there are <= @a history_len elements.
|
|
|
|
* @param combo_entry .
|
|
|
|
* @param text Text to add, or @c NULL for current entry text.
|
|
|
|
* @param history_len Max number of items, or @c 0 for default. */
|
2012-09-15 23:40:13 +02:00
|
|
|
void ui_combo_box_add_to_history(GtkComboBoxText *combo_entry,
|
2010-06-18 12:20:15 +00:00
|
|
|
const gchar *text, gint history_len)
|
2006-11-15 15:57:23 +00:00
|
|
|
{
|
2010-06-18 12:20:15 +00:00
|
|
|
GtkComboBox *combo = GTK_COMBO_BOX(combo_entry);
|
2006-11-15 15:57:23 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
2010-06-18 12:20:15 +00:00
|
|
|
if (history_len <= 0)
|
|
|
|
history_len = 10;
|
|
|
|
if (!text)
|
2011-10-11 21:30:28 -07:00
|
|
|
text = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo))));
|
2010-06-18 12:20:15 +00:00
|
|
|
|
2006-11-15 15:57:23 +00:00
|
|
|
model = gtk_combo_box_get_model(combo);
|
2010-06-17 17:28:28 +00:00
|
|
|
|
|
|
|
if (tree_model_find_text(model, &iter, 0, text))
|
2006-11-15 15:57:23 +00:00
|
|
|
{
|
2010-06-17 17:28:28 +00:00
|
|
|
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
|
2006-11-15 15:57:23 +00:00
|
|
|
}
|
2012-09-15 23:40:13 +02:00
|
|
|
gtk_combo_box_text_prepend_text(combo_entry, 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
|
|
|
|
2012-09-15 23:40:13 +02:00
|
|
|
/* Same as gtk_combo_box_text_prepend_text(), except that text is only prepended if it not already
|
2008-11-16 17:53:55 +00:00
|
|
|
* exists in the combo's model. */
|
2012-09-15 23:40:13 +02:00
|
|
|
void ui_combo_box_prepend_text_once(GtkComboBoxText *combo, const gchar *text)
|
2008-11-16 17:53:55 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2012-09-15 23:40:13 +02:00
|
|
|
model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
|
2010-07-02 12:19:00 +00:00
|
|
|
if (tree_model_find_text(model, &iter, 0, text))
|
2008-11-16 17:53:55 +00:00
|
|
|
return; /* don't prepend duplicate */
|
|
|
|
|
2012-09-15 23:40:13 +02:00
|
|
|
gtk_combo_box_text_prepend_text(combo, text);
|
2008-11-16 17:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-05 10:37:36 +00:00
|
|
|
/* Changes the color of the notebook tab text and open files items according to
|
|
|
|
* document status. */
|
2008-06-15 13:35:48 +00:00
|
|
|
void ui_update_tab_status(GeanyDocument *doc)
|
2006-12-05 10:37:36 +00:00
|
|
|
{
|
2013-02-11 03:31:05 +01:00
|
|
|
gtk_widget_set_name(doc->priv->tab_label, document_get_status_widget_class(doc));
|
2006-12-05 10:37:36 +00:00
|
|
|
|
2009-09-28 11:16:59 +00:00
|
|
|
sidebar_openfiles_update(doc);
|
2006-12-05 10:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-25 17:38:31 +00:00
|
|
|
static gboolean tree_model_iter_get_next(GtkTreeModel *model, GtkTreeIter *iter,
|
|
|
|
gboolean down)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
if (down)
|
|
|
|
return gtk_tree_model_iter_next(model, iter);
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path(model, iter);
|
|
|
|
result = gtk_tree_path_prev(path) && gtk_tree_model_get_iter(model, iter, path);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* note: the while loop might be more efficient when searching upwards if it
|
|
|
|
* used tree paths instead of tree iters, but in practice it probably doesn't matter much. */
|
|
|
|
static gboolean tree_view_find(GtkTreeView *treeview, TVMatchCallback cb, gboolean down)
|
2006-12-08 15:50:10 +00:00
|
|
|
{
|
|
|
|
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 */
|
2008-06-25 17:38:31 +00:00
|
|
|
if (! tree_model_iter_get_next(model, &iter, down))
|
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);
|
2011-08-13 20:44:39 +00:00
|
|
|
if (cb(FALSE))
|
2008-02-27 13:17:29 +00:00
|
|
|
break; /* found next message */
|
2006-12-08 15:50:10 +00:00
|
|
|
|
2008-06-25 17:38:31 +00:00
|
|
|
if (! tree_model_iter_get_next(model, &iter, down))
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-25 17:38:31 +00:00
|
|
|
/* Returns FALSE if the treeview has items but no matching next item. */
|
|
|
|
gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb)
|
|
|
|
{
|
|
|
|
return tree_view_find(treeview, cb, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns FALSE if the treeview has items but no matching next item. */
|
|
|
|
gboolean ui_tree_view_find_previous(GtkTreeView *treeview, TVMatchCallback cb)
|
|
|
|
{
|
|
|
|
return tree_view_find(treeview, cb, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-25 22:43:15 +00:00
|
|
|
/**
|
|
|
|
* Modifies the font of a widget using gtk_widget_modify_font().
|
|
|
|
*
|
|
|
|
* @param widget The widget.
|
|
|
|
* @param str The font name as expected by pango_font_description_from_string().
|
|
|
|
*/
|
|
|
|
void ui_widget_modify_font_from_string(GtkWidget *widget, const gchar *str)
|
2006-12-13 15:18:49 +00:00
|
|
|
{
|
|
|
|
PangoFontDescription *pfd;
|
|
|
|
|
|
|
|
pfd = pango_font_description_from_string(str);
|
2009-10-25 22:43:15 +00:00
|
|
|
gtk_widget_modify_font(widget, pfd);
|
2006-12-13 15:18:49 +00:00
|
|
|
pango_font_description_free(pfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-24 12:01:30 +00:00
|
|
|
/** Creates a @c GtkHBox with @a entry packed into it and an open button which runs a
|
|
|
|
* file chooser, replacing entry text (if successful) with the path returned from the
|
|
|
|
* @c GtkFileChooser.
|
|
|
|
* @note @a entry can be the child of an unparented widget, such as @c GtkComboBoxEntry.
|
|
|
|
* @param title The file chooser dialog title, or @c NULL.
|
|
|
|
* @param action The mode of the file chooser.
|
|
|
|
* @param entry Can be an unpacked @c GtkEntry, or the child of an unpacked widget,
|
|
|
|
* such as @c GtkComboBoxEntry.
|
|
|
|
* @return The @c GtkHBox.
|
|
|
|
*/
|
|
|
|
/* @see ui_setup_open_button_callback(). */
|
2007-05-11 16:34:18 +00:00
|
|
|
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)
|
2008-07-18 13:40:48 +00:00
|
|
|
g_object_set_data_full(G_OBJECT(open_btn), "title", g_strdup(title),
|
|
|
|
(GDestroyNotify) g_free);
|
2011-10-30 22:52:29 +01:00
|
|
|
g_object_set_data(G_OBJECT(open_btn), "action", GINT_TO_POINTER(action));
|
2014-01-09 17:50:30 +01:00
|
|
|
g_signal_connect(open_btn, "clicked", G_CALLBACK(ui_path_box_open_clicked), path_entry);
|
2007-04-29 12:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2008-05-22 14:41:28 +00:00
|
|
|
GTK_WINDOW(main_widgets.window), action,
|
2007-04-29 12:03:25 +00:00
|
|
|
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);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2007-04-29 12:03:25 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2009-11-17 21:47:06 +00:00
|
|
|
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
|
|
|
{
|
|
|
|
if (g_path_is_absolute(locale_path))
|
|
|
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), locale_path);
|
|
|
|
}
|
2007-04-29 12:03:25 +00:00
|
|
|
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;
|
|
|
|
|
2009-03-16 13:45:12 +00:00
|
|
|
dir_locale = gtk_file_chooser_get_filename(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)
|
|
|
|
{
|
2014-01-09 17:50:30 +01:00
|
|
|
GtkFileChooserAction action = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "action"));
|
|
|
|
GtkEntry *entry = user_data;
|
|
|
|
const gchar *title = g_object_get_data(G_OBJECT(button), "title");
|
2009-11-30 22:58:57 +00:00
|
|
|
gchar *utf8_path = NULL;
|
2007-05-11 16:34:18 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* TODO: extend for other actions */
|
2009-11-17 21:47:06 +00:00
|
|
|
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
|
|
|
|
action == GTK_FILE_CHOOSER_ACTION_OPEN);
|
2007-05-11 16:34:18 +00:00
|
|
|
|
|
|
|
if (title == NULL)
|
|
|
|
title = (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ?
|
|
|
|
_("Select Folder") : _("Select File");
|
|
|
|
|
2009-11-17 21:47:06 +00:00
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
|
|
|
{
|
2007-05-11 16:34:18 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2009-12-20 21:49:23 +00:00
|
|
|
utf8_path = win32_show_file_dialog(GTK_WINDOW(ui_widgets.prefs_dialog), title,
|
2007-05-11 16:34:18 +00:00
|
|
|
gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
|
|
#else
|
2009-11-17 21:47:06 +00:00
|
|
|
utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry)));
|
2007-05-11 16:34:18 +00:00
|
|
|
#endif
|
2009-11-17 21:47:06 +00:00
|
|
|
}
|
|
|
|
else if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
|
|
{
|
|
|
|
gchar *path = g_path_get_dirname(gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
|
|
#ifdef G_OS_WIN32
|
2009-12-20 21:49:23 +00:00
|
|
|
utf8_path = win32_show_folder_dialog(ui_widgets.prefs_dialog, title,
|
|
|
|
gtk_entry_get_text(GTK_ENTRY(entry)));
|
2009-11-17 21:47:06 +00:00
|
|
|
#else
|
|
|
|
utf8_path = run_file_chooser(title, action, path);
|
|
|
|
#endif
|
|
|
|
g_free(path);
|
|
|
|
}
|
2007-05-11 16:34:18 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (utf8_path != NULL)
|
2007-05-11 16:34:18 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_widget_show(ui_widgets.statusbar);
|
2008-06-15 13:35:48 +00:00
|
|
|
ui_update_statusbar(NULL, -1);
|
2007-05-04 16:59:00 +00:00
|
|
|
}
|
|
|
|
else
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_widget_hide(ui_widgets.statusbar);
|
2007-05-04 16:59:00 +00:00
|
|
|
}
|
2007-07-13 15:54:16 +00:00
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Packs all @c GtkWidgets passed after the row argument into a table, using
|
2008-07-24 12:01:30 +00:00
|
|
|
* one widget per cell. The first widget is not expanded as the table grows,
|
|
|
|
* as this is usually a label.
|
|
|
|
* @param table
|
|
|
|
* @param row The row number of the table.
|
|
|
|
*/
|
2007-07-13 15:54:16 +00:00
|
|
|
void ui_table_add_row(GtkTable *table, gint row, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2011-10-30 22:52:29 +01:00
|
|
|
guint i;
|
2007-07-13 15:54:16 +00:00
|
|
|
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-11-26 13:15:53 +00:00
|
|
|
static void on_config_file_clicked(GtkWidget *widget, gpointer user_data)
|
|
|
|
{
|
|
|
|
const gchar *file_name = user_data;
|
2009-06-09 14:39:28 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
|
|
|
|
|
|
|
if (strstr(file_name, G_DIR_SEPARATOR_S "filetypes."))
|
|
|
|
ft = filetypes[GEANY_FILETYPES_CONF];
|
2008-11-26 13:15:53 +00:00
|
|
|
|
|
|
|
if (g_file_test(file_name, G_FILE_TEST_EXISTS))
|
2009-06-09 14:39:28 +00:00
|
|
|
document_open_file(file_name, FALSE, ft, NULL);
|
2008-11-26 13:15:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-07 17:37:00 +00:00
|
|
|
gchar *utf8_filename = utils_get_utf8_from_locale(file_name);
|
2008-12-06 12:28:21 +00:00
|
|
|
gchar *base_name = g_path_get_basename(file_name);
|
|
|
|
gchar *global_file = g_build_filename(app->datadir, base_name, NULL);
|
|
|
|
gchar *global_content = NULL;
|
2008-11-26 13:15:53 +00:00
|
|
|
|
2008-12-06 12:28:21 +00:00
|
|
|
/* if the requested file doesn't exist in the user's config dir, try loading the file
|
|
|
|
* from the global data directory and use its contents for the newly created file */
|
|
|
|
if (g_file_test(global_file, G_FILE_TEST_EXISTS))
|
|
|
|
g_file_get_contents(global_file, &global_content, NULL, NULL);
|
|
|
|
|
2010-03-15 14:05:42 +00:00
|
|
|
document_new_file(utf8_filename, ft, global_content);
|
2010-03-07 17:37:00 +00:00
|
|
|
|
|
|
|
utils_free_pointers(4, utf8_filename, base_name, global_file, global_content, NULL);
|
2008-11-26 13:15:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-16 21:03:06 +02:00
|
|
|
static void free_on_closure_notify(gpointer data, GClosure *closure)
|
|
|
|
{
|
|
|
|
g_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 13:15:53 +00:00
|
|
|
/* @note You should connect to the "document-save" signal yourself to detect
|
|
|
|
* if the user has just saved the config file, reloading it. */
|
2008-12-06 11:10:06 +00:00
|
|
|
void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label, GtkContainer *parent)
|
2008-11-26 13:15:53 +00:00
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
parent = GTK_CONTAINER(widgets.config_files_menu);
|
|
|
|
|
|
|
|
if (!label)
|
|
|
|
{
|
|
|
|
gchar *base_name;
|
|
|
|
|
|
|
|
base_name = g_path_get_basename(real_path);
|
|
|
|
item = gtk_menu_item_new_with_label(base_name);
|
|
|
|
g_free(base_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
item = gtk_menu_item_new_with_mnemonic(label);
|
|
|
|
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(parent, item);
|
2011-10-16 21:03:06 +02:00
|
|
|
g_signal_connect_data(item, "activate", G_CALLBACK(on_config_file_clicked),
|
|
|
|
g_strdup(real_path), free_on_closure_notify, 0);
|
2008-11-26 13:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-08 12:25:47 +00:00
|
|
|
static gboolean sort_menu(gpointer data)
|
|
|
|
{
|
|
|
|
ui_menu_sort_by_label(GTK_MENU(data));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 13:15:53 +00:00
|
|
|
static void create_config_files_menu(void)
|
|
|
|
{
|
|
|
|
GtkWidget *menu, *item;
|
|
|
|
|
|
|
|
widgets.config_files_menu = menu = gtk_menu_new();
|
|
|
|
|
2009-10-14 13:51:43 +00:00
|
|
|
item = ui_lookup_widget(main_widgets.window, "configuration_files1");
|
2008-11-26 13:15:53 +00:00
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
|
2009-04-08 12:25:47 +00:00
|
|
|
|
|
|
|
/* sort menu after all items added */
|
|
|
|
g_idle_add(sort_menu, widgets.config_files_menu);
|
2008-11-26 13:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-10 18:33:04 +01:00
|
|
|
/* adds factory icons with a named icon source using the stock items id */
|
|
|
|
static void add_stock_icons(const GtkStockItem *items, gsize count)
|
|
|
|
{
|
|
|
|
GtkIconFactory *factory = gtk_icon_factory_new();
|
|
|
|
GtkIconSource *source = gtk_icon_source_new();
|
|
|
|
gsize i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
GtkIconSet *set = gtk_icon_set_new();
|
|
|
|
|
|
|
|
gtk_icon_source_set_icon_name(source, items[i].stock_id);
|
|
|
|
gtk_icon_set_add_source(set, source);
|
|
|
|
gtk_icon_factory_add(factory, items[i].stock_id, set);
|
|
|
|
gtk_icon_set_unref(set);
|
|
|
|
}
|
|
|
|
gtk_icon_source_free(source);
|
|
|
|
gtk_icon_factory_add_default(factory);
|
|
|
|
g_object_unref(factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 16:53:28 +00:00
|
|
|
void ui_init_stock_items(void)
|
2008-12-06 11:45:48 +00:00
|
|
|
{
|
2008-12-09 20:31:38 +00:00
|
|
|
GtkStockItem items[] =
|
2008-12-06 11:45:48 +00:00
|
|
|
{
|
2011-06-17 22:52:43 +00:00
|
|
|
{ GEANY_STOCK_SAVE_ALL, N_("Save All"), 0, 0, GETTEXT_PACKAGE },
|
|
|
|
{ GEANY_STOCK_CLOSE_ALL, N_("Close All"), 0, 0, GETTEXT_PACKAGE },
|
|
|
|
{ GEANY_STOCK_BUILD, N_("Build"), 0, 0, GETTEXT_PACKAGE }
|
2008-12-06 11:45:48 +00:00
|
|
|
};
|
|
|
|
|
2014-01-10 18:33:04 +01:00
|
|
|
gtk_stock_add(items, G_N_ELEMENTS(items));
|
|
|
|
add_stock_icons(items, G_N_ELEMENTS(items));
|
2008-12-06 11:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 16:51:32 +00:00
|
|
|
void ui_init_toolbar_widgets(void)
|
|
|
|
{
|
|
|
|
widgets.save_buttons[1] = toolbar_get_widget_by_name("Save");
|
|
|
|
widgets.save_buttons[3] = toolbar_get_widget_by_name("SaveAll");
|
|
|
|
widgets.redo_items[2] = toolbar_get_widget_by_name("Redo");
|
|
|
|
widgets.undo_items[2] = toolbar_get_widget_by_name("Undo");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-23 16:18:05 +00:00
|
|
|
void ui_swap_sidebar_pos(void)
|
|
|
|
{
|
|
|
|
GtkWidget *pane = ui_lookup_widget(main_widgets.window, "hpaned1");
|
|
|
|
GtkWidget *left = gtk_paned_get_child1(GTK_PANED(pane));
|
|
|
|
GtkWidget *right = gtk_paned_get_child2(GTK_PANED(pane));
|
|
|
|
|
2012-04-03 16:09:06 +01:00
|
|
|
g_object_ref(left);
|
|
|
|
g_object_ref(right);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (pane), left);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (pane), right);
|
|
|
|
/* only scintilla notebook should expand */
|
|
|
|
gtk_paned_pack1(GTK_PANED(pane), right, right == main_widgets.notebook, TRUE);
|
|
|
|
gtk_paned_pack2(GTK_PANED(pane), left, left == main_widgets.notebook, TRUE);
|
|
|
|
g_object_unref(left);
|
|
|
|
g_object_unref(right);
|
2009-10-23 16:18:05 +00:00
|
|
|
|
2012-09-15 13:52:49 +02:00
|
|
|
gtk_paned_set_position(GTK_PANED(pane), gtk_widget_get_allocated_width(pane)
|
2009-10-23 16:18:05 +00:00
|
|
|
- gtk_paned_get_position(GTK_PANED(pane)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-20 16:51:32 +00:00
|
|
|
static void init_recent_files(void)
|
|
|
|
{
|
|
|
|
GtkWidget *toolbar_recent_files_menu;
|
|
|
|
|
|
|
|
/* add recent files to the File menu */
|
|
|
|
ui_widgets.recent_files_menuitem = ui_lookup_widget(main_widgets.window, "recent_files1");
|
|
|
|
ui_widgets.recent_files_menu_menubar = gtk_menu_new();
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(ui_widgets.recent_files_menuitem),
|
|
|
|
ui_widgets.recent_files_menu_menubar);
|
|
|
|
|
|
|
|
/* add recent files to the toolbar Open button */
|
|
|
|
toolbar_recent_files_menu = gtk_menu_new();
|
|
|
|
g_object_ref(toolbar_recent_files_menu);
|
|
|
|
geany_menu_button_action_set_menu(GEANY_MENU_BUTTON_ACTION(
|
|
|
|
toolbar_get_action_by_name("Open")), toolbar_recent_files_menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 17:27:24 +00:00
|
|
|
static void ui_menu_move(GtkWidget *menu, GtkWidget *old, GtkWidget *new)
|
|
|
|
{
|
|
|
|
g_object_ref(menu);
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(old), NULL);
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(new), menu);
|
|
|
|
g_object_unref(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 11:36:50 +00:00
|
|
|
typedef struct GeanySharedMenu
|
2009-10-27 17:27:24 +00:00
|
|
|
{
|
2011-03-24 16:52:34 +00:00
|
|
|
const gchar *menu;
|
|
|
|
const gchar *menubar_item;
|
|
|
|
const gchar *popup_item;
|
2010-09-20 11:36:50 +00:00
|
|
|
}
|
|
|
|
GeanySharedMenu;
|
|
|
|
|
|
|
|
#define foreach_menu(item, array) \
|
|
|
|
for (item = array; item->menu; item++)
|
2009-10-27 17:27:24 +00:00
|
|
|
|
2010-09-20 11:36:50 +00:00
|
|
|
static void on_editor_menu_show(GtkWidget *widget, GeanySharedMenu *items)
|
|
|
|
{
|
|
|
|
GeanySharedMenu *item;
|
|
|
|
|
|
|
|
foreach_menu(item, items)
|
|
|
|
{
|
|
|
|
GtkWidget *popup = ui_lookup_widget(main_widgets.editor_menu, item->popup_item);
|
|
|
|
GtkWidget *bar = ui_lookup_widget(main_widgets.window, item->menubar_item);
|
2010-09-20 11:52:07 +00:00
|
|
|
GtkWidget *menu = ui_lookup_widget(main_widgets.window, item->menu);
|
2009-10-27 18:10:39 +00:00
|
|
|
|
2010-09-20 11:52:07 +00:00
|
|
|
ui_menu_move(menu, bar, popup);
|
2010-09-20 11:36:50 +00:00
|
|
|
}
|
2009-10-27 17:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 11:36:50 +00:00
|
|
|
static void on_editor_menu_hide(GtkWidget *widget, GeanySharedMenu *items)
|
2009-10-27 17:27:24 +00:00
|
|
|
{
|
2010-09-20 11:36:50 +00:00
|
|
|
GeanySharedMenu *item;
|
2009-10-27 17:27:24 +00:00
|
|
|
|
2010-09-20 11:36:50 +00:00
|
|
|
foreach_menu(item, items)
|
|
|
|
{
|
|
|
|
GtkWidget *popup = ui_lookup_widget(main_widgets.editor_menu, item->popup_item);
|
|
|
|
GtkWidget *bar = ui_lookup_widget(main_widgets.window, item->menubar_item);
|
2010-09-20 11:52:07 +00:00
|
|
|
GtkWidget *menu = ui_lookup_widget(main_widgets.window, item->menu);
|
2009-10-27 18:10:39 +00:00
|
|
|
|
2010-09-20 11:52:07 +00:00
|
|
|
ui_menu_move(menu, popup, bar);
|
2010-09-20 11:36:50 +00:00
|
|
|
}
|
2009-10-27 17:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-09 17:15:16 +00:00
|
|
|
/* Currently ui_init() is called before keyfile.c stash group code is initialized,
|
|
|
|
* so this is called after that's done. */
|
|
|
|
void ui_init_prefs(void)
|
2010-06-29 12:11:21 +00:00
|
|
|
{
|
2010-07-09 17:15:16 +00:00
|
|
|
StashGroup *group = stash_group_new(PACKAGE);
|
2010-07-08 11:35:32 +00:00
|
|
|
|
2011-07-28 17:59:22 +00:00
|
|
|
/* various prefs */
|
2011-09-22 11:52:58 +00:00
|
|
|
configuration_add_various_pref_group(group);
|
2010-07-08 11:35:32 +00:00
|
|
|
|
2010-08-10 12:49:16 +00:00
|
|
|
stash_group_add_boolean(group, &interface_prefs.show_symbol_list_expanders,
|
|
|
|
"show_symbol_list_expanders", TRUE);
|
|
|
|
stash_group_add_boolean(group, &interface_prefs.compiler_tab_autoscroll,
|
|
|
|
"compiler_tab_autoscroll", TRUE);
|
|
|
|
stash_group_add_boolean(group, &ui_prefs.allow_always_save,
|
|
|
|
"allow_always_save", FALSE);
|
2013-04-14 17:08:09 -07:00
|
|
|
stash_group_add_string(group, &ui_prefs.statusbar_template,
|
|
|
|
"statusbar_template", _(DEFAULT_STATUSBAR_TEMPLATE));
|
2010-09-23 16:24:43 +00:00
|
|
|
stash_group_add_boolean(group, &ui_prefs.new_document_after_close,
|
|
|
|
"new_document_after_close", FALSE);
|
2011-07-28 17:59:22 +00:00
|
|
|
stash_group_add_boolean(group, &interface_prefs.msgwin_status_visible,
|
|
|
|
"msgwin_status_visible", TRUE);
|
|
|
|
stash_group_add_boolean(group, &interface_prefs.msgwin_compiler_visible,
|
|
|
|
"msgwin_compiler_visible", TRUE);
|
|
|
|
stash_group_add_boolean(group, &interface_prefs.msgwin_messages_visible,
|
|
|
|
"msgwin_messages_visible", TRUE);
|
|
|
|
stash_group_add_boolean(group, &interface_prefs.msgwin_scribble_visible,
|
|
|
|
"msgwin_scribble_visible", TRUE);
|
2010-06-29 12:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-24 14:34:05 -07:00
|
|
|
/* Used to find out the name of the GtkBuilder retrieved object since
|
|
|
|
* some objects will be GTK_IS_BUILDABLE() and use the GtkBuildable
|
|
|
|
* 'name' property for that and those that don't implement GtkBuildable
|
|
|
|
* will have a "gtk-builder-name" stored in the GObject's data list. */
|
|
|
|
static const gchar *ui_guess_object_name(GObject *obj)
|
|
|
|
{
|
2011-10-14 13:28:14 +01:00
|
|
|
const gchar *name = NULL;
|
2011-09-24 14:34:05 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail(G_IS_OBJECT(obj), NULL);
|
|
|
|
|
|
|
|
if (GTK_IS_BUILDABLE(obj))
|
|
|
|
name = gtk_buildable_get_name(GTK_BUILDABLE(obj));
|
|
|
|
if (! name)
|
|
|
|
name = g_object_get_data(obj, "gtk-builder-name");
|
|
|
|
if (! name)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
/* Compatibility functions */
|
|
|
|
GtkWidget *create_edit_menu1(void)
|
|
|
|
{
|
|
|
|
return edit_menu1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *create_prefs_dialog(void)
|
|
|
|
{
|
|
|
|
return prefs_dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *create_project_dialog(void)
|
|
|
|
{
|
|
|
|
return project_dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *create_toolbar_popup_menu1(void)
|
|
|
|
{
|
|
|
|
return toolbar_popup_menu1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *create_window1(void)
|
|
|
|
{
|
|
|
|
return window1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *ui_get_top_parent(GtkWidget *widget)
|
|
|
|
{
|
2011-12-10 16:14:11 -08:00
|
|
|
GtkWidget *parent;
|
2011-10-19 00:35:24 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail(GTK_IS_WIDGET(widget), NULL);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU(widget))
|
|
|
|
parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
|
|
|
|
else
|
|
|
|
parent = gtk_widget_get_parent(widget);
|
|
|
|
if (parent == NULL)
|
|
|
|
parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
|
|
|
|
if (parent == NULL)
|
|
|
|
break;
|
|
|
|
widget = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-24 14:34:05 -07:00
|
|
|
void ui_init_builder(void)
|
|
|
|
{
|
|
|
|
gchar *interface_file;
|
2011-12-10 16:14:11 -08:00
|
|
|
const gchar *name;
|
2011-09-24 14:34:05 -07:00
|
|
|
GError *error;
|
|
|
|
GSList *iter, *all_objects;
|
2011-10-19 00:35:24 -07:00
|
|
|
GtkWidget *widget, *toplevel;
|
|
|
|
|
|
|
|
/* prevent function from being called twice */
|
|
|
|
if (GTK_IS_BUILDER(builder))
|
|
|
|
return;
|
2011-09-24 14:34:05 -07:00
|
|
|
|
|
|
|
builder = gtk_builder_new();
|
|
|
|
|
2011-12-10 14:39:07 -08:00
|
|
|
gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
|
|
|
|
|
2011-09-24 14:34:05 -07:00
|
|
|
error = NULL;
|
2011-10-14 13:23:45 +01:00
|
|
|
interface_file = g_build_filename(app->datadir, "geany.glade", NULL);
|
2011-09-24 14:34:05 -07:00
|
|
|
if (! gtk_builder_add_from_file(builder, interface_file, &error))
|
|
|
|
{
|
2011-12-10 15:44:37 -08:00
|
|
|
/* Show the user this message so they know WTF happened */
|
|
|
|
dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR,
|
|
|
|
_("Geany cannot start!"), error->message);
|
|
|
|
/* Aborts */
|
|
|
|
g_error("Cannot create user-interface: %s", error->message);
|
2011-09-24 14:34:05 -07:00
|
|
|
g_error_free(error);
|
|
|
|
g_free(interface_file);
|
|
|
|
g_object_unref(builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_free(interface_file);
|
|
|
|
|
|
|
|
gtk_builder_connect_signals(builder, NULL);
|
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
edit_menu1 = GTK_WIDGET(gtk_builder_get_object(builder, "edit_menu1"));
|
|
|
|
prefs_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "prefs_dialog"));
|
|
|
|
project_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "project_dialog"));
|
|
|
|
toolbar_popup_menu1 = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar_popup_menu1"));
|
|
|
|
window1 = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
|
|
|
|
|
|
|
|
g_object_set_data(G_OBJECT(edit_menu1), "edit_menu1", edit_menu1);
|
|
|
|
g_object_set_data(G_OBJECT(prefs_dialog), "prefs_dialog", prefs_dialog);
|
|
|
|
g_object_set_data(G_OBJECT(project_dialog), "project_dialog", project_dialog);
|
|
|
|
g_object_set_data(G_OBJECT(toolbar_popup_menu1), "toolbar_popup_menu1", toolbar_popup_menu1);
|
|
|
|
g_object_set_data(G_OBJECT(window1), "window1", window1);
|
2011-09-24 14:34:05 -07:00
|
|
|
|
|
|
|
all_objects = gtk_builder_get_objects(builder);
|
|
|
|
for (iter = all_objects; iter != NULL; iter = g_slist_next(iter))
|
|
|
|
{
|
2011-10-19 00:35:24 -07:00
|
|
|
if (! GTK_IS_WIDGET(iter->data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
widget = GTK_WIDGET(iter->data);
|
|
|
|
|
|
|
|
name = ui_guess_object_name(G_OBJECT(widget));
|
2011-09-24 14:34:05 -07:00
|
|
|
if (! name)
|
|
|
|
{
|
|
|
|
g_warning("Unable to get name from GtkBuilder object");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
toplevel = ui_get_top_parent(widget);
|
|
|
|
if (toplevel)
|
|
|
|
ui_hookup_widget(toplevel, widget, name);
|
2011-09-24 14:34:05 -07:00
|
|
|
}
|
|
|
|
g_slist_free(all_objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-29 20:18:19 +02:00
|
|
|
static void init_custom_style(void)
|
|
|
|
{
|
2012-09-28 04:30:57 +02:00
|
|
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
|
|
|
gchar *css_file = g_build_filename(app->datadir, "geany.css", NULL);
|
|
|
|
GtkCssProvider *css = gtk_css_provider_new();
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (! gtk_css_provider_load_from_path(css, css_file, &error))
|
|
|
|
{
|
|
|
|
g_warning("Failed to load custom CSS: %s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
|
|
|
GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref(css);
|
|
|
|
g_free(css_file);
|
|
|
|
#else
|
Fix our custom styles under KDE and for people using gtk-chtheme
We have a custom RC file defining various styles we need, and we want
the user to be able to override them (e.g. if they want -- or need --
other colors). Fair enough, one would simply call gtk_rc_parse() with
the appropriate filename. However, the styling rules applies in the
order they are loaded, then if we load our styles after GTK has loaded
the user's ones we'd override them.
There are 2 solutions to fix this:
1) set our styles' priority to something with lower than "user"
(actually "theme" priority because rules precedence are first
calculated depending on the priority no matter of how precise the
rules is, so we need to override the theme).
2) prepend our custom style to GTK's list while keeping priority to
user (which is the default), so it gets loaded before real user's
ones and so gets overridden by them.
One would normally go for 1 because it's ways simpler and requires less
code: you just have to add the priorities to your styles, which is a
matter of adding a few ":theme" in the RC file. However, KDE being a
bitch it doesn't set the gtk-theme-name but rather directly includes
the style to use in a user gtkrc file, which makes the theme have
"user" priority, hence overriding our styles. So, we cannot set
priorities in the RC file if we want to support running under KDE,
which pretty much leave us with no choice but to go with solution 2,
which unfortunately requires writing ugly code since GTK don't have a
gtk_rc_prepend_default_file() function. Thank you very much KDE.
Though, as a side benefit it also makes the code work with people using
gtk-chtheme, which also found it funny to include the theme in the user
RC file.
2013-03-15 15:54:00 +01:00
|
|
|
/* see setup_gtk2_styles() in main.c */
|
2012-09-28 04:30:57 +02:00
|
|
|
#endif
|
2012-09-29 20:18:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void ui_init(void)
|
2007-07-20 12:06:51 +00:00
|
|
|
{
|
2012-09-29 20:18:19 +02:00
|
|
|
init_custom_style();
|
|
|
|
|
2009-06-20 16:51:32 +00:00
|
|
|
init_recent_files();
|
|
|
|
|
2008-12-18 21:21:53 +00:00
|
|
|
ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar");
|
|
|
|
ui_widgets.print_page_setup = ui_lookup_widget(main_widgets.window, "page_setup1");
|
|
|
|
|
2009-01-27 20:19:43 +00:00
|
|
|
main_widgets.progressbar = progress_bar_create();
|
|
|
|
|
2010-09-13 14:39:32 +00:00
|
|
|
/* current word sensitive items */
|
2011-12-10 14:10:44 -08:00
|
|
|
widgets.popup_goto_items[0] = ui_lookup_widget(main_widgets.editor_menu, "goto_tag_definition2");
|
2010-09-13 14:39:32 +00:00
|
|
|
widgets.popup_goto_items[1] = ui_lookup_widget(main_widgets.editor_menu, "context_action1");
|
2011-12-10 14:10:44 -08:00
|
|
|
widgets.popup_goto_items[2] = ui_lookup_widget(main_widgets.editor_menu, "find_usage2");
|
|
|
|
widgets.popup_goto_items[3] = ui_lookup_widget(main_widgets.editor_menu, "find_document_usage2");
|
2010-09-13 14:39:32 +00:00
|
|
|
|
2008-12-18 21:21:53 +00:00
|
|
|
widgets.popup_copy_items[0] = ui_lookup_widget(main_widgets.editor_menu, "cut1");
|
|
|
|
widgets.popup_copy_items[1] = ui_lookup_widget(main_widgets.editor_menu, "copy1");
|
|
|
|
widgets.popup_copy_items[2] = ui_lookup_widget(main_widgets.editor_menu, "delete1");
|
|
|
|
widgets.menu_copy_items[0] = ui_lookup_widget(main_widgets.window, "menu_cut1");
|
|
|
|
widgets.menu_copy_items[1] = ui_lookup_widget(main_widgets.window, "menu_copy1");
|
|
|
|
widgets.menu_copy_items[2] = ui_lookup_widget(main_widgets.window, "menu_delete1");
|
|
|
|
widgets.menu_insert_include_items[0] = ui_lookup_widget(main_widgets.editor_menu, "insert_include1");
|
|
|
|
widgets.menu_insert_include_items[1] = ui_lookup_widget(main_widgets.window, "insert_include2");
|
|
|
|
widgets.save_buttons[0] = ui_lookup_widget(main_widgets.window, "menu_save1");
|
|
|
|
widgets.save_buttons[2] = ui_lookup_widget(main_widgets.window, "menu_save_all1");
|
|
|
|
widgets.redo_items[0] = ui_lookup_widget(main_widgets.editor_menu, "redo1");
|
|
|
|
widgets.redo_items[1] = ui_lookup_widget(main_widgets.window, "menu_redo2");
|
|
|
|
widgets.undo_items[0] = ui_lookup_widget(main_widgets.editor_menu, "undo1");
|
|
|
|
widgets.undo_items[1] = ui_lookup_widget(main_widgets.window, "menu_undo2");
|
2008-07-17 16:28:16 +00:00
|
|
|
|
2010-09-20 11:36:50 +00:00
|
|
|
/* reparent context submenus as needed */
|
|
|
|
{
|
|
|
|
GeanySharedMenu arr[] = {
|
2010-09-20 11:52:07 +00:00
|
|
|
{"commands2_menu", "commands2", "commands1"},
|
|
|
|
{"menu_format1_menu", "menu_format1", "menu_format2"},
|
2010-09-20 12:06:04 +00:00
|
|
|
{"more1_menu", "more1", "search2"},
|
2010-09-20 11:36:50 +00:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
static GeanySharedMenu items[G_N_ELEMENTS(arr)];
|
|
|
|
|
|
|
|
memcpy(items, arr, sizeof(arr));
|
|
|
|
g_signal_connect(main_widgets.editor_menu, "show", G_CALLBACK(on_editor_menu_show), items);
|
|
|
|
g_signal_connect(main_widgets.editor_menu, "hide", G_CALLBACK(on_editor_menu_hide), items);
|
|
|
|
}
|
2009-10-27 17:27:24 +00:00
|
|
|
|
2009-06-20 16:51:32 +00:00
|
|
|
ui_init_toolbar_widgets();
|
2007-07-20 12:06:51 +00:00
|
|
|
init_document_widgets();
|
2008-11-26 13:15:53 +00:00
|
|
|
create_config_files_menu();
|
2008-10-13 12:38:32 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 20:14:42 +00:00
|
|
|
|
2011-09-24 14:34:05 -07:00
|
|
|
void ui_finalize_builder(void)
|
|
|
|
{
|
2011-10-19 00:35:24 -07:00
|
|
|
if (GTK_IS_BUILDER(builder))
|
|
|
|
g_object_unref(builder);
|
|
|
|
|
|
|
|
/* cleanup refs lingering even after GtkBuilder is destroyed */
|
|
|
|
if (GTK_IS_WIDGET(edit_menu1))
|
|
|
|
gtk_widget_destroy(edit_menu1);
|
|
|
|
if (GTK_IS_WIDGET(prefs_dialog))
|
|
|
|
gtk_widget_destroy(prefs_dialog);
|
|
|
|
if (GTK_IS_WIDGET(project_dialog))
|
|
|
|
gtk_widget_destroy(project_dialog);
|
|
|
|
if (GTK_IS_WIDGET(toolbar_popup_menu1))
|
|
|
|
gtk_widget_destroy(toolbar_popup_menu1);
|
|
|
|
if (GTK_IS_WIDGET(window1))
|
|
|
|
gtk_widget_destroy(window1);
|
2011-09-24 14:34:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-11 16:56:28 +00:00
|
|
|
static void auto_separator_update(GeanyAutoSeparator *autosep)
|
|
|
|
{
|
2013-02-21 19:27:06 +02:00
|
|
|
g_return_if_fail(autosep->item_count >= 0);
|
2008-12-11 16:56:28 +00:00
|
|
|
|
|
|
|
if (autosep->widget)
|
2013-02-21 19:27:06 +02:00
|
|
|
{
|
|
|
|
if (autosep->item_count > 0)
|
|
|
|
ui_widget_show_hide(autosep->widget, autosep->show_count > 0);
|
|
|
|
else
|
|
|
|
gtk_widget_destroy(autosep->widget);
|
|
|
|
}
|
2008-12-11 16:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void on_auto_separator_item_show_hide(GtkWidget *widget, gpointer user_data)
|
|
|
|
{
|
|
|
|
GeanyAutoSeparator *autosep = user_data;
|
|
|
|
|
2012-09-15 13:52:49 +02:00
|
|
|
if (gtk_widget_get_visible(widget))
|
2013-02-21 19:27:06 +02:00
|
|
|
autosep->show_count++;
|
2008-12-11 16:56:28 +00:00
|
|
|
else
|
2013-02-21 19:27:06 +02:00
|
|
|
autosep->show_count--;
|
2008-12-11 16:56:28 +00:00
|
|
|
auto_separator_update(autosep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void on_auto_separator_item_destroy(GtkWidget *widget, gpointer user_data)
|
|
|
|
{
|
|
|
|
GeanyAutoSeparator *autosep = user_data;
|
|
|
|
|
2013-02-21 19:27:06 +02:00
|
|
|
autosep->item_count--;
|
|
|
|
autosep->item_count = MAX(autosep->item_count, 0);
|
2012-09-15 13:52:49 +02:00
|
|
|
/* gtk_widget_get_visible() won't work now the widget is being destroyed,
|
2008-12-11 16:56:28 +00:00
|
|
|
* so assume widget was visible */
|
2013-02-21 19:27:06 +02:00
|
|
|
autosep->show_count--;
|
|
|
|
autosep->show_count = MAX(autosep->item_count, 0);
|
2008-12-11 16:56:28 +00:00
|
|
|
auto_separator_update(autosep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Show the separator widget if @a item or another is visible. */
|
|
|
|
/* Note: This would be neater taking a widget argument, setting a "visible-count"
|
|
|
|
* property, and using reference counting to keep the widget alive whilst its visible group
|
|
|
|
* is alive. */
|
|
|
|
void ui_auto_separator_add_ref(GeanyAutoSeparator *autosep, GtkWidget *item)
|
|
|
|
{
|
|
|
|
/* set widget ptr NULL when widget destroyed */
|
2013-02-21 19:27:06 +02:00
|
|
|
if (autosep->item_count == 0)
|
2008-12-11 16:56:28 +00:00
|
|
|
g_signal_connect(autosep->widget, "destroy",
|
|
|
|
G_CALLBACK(gtk_widget_destroyed), &autosep->widget);
|
|
|
|
|
2012-09-15 13:52:49 +02:00
|
|
|
if (gtk_widget_get_visible(item))
|
2013-02-21 19:27:06 +02:00
|
|
|
autosep->show_count++;
|
|
|
|
|
|
|
|
autosep->item_count++;
|
|
|
|
auto_separator_update(autosep);
|
|
|
|
|
2008-12-11 16:56:28 +00:00
|
|
|
g_signal_connect(item, "show", G_CALLBACK(on_auto_separator_item_show_hide), autosep);
|
|
|
|
g_signal_connect(item, "hide", G_CALLBACK(on_auto_separator_item_show_hide), autosep);
|
|
|
|
g_signal_connect(item, "destroy", G_CALLBACK(on_auto_separator_item_destroy), autosep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-18 20:14:42 +00:00
|
|
|
/**
|
2011-06-13 18:41:50 +00:00
|
|
|
* Sets @a text as the contents of the tooltip for @a widget.
|
2008-11-18 20:14:42 +00:00
|
|
|
*
|
2011-06-13 18:41:50 +00:00
|
|
|
* @param widget The widget the tooltip should be set for.
|
|
|
|
* @param text The text for the tooltip.
|
2009-01-30 18:53:23 +00:00
|
|
|
*
|
2011-06-13 18:41:50 +00:00
|
|
|
* @since 0.16
|
|
|
|
* @deprecated 0.21 use gtk_widget_set_tooltip_text() instead
|
2008-11-18 20:14:42 +00:00
|
|
|
*/
|
|
|
|
void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text)
|
|
|
|
{
|
|
|
|
gtk_widget_set_tooltip_text(widget, text);
|
|
|
|
}
|
2008-12-02 18:33:41 +00:00
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Returns a widget from a name in a component, usually created by Glade.
|
2008-12-02 18:33:41 +00:00
|
|
|
* Call it with the toplevel widget in the component (i.e. a window/dialog),
|
|
|
|
* or alternatively any widget in the component, and the name of the widget
|
|
|
|
* you want returned.
|
|
|
|
* @param widget Widget with the @a widget_name property set.
|
|
|
|
* @param widget_name Name to lookup.
|
2008-12-28 17:25:09 +00:00
|
|
|
* @return The widget found.
|
2011-10-19 00:35:24 -07:00
|
|
|
* @see ui_hookup_widget().
|
2009-01-30 18:53:23 +00:00
|
|
|
*
|
|
|
|
* @since 0.16
|
|
|
|
*/
|
2008-12-02 18:33:41 +00:00
|
|
|
GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
|
|
|
|
{
|
2011-10-19 00:35:24 -07:00
|
|
|
GtkWidget *parent, *found_widget;
|
2011-09-22 23:10:45 -07:00
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
g_return_val_if_fail(widget != NULL, NULL);
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_val_if_fail(widget_name != NULL, NULL);
|
2009-04-05 14:13:56 +00:00
|
|
|
|
2011-10-19 00:35:24 -07:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (GTK_IS_MENU(widget))
|
|
|
|
parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
|
|
|
|
else
|
2012-09-11 17:12:35 +02:00
|
|
|
parent = gtk_widget_get_parent(widget);
|
2011-10-19 00:35:24 -07:00
|
|
|
if (parent == NULL)
|
|
|
|
parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
|
|
|
|
if (parent == NULL)
|
|
|
|
break;
|
|
|
|
widget = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
|
2009-04-05 21:07:40 +00:00
|
|
|
if (G_UNLIKELY(found_widget == NULL))
|
2008-12-18 21:21:53 +00:00
|
|
|
g_warning("Widget not found: %s", widget_name);
|
|
|
|
return found_widget;
|
2008-12-02 18:33:41 +00:00
|
|
|
}
|
2009-01-27 20:19:43 +00:00
|
|
|
|
|
|
|
|
2012-01-20 19:14:31 +01:00
|
|
|
/* wraps gtk_builder_get_object()
|
|
|
|
* unlike ui_lookup_widget(), it does only support getting object created from the main
|
|
|
|
* UI file, but it can fetch any object, not only widgets */
|
|
|
|
gpointer ui_builder_get_object (const gchar *name)
|
|
|
|
{
|
|
|
|
return gtk_builder_get_object (builder, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-27 20:19:43 +00:00
|
|
|
/* Progress Bar */
|
2011-10-30 22:52:29 +01:00
|
|
|
static guint progress_bar_timer_id = 0;
|
2009-01-27 20:19:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *progress_bar_create(void)
|
|
|
|
{
|
|
|
|
GtkWidget *bar = gtk_progress_bar_new();
|
|
|
|
|
2011-08-06 18:34:14 +00:00
|
|
|
/* Set the progressbar's height to 1 to fit it in the statusbar */
|
|
|
|
gtk_widget_set_size_request(bar, -1, 1);
|
|
|
|
gtk_box_pack_start (GTK_BOX(ui_widgets.statusbar), bar, FALSE, FALSE, 3);
|
2009-01-27 20:19:43 +00:00
|
|
|
|
|
|
|
return bar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean progress_bar_pulse(gpointer data)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_pulse(GTK_PROGRESS_BAR(main_widgets.progressbar));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a constantly pulsing progressbar in the right corner of the statusbar
|
|
|
|
* (if the statusbar is visible). This is a convenience function which adds a timer to
|
|
|
|
* pulse the progressbar constantly until ui_progress_bar_stop() is called.
|
|
|
|
* You can use this function when you have time consuming asynchronous operation and want to
|
|
|
|
* display some activity in the GUI and when you don't know about detailed progress steps.
|
|
|
|
* The progressbar widget is hidden by default when it is not active. This function and
|
|
|
|
* ui_progress_bar_stop() will show and hide it automatically for you.
|
|
|
|
*
|
|
|
|
* You can also access the progressbar widget directly using @c geany->main_widgets->progressbar
|
|
|
|
* and use the GtkProgressBar API to set discrete fractions to display better progress information.
|
|
|
|
* In this case, you need to show and hide the widget yourself. You can find some example code
|
|
|
|
* in @c src/printing.c.
|
|
|
|
*
|
|
|
|
* @param text The text to be shown as the progress bar label or NULL to leave it empty.
|
2009-01-30 18:53:23 +00:00
|
|
|
*
|
|
|
|
* @since 0.16
|
|
|
|
**/
|
2009-01-27 20:19:43 +00:00
|
|
|
void ui_progress_bar_start(const gchar *text)
|
|
|
|
{
|
2011-10-30 22:52:29 +01:00
|
|
|
g_return_if_fail(progress_bar_timer_id == 0);
|
2009-01-27 20:19:43 +00:00
|
|
|
|
|
|
|
if (! interface_prefs.statusbar_visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text);
|
|
|
|
|
|
|
|
progress_bar_timer_id = g_timeout_add(200, progress_bar_pulse, NULL);
|
|
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(main_widgets.progressbar));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-30 18:53:23 +00:00
|
|
|
/** Stops a running progress bar and hides the widget again.
|
|
|
|
*
|
|
|
|
* @since 0.16
|
|
|
|
**/
|
2009-01-27 20:19:43 +00:00
|
|
|
void ui_progress_bar_stop(void)
|
|
|
|
{
|
|
|
|
gtk_widget_hide(GTK_WIDGET(main_widgets.progressbar));
|
|
|
|
|
2011-10-30 22:52:29 +01:00
|
|
|
if (progress_bar_timer_id != 0)
|
2009-01-27 20:19:43 +00:00
|
|
|
{
|
|
|
|
g_source_remove(progress_bar_timer_id);
|
2011-10-30 22:52:29 +01:00
|
|
|
progress_bar_timer_id = 0;
|
2009-01-27 20:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 12:25:47 +00:00
|
|
|
|
|
|
|
static gint compare_menu_item_labels(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
GtkMenuItem *item_a = GTK_MENU_ITEM(a);
|
|
|
|
GtkMenuItem *item_b = GTK_MENU_ITEM(b);
|
|
|
|
gchar *sa, *sb;
|
|
|
|
gint result;
|
|
|
|
|
|
|
|
sa = ui_menu_item_get_text(item_a);
|
|
|
|
sb = ui_menu_item_get_text(item_b);
|
|
|
|
result = utils_str_casecmp(sa, sb);
|
|
|
|
g_free(sa);
|
|
|
|
g_free(sb);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Currently @a menu should contain only GtkMenuItems with labels. */
|
|
|
|
void ui_menu_sort_by_label(GtkMenu *menu)
|
|
|
|
{
|
|
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(menu));
|
|
|
|
GList *node;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
list = g_list_sort(list, compare_menu_item_labels);
|
|
|
|
pos = 0;
|
2009-06-12 15:32:35 +00:00
|
|
|
foreach_list(node, list)
|
2009-04-08 12:25:47 +00:00
|
|
|
{
|
2009-06-12 15:32:35 +00:00
|
|
|
gtk_menu_reorder_child(menu, node->data, pos);
|
2009-04-08 12:25:47 +00:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
g_list_free(list);
|
|
|
|
}
|
|
|
|
|
2009-09-21 16:21:03 +00:00
|
|
|
|
2010-08-12 17:21:24 +00:00
|
|
|
void ui_label_set_markup(GtkLabel *label, const gchar *format, ...)
|
2009-09-21 16:21:03 +00:00
|
|
|
{
|
|
|
|
va_list a;
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
va_start(a, format);
|
|
|
|
text = g_strdup_vprintf(format, a);
|
|
|
|
va_end(a);
|
|
|
|
|
|
|
|
gtk_label_set_text(label, text);
|
|
|
|
gtk_label_set_use_markup(label, TRUE);
|
|
|
|
g_free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-05 21:13:47 +00:00
|
|
|
GtkWidget *ui_label_new_bold(const gchar *text)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *label_text;
|
|
|
|
|
|
|
|
label_text = g_markup_escape_text(text, -1);
|
2010-08-12 17:21:24 +00:00
|
|
|
label = gtk_label_new(NULL);
|
|
|
|
ui_label_set_markup(GTK_LABEL(label), "<b>%s</b>", label_text);
|
2010-08-05 21:13:47 +00:00
|
|
|
g_free(label_text);
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Adds a list of document items to @a menu.
|
2009-10-13 17:14:25 +00:00
|
|
|
* @param menu Menu.
|
|
|
|
* @param active Which document to highlight, or @c NULL.
|
|
|
|
* @param callback is used for each menu item's @c "activate" signal and will be passed
|
|
|
|
* the corresponding document pointer as @c user_data.
|
2009-10-14 12:21:18 +00:00
|
|
|
* @warning You should check @c doc->is_valid in the callback.
|
|
|
|
* @since 0.19 */
|
2009-10-13 17:14:25 +00:00
|
|
|
void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback)
|
2011-04-10 17:03:41 +00:00
|
|
|
{
|
|
|
|
ui_menu_add_document_items_sorted(menu, active, callback, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Adds a list of document items to @a menu.
|
|
|
|
*
|
2011-04-12 17:43:00 +00:00
|
|
|
* @a compare_func might be NULL to not sort the documents in the menu. In this case,
|
2011-04-10 17:03:41 +00:00
|
|
|
* the order of the document tabs is used.
|
|
|
|
*
|
2012-08-06 16:12:31 +02:00
|
|
|
* See document_compare_by_display_name() for an example sort function.
|
2011-04-10 17:03:41 +00:00
|
|
|
*
|
|
|
|
* @param menu Menu.
|
|
|
|
* @param active Which document to highlight, or @c NULL.
|
|
|
|
* @param callback is used for each menu item's @c "activate" signal and will be passed
|
|
|
|
* the corresponding document pointer as @c user_data.
|
2011-04-12 17:43:00 +00:00
|
|
|
* @param compare_func is used to sort the list. Might be @c NULL to not sort the list.
|
2011-04-10 17:03:41 +00:00
|
|
|
* @warning You should check @c doc->is_valid in the callback.
|
|
|
|
* @since 0.21 */
|
|
|
|
void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active,
|
2011-04-12 17:43:00 +00:00
|
|
|
GCallback callback, GCompareFunc compare_func)
|
2009-10-13 17:14:25 +00:00
|
|
|
{
|
2010-10-26 17:30:16 +00:00
|
|
|
GtkWidget *menu_item, *menu_item_label, *image;
|
2009-10-13 17:14:25 +00:00
|
|
|
GeanyDocument *doc;
|
|
|
|
guint i, len;
|
2010-08-05 21:13:47 +00:00
|
|
|
gchar *base_name, *label;
|
2011-04-10 17:03:41 +00:00
|
|
|
GPtrArray *sorted_documents;
|
2009-10-13 17:14:25 +00:00
|
|
|
|
2011-10-30 22:52:29 +01:00
|
|
|
len = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
|
2011-04-10 17:03:41 +00:00
|
|
|
|
|
|
|
sorted_documents = g_ptr_array_sized_new(len);
|
|
|
|
/* copy the documents_array into the new one */
|
|
|
|
foreach_document(i)
|
2009-10-13 17:14:25 +00:00
|
|
|
{
|
2011-04-13 12:22:30 +00:00
|
|
|
g_ptr_array_add(sorted_documents, documents[i]);
|
2011-04-10 17:03:41 +00:00
|
|
|
}
|
2011-04-17 13:41:54 +00:00
|
|
|
if (compare_func == NULL)
|
|
|
|
compare_func = document_compare_by_tab_order;
|
|
|
|
|
2011-04-10 17:03:41 +00:00
|
|
|
/* and now sort it */
|
2011-04-17 13:41:54 +00:00
|
|
|
g_ptr_array_sort(sorted_documents, compare_func);
|
2011-04-10 17:03:41 +00:00
|
|
|
|
2011-04-11 16:29:01 +00:00
|
|
|
for (i = 0; i < sorted_documents->len; i++)
|
2011-04-10 17:03:41 +00:00
|
|
|
{
|
|
|
|
doc = g_ptr_array_index(sorted_documents, i);
|
2009-10-13 17:14:25 +00:00
|
|
|
|
|
|
|
base_name = g_path_get_basename(DOC_FILENAME(doc));
|
2010-10-26 17:30:16 +00:00
|
|
|
menu_item = gtk_image_menu_item_new_with_label(base_name);
|
2010-10-27 14:20:18 +00:00
|
|
|
image = gtk_image_new_from_pixbuf(doc->file_type->icon);
|
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image);
|
2010-10-26 17:30:16 +00:00
|
|
|
|
2009-10-13 17:14:25 +00:00
|
|
|
gtk_widget_show(menu_item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), menu_item);
|
|
|
|
g_signal_connect(menu_item, "activate", callback, doc);
|
|
|
|
|
|
|
|
menu_item_label = gtk_bin_get_child(GTK_BIN(menu_item));
|
2013-02-11 03:31:05 +01:00
|
|
|
gtk_widget_set_name(menu_item_label, document_get_status_widget_class(doc));
|
2009-10-13 17:14:25 +00:00
|
|
|
|
|
|
|
if (doc == active)
|
2010-08-05 21:13:47 +00:00
|
|
|
{
|
|
|
|
label = g_markup_escape_text(base_name, -1);
|
|
|
|
ui_label_set_markup(GTK_LABEL(menu_item_label), "<b>%s</b>", label);
|
|
|
|
g_free(label);
|
|
|
|
}
|
2009-10-13 17:14:25 +00:00
|
|
|
|
|
|
|
g_free(base_name);
|
|
|
|
}
|
2011-04-10 17:03:41 +00:00
|
|
|
g_ptr_array_free(sorted_documents, TRUE);
|
2009-10-13 17:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Checks whether the passed @a keyval is the Enter or Return key.
|
2010-03-07 19:33:15 +00:00
|
|
|
* There are three different Enter/Return key values
|
|
|
|
* (@c GDK_Return, @c GDK_ISO_Enter, @c GDK_KP_Enter).
|
|
|
|
* This is just a convenience function.
|
|
|
|
* @param keyval A keyval.
|
|
|
|
* @return @c TRUE if @a keyval is the one of the Enter/Return key values, otherwise @c FALSE.
|
|
|
|
* @since 0.19 */
|
|
|
|
gboolean ui_is_keyval_enter_or_return(guint keyval)
|
|
|
|
{
|
|
|
|
return (keyval == GDK_Return || keyval == GDK_ISO_Enter|| keyval == GDK_KP_Enter);
|
|
|
|
}
|
2010-04-11 21:56:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Reads an integer from the GTK default settings registry
|
|
|
|
* (see http://library.gnome.org/devel/gtk/stable/GtkSettings.html).
|
|
|
|
* @param property_name The property to read.
|
|
|
|
* @param default_value The default value in case the value could not be read.
|
|
|
|
* @return The value for the property if it exists, otherwise the @a default_value.
|
|
|
|
* @since 0.19 */
|
|
|
|
gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value)
|
|
|
|
{
|
|
|
|
if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(
|
|
|
|
gtk_settings_get_default())), property_name))
|
|
|
|
{
|
|
|
|
gint value;
|
|
|
|
g_object_get(G_OBJECT(gtk_settings_get_default()), property_name, &value, NULL);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return default_value;
|
|
|
|
}
|
2010-05-09 15:48:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text,
|
|
|
|
gint new_text_len, gint *position, gpointer data)
|
|
|
|
{
|
2010-11-02 17:15:22 +00:00
|
|
|
gboolean first = position != NULL && *position == 0;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (new_text_len == -1)
|
2011-10-30 22:52:29 +01:00
|
|
|
new_text_len = (gint) strlen(new_text);
|
2010-05-09 15:48:29 +00:00
|
|
|
|
2010-11-02 17:15:22 +00:00
|
|
|
for (i = 0; i < new_text_len; i++, new_text++)
|
2010-05-09 15:48:29 +00:00
|
|
|
{
|
2010-11-02 17:15:22 +00:00
|
|
|
if ((!first || !strchr("+-", *new_text)) && !isdigit(*new_text))
|
|
|
|
{
|
|
|
|
g_signal_stop_emission_by_name(editable, "insert-text");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
first = FALSE;
|
2010-05-09 15:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:02:30 +00:00
|
|
|
|
|
|
|
/* gets the icon that applies to a particular MIME type */
|
|
|
|
GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size)
|
|
|
|
{
|
|
|
|
GdkPixbuf *icon = NULL;
|
|
|
|
gchar *ctype;
|
|
|
|
GIcon *gicon;
|
|
|
|
GtkIconInfo *info;
|
|
|
|
GtkIconTheme *theme;
|
|
|
|
gint real_size;
|
|
|
|
|
2010-10-26 18:11:23 +00:00
|
|
|
if (!gtk_icon_size_lookup(size, &real_size, NULL))
|
|
|
|
{
|
|
|
|
g_return_val_if_reached(NULL);
|
|
|
|
}
|
2010-10-26 16:02:30 +00:00
|
|
|
ctype = g_content_type_from_mime_type(mime_type);
|
2010-11-07 15:24:26 +00:00
|
|
|
if (ctype != NULL)
|
2010-10-26 16:02:30 +00:00
|
|
|
{
|
2010-11-07 15:24:26 +00:00
|
|
|
gicon = g_content_type_get_icon(ctype);
|
|
|
|
theme = gtk_icon_theme_get_default();
|
|
|
|
info = gtk_icon_theme_lookup_by_gicon(theme, gicon, real_size, 0);
|
|
|
|
g_object_unref(gicon);
|
|
|
|
g_free(ctype);
|
|
|
|
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
icon = gtk_icon_info_load_icon(info, NULL);
|
|
|
|
gtk_icon_info_free(info);
|
|
|
|
}
|
2010-10-26 16:02:30 +00:00
|
|
|
}
|
2011-10-28 10:25:58 -07:00
|
|
|
|
2011-06-17 22:51:17 +00:00
|
|
|
/* fallback for builds with GIO < 2.18 or if icon lookup failed, like it might happen on Windows */
|
2010-11-07 15:24:26 +00:00
|
|
|
if (icon == NULL)
|
|
|
|
{
|
|
|
|
const gchar *stock_id = GTK_STOCK_FILE;
|
|
|
|
GtkIconSet *icon_set;
|
2010-10-26 16:02:30 +00:00
|
|
|
|
2010-11-07 15:24:26 +00:00
|
|
|
if (strstr(mime_type, "directory"))
|
|
|
|
stock_id = GTK_STOCK_DIRECTORY;
|
2010-10-26 16:02:30 +00:00
|
|
|
|
2010-11-07 15:24:26 +00:00
|
|
|
icon_set = gtk_icon_factory_lookup_default(stock_id);
|
|
|
|
if (icon_set)
|
|
|
|
{
|
2013-04-20 15:46:15 +02:00
|
|
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
|
|
|
GtkStyleContext *ctx = gtk_style_context_new();
|
2013-11-18 22:22:57 +01:00
|
|
|
GtkWidgetPath *path = gtk_widget_path_new();
|
|
|
|
gtk_style_context_set_path(ctx, path);
|
|
|
|
gtk_widget_path_unref(path);
|
2013-04-20 15:46:15 +02:00
|
|
|
icon = gtk_icon_set_render_icon_pixbuf(icon_set, ctx, size);
|
|
|
|
g_object_unref(ctx);
|
|
|
|
#else
|
2010-11-07 15:24:26 +00:00
|
|
|
icon = gtk_icon_set_render_icon(icon_set, gtk_widget_get_default_style(),
|
|
|
|
gtk_widget_get_default_direction(),
|
|
|
|
GTK_STATE_NORMAL, size, NULL, NULL);
|
2013-04-20 15:46:15 +02:00
|
|
|
#endif
|
2010-11-07 15:24:26 +00:00
|
|
|
}
|
2010-10-26 16:02:30 +00:00
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2011-06-02 21:15:37 +00:00
|
|
|
|
|
|
|
void ui_focus_current_document(void)
|
|
|
|
{
|
|
|
|
GeanyDocument *doc = document_get_current();
|
|
|
|
|
|
|
|
if (doc != NULL)
|
|
|
|
document_grab_focus(doc);
|
|
|
|
}
|
2012-01-08 17:37:58 +00:00
|
|
|
|
|
|
|
|
2012-02-19 10:30:31 +01:00
|
|
|
/** Finds the label text associated with stock_id
|
|
|
|
* @param stock_id stock_id to lookup e.g. @c GTK_STOCK_OPEN.
|
|
|
|
* @return The label text for stock
|
2012-01-08 17:37:58 +00:00
|
|
|
* @since Geany 1.22 */
|
|
|
|
const gchar *ui_lookup_stock_label(const gchar *stock_id)
|
|
|
|
{
|
|
|
|
GtkStockItem item;
|
|
|
|
|
|
|
|
if (gtk_stock_lookup(stock_id, &item))
|
|
|
|
return item.label;
|
|
|
|
|
|
|
|
g_warning("No stock id '%s'!", stock_id);
|
|
|
|
return NULL;
|
|
|
|
}
|