geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

osx.c
Go to the documentation of this file.
1/*
2 * osx.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2015 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#ifdef MAC_INTEGRATION
22
23#include "osx.h"
24
25#include "utils.h"
26#include "ui_utils.h"
27#include "main.h"
28
29
30static gboolean app_block_termination_cb(GtkosxApplication *app, gpointer data)
31{
32 return !main_quit();
33}
34
35
36/* For some reason osx doesn't like when the NSApplicationOpenFile handler blocks for
37 * a long time which may be caused by the project_ask_close() below. Finish the
38 * NSApplicationOpenFile handler immediately and perform the potentially blocking
39 * code on idle in this function. */
40static gboolean open_project_idle(gchar *locale_path)
41{
42 gchar *utf8_path;
43
44 utf8_path = utils_get_utf8_from_locale(locale_path);
45 if (app->project == NULL ||
46 (g_strcmp0(utf8_path, app->project->file_name) != 0 && project_ask_close()))
48 g_free(utf8_path);
49 g_free(locale_path);
50 return FALSE;
51}
52
53
54static gboolean app_open_file_cb(GtkosxApplication *osx_app, gchar *path, gpointer user_data)
55{
56 gchar opened = FALSE;
57 gchar *locale_path;
58
59 locale_path = utils_get_locale_from_utf8(path);
60
61 if (!g_path_is_absolute(locale_path))
62 {
63 gchar *cwd = g_get_current_dir();
64 SETPTR(locale_path, g_build_filename(cwd, locale_path, NULL));
65 g_free(cwd);
66 }
67
68 if (g_str_has_suffix(path, ".geany"))
69 {
70 g_idle_add((GSourceFunc)open_project_idle, locale_path);
71 opened = TRUE;
72 }
73 else
74 {
75 opened = document_open_file(locale_path, FALSE, NULL, NULL) != NULL;
76 g_free(locale_path);
77 }
78
79 return opened;
80}
81
82
83static void on_new_window(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
84{
86}
87
88
89void osx_ui_init(void)
90{
91 GtkWidget *item, *menu;
92 GtkosxApplication *osx_app = gtkosx_application_get();
93
94 item = ui_lookup_widget(main_widgets.window, "menubar1");
95 gtk_widget_hide(item);
96 gtkosx_application_set_menu_bar(osx_app, GTK_MENU_SHELL(item));
97
98 item = ui_lookup_widget(main_widgets.window, "menu_quit1");
99 gtk_widget_hide(item);
100
101 item = ui_lookup_widget(main_widgets.window, "menu_info1");
102 gtkosx_application_insert_app_menu_item(osx_app, item, 0);
103
104 item = ui_lookup_widget(main_widgets.window, "menu_help1");
105 gtkosx_application_set_help_menu(osx_app, GTK_MENU_ITEM(item));
106
107 gtkosx_application_set_use_quartz_accelerators(osx_app, FALSE);
108
109 g_signal_connect(osx_app, "NSApplicationBlockTermination",
110 G_CALLBACK(app_block_termination_cb), NULL);
111 g_signal_connect(osx_app, "NSApplicationOpenFile",
112 G_CALLBACK(app_open_file_cb), NULL);
113
114 menu = gtk_menu_new();
115 item = gtk_menu_item_new_with_label("New Window");
116 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(on_new_window), NULL);
117 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
118 gtkosx_application_set_dock_menu(osx_app, GTK_MENU_SHELL(menu));
119}
120
121#endif /* MAC_INTEGRATION */
GeanyDocument * document_open_file(const gchar *locale_filename, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
Opens a document specified by locale_filename.
Definition: document.c:908
gboolean main_quit(void)
Definition: libmain.c:1383
GeanyApp * app
Definition: libmain.c:86
Main program-related commands.
gboolean project_load_file_with_session(const gchar *locale_file_name)
Definition: project.c:274
gboolean project_ask_close(void)
Definition: project.c:660
#define NULL
Definition: rbtree.h:150
struct GeanyProject * project
Currently active project or NULL if none is open.
Definition: app.h:49
GtkWidget * window
Main window.
Definition: ui_utils.h:80
gchar * file_name
Where the project file is stored (in UTF-8).
Definition: project.h:38
GeanyMainWidgets main_widgets
Definition: ui_utils.c:72
GtkWidget * ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
Returns a widget from a name in a component, usually created by Glade.
Definition: ui_utils.c:2743
User Interface general utility functions.
gchar * utils_get_utf8_from_locale(const gchar *locale_text)
Converts the given string (in locale encoding) into UTF-8 encoding.
Definition: utils.c:1272
void utils_start_new_geany_instance(const gchar *doc_path)
Definition: utils.c:2348
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
Definition: utils.c:1243
General utility functions, non-GTK related.
#define SETPTR(ptr, result)
Assigns result to ptr, then frees the old value.
Definition: utils.h:50