Skip to content

Commit 3aeeac7

Browse files
committed
cleanups
1 parent f7d2279 commit 3aeeac7

10 files changed

Lines changed: 144 additions & 213 deletions

File tree

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- rename win.fullscreen etc. as main.fullscreen
2+
3+
- move settings, cssprovider into nip4app?
4+

src/nip4app.c renamed to src/app.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
#include "nip4.h"
22

3-
struct _Nip4App {
3+
struct _App {
44
GtkApplication parent;
55
};
66

7-
G_DEFINE_TYPE(Nip4App, nip4_app, GTK_TYPE_APPLICATION);
7+
G_DEFINE_TYPE(App, app, GTK_TYPE_APPLICATION);
88

99
static void
10-
nip4_app_init(Nip4App *app)
10+
app_init(App *app)
1111
{
1212
}
1313

1414
static void
15-
nip4_app_activate(GApplication *app)
15+
app_activate(GApplication *gapp)
1616
{
1717
MainWindow *win;
1818

19-
win = main_window_new(APP(app));
19+
win = main_window_new(APP(gapp));
2020
gtk_window_present(GTK_WINDOW(win));
2121
}
2222

2323
static void
24-
nip4_app_quit_activated(GSimpleAction *action,
25-
GVariant *parameter, gpointer app)
24+
app_quit_activated(GSimpleAction *action,
25+
GVariant *parameter, gpointer user_data)
2626
{
27-
g_application_quit(G_APPLICATION(app));
27+
g_application_quit(G_APPLICATION(user_data));
2828
}
2929

3030
static void
31-
nip4_app_new_activated(GSimpleAction *action,
31+
app_new_activated(GSimpleAction *action,
3232
GVariant *parameter, gpointer user_data)
3333
{
34-
nip4_app_activate(G_APPLICATION(user_data));
34+
app_activate(G_APPLICATION(user_data));
3535
}
3636

3737
static MainWindow *
38-
nip4_app_win(Nip4App *app)
38+
app_win(App *app)
3939
{
4040
GList *windows = gtk_application_get_windows(GTK_APPLICATION(app));
4141

@@ -46,19 +46,19 @@ nip4_app_win(Nip4App *app)
4646
}
4747

4848
static void
49-
nip4_app_about_activated(GSimpleAction *action,
49+
app_about_activated(GSimpleAction *action,
5050
GVariant *parameter, gpointer user_data)
5151
{
52-
Nip4App *app = APP(user_data);
53-
MainWindow *win = nip4_app_win(app);
52+
App *app = APP(user_data);
53+
MainWindow *win = app_win(app);
5454

5555
static const char *authors[] = {
5656
"jcupitt",
5757
NULL
5858
};
5959

6060
#ifdef DEBUG
61-
printf("nip4_app_about_activated:\n");
61+
printf("app_about_activated:\n");
6262
#endif /*DEBUG*/
6363

6464
gtk_show_about_dialog(win ? GTK_WINDOW(win) : NULL,
@@ -75,13 +75,13 @@ nip4_app_about_activated(GSimpleAction *action,
7575
}
7676

7777
static GActionEntry app_entries[] = {
78-
{ "quit", nip4_app_quit_activated },
79-
{ "new", nip4_app_new_activated },
80-
{ "about", nip4_app_about_activated },
78+
{ "quit", app_quit_activated },
79+
{ "new", app_new_activated },
80+
{ "about", app_about_activated },
8181
};
8282

8383
static void
84-
nip4_app_startup(GApplication *app)
84+
app_startup(GApplication *app)
8585
{
8686
int i;
8787
GtkSettings *settings;
@@ -90,9 +90,11 @@ nip4_app_startup(GApplication *app)
9090
const gchar *action_and_target;
9191
const gchar *accelerators[2];
9292
} accels[] = {
93+
// application wide accels
9394
{ "app.quit", { "<Primary>q", NULL } },
9495
{ "app.new", { "<Primary>n", NULL } },
9596

97+
// main window accels ... the "win." prefix is wired into gtk
9698
{ "win.copy", { "<Primary>c", NULL } },
9799
{ "win.paste", { "<Primary>v", NULL } },
98100
{ "win.duplicate", { "<Primary>d", NULL } },
@@ -108,7 +110,7 @@ nip4_app_startup(GApplication *app)
108110
{ "win.properties", { "<Alt>Return", NULL } },
109111
};
110112

111-
G_APPLICATION_CLASS(nip4_app_parent_class)->startup(app);
113+
G_APPLICATION_CLASS(app_parent_class)->startup(app);
112114

113115
/* Image display programs are supposed to default to a dark theme,
114116
* according to the HIG.
@@ -132,16 +134,15 @@ nip4_app_startup(GApplication *app)
132134
MAIN_WINDOW_TYPE;
133135

134136
g_action_map_add_action_entries(G_ACTION_MAP(app),
135-
app_entries, G_N_ELEMENTS(app_entries),
136-
app);
137+
app_entries, G_N_ELEMENTS(app_entries), app);
137138

138139
for (i = 0; i < G_N_ELEMENTS(accels); i++)
139140
gtk_application_set_accels_for_action(GTK_APPLICATION(app),
140141
accels[i].action_and_target, accels[i].accelerators);
141142
}
142143

143144
static void
144-
nip4_app_open(GApplication *app,
145+
app_open(GApplication *app,
145146
GFile **files, int n_files, const char *hint)
146147
{
147148
for(int i = 0; i < n_files; i++) {
@@ -153,34 +154,34 @@ nip4_app_open(GApplication *app,
153154
}
154155

155156
static void
156-
nip4_app_shutdown(GApplication *app)
157+
app_shutdown(GApplication *app)
157158
{
158159
MainWindow *win;
159160

160161
#ifdef DEBUG
161-
printf("nip4_app_shutdown:\n");
162+
printf("app_shutdown:\n");
162163
#endif /*DEBUG*/
163164

164165
/* Force down all our windows ... this will not happen automatically
165166
* on _quit().
166167
*/
167-
while ((win = nip4_app_win(APP(app))))
168+
while ((win = app_win(APP(app))))
168169
gtk_window_destroy(GTK_WINDOW(win));
169170

170-
G_APPLICATION_CLASS(nip4_app_parent_class)->shutdown(app);
171+
G_APPLICATION_CLASS(app_parent_class)->shutdown(app);
171172
}
172173

173174
static void
174-
nip4_app_class_init(Nip4AppClass *class)
175+
app_class_init(AppClass *class)
175176
{
176-
G_APPLICATION_CLASS(class)->startup = nip4_app_startup;
177-
G_APPLICATION_CLASS(class)->activate = nip4_app_activate;
178-
G_APPLICATION_CLASS(class)->open = nip4_app_open;
179-
G_APPLICATION_CLASS(class)->shutdown = nip4_app_shutdown;
177+
G_APPLICATION_CLASS(class)->startup = app_startup;
178+
G_APPLICATION_CLASS(class)->activate = app_activate;
179+
G_APPLICATION_CLASS(class)->open = app_open;
180+
G_APPLICATION_CLASS(class)->shutdown = app_shutdown;
180181
}
181182

182-
Nip4App *
183-
nip4_app_new(void)
183+
App *
184+
app_new(void)
184185
{
185186
return g_object_new(APP_TYPE,
186187
"application-id", APPLICATION_ID,

src/app.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __APP_H
2+
#define __APP_H
3+
4+
#define APP_TYPE (app_get_type())
5+
#define APP NIP4_APP
6+
7+
G_DECLARE_FINAL_TYPE(App, app, NIP4, APP, GtkApplication)
8+
9+
App *app_new(void);
10+
11+
#endif /* __APP_H */

src/gtk/mainwindow.ui

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,32 @@
1616
</section>
1717

1818
<section>
19-
<attribute name="display-hint">horizontal-buttons</attribute>
20-
<item>
21-
<attribute name="label">Previous page</attribute>
22-
<attribute name="action">win.prev</attribute>
23-
<attribute name="verb-icon">go-previous-symbolic</attribute>
24-
</item>
2519
<item>
26-
<attribute name="label">Next page</attribute>
27-
<attribute name="action">win.next</attribute>
28-
<attribute name="verb-icon">go-next-symbolic</attribute>
29-
</item>
30-
</section>
31-
32-
<section>
33-
<item>
34-
<attribute name='label' translatable='yes'>New window</attribute>
20+
<attribute name='label' translatable='yes'>New workspace</attribute>
3521
<attribute name='action'>app.new</attribute>
3622
</item>
3723
<item>
38-
<attribute name='label' translatable='yes'>Duplicate window</attribute>
24+
<attribute name='label' translatable='yes'>Duplicate workspace</attribute>
3925
<attribute name='action'>win.duplicate</attribute>
4026
</item>
4127
<item>
42-
<attribute name='label' translatable='yes'>Reload image</attribute>
43-
<attribute name='action'>win.reload</attribute>
44-
</item>
45-
<item>
46-
<attribute name='label' translatable='yes'>Replace image ...</attribute>
47-
<attribute name='action'>win.replace</attribute>
48-
</item>
49-
<item>
50-
<attribute name='label' translatable='yes'>Next image</attribute>
51-
<attribute name='action'>win.next_image</attribute>
52-
</item>
53-
<item>
54-
<attribute name='label' translatable='yes'>Previous image</attribute>
55-
<attribute name='action'>win.prev_image</attribute>
28+
<attribute name='label' translatable='yes'>Open workspace ...</attribute>
29+
<attribute name='action'>win.open</attribute>
5630
</item>
5731
</section>
5832

5933
<section>
6034
<item>
61-
<attribute name='label' translatable='yes'>Save as ...</attribute>
35+
<attribute name='label' translatable='yes'>Save workspace as ...</attribute>
6236
<attribute name='action'>win.saveas</attribute>
6337
</item>
6438
</section>
6539

6640
<section>
67-
<submenu>
68-
<attribute name="label">Zoom</attribute>
69-
<section>
70-
<item>
71-
<attribute name="label" translatable="yes">Zoom in</attribute>
72-
<attribute name="action">win.magin</attribute>
73-
</item>
74-
<item>
75-
<attribute name="label" translatable="yes">Zoom out</attribute>
76-
<attribute name="action">win.magout</attribute>
77-
</item>
78-
<item>
79-
<attribute name="label" translatable="yes">1:1</attribute>
80-
<attribute name="action">win.oneone</attribute>
81-
</item>
82-
<item>
83-
<attribute name="label" translatable="yes">Best fit</attribute>
84-
<attribute name="action">win.bestfit</attribute>
85-
</item>
86-
</section>
87-
</submenu>
88-
8941
<item>
9042
<attribute name="label" translatable="yes">Fullscreen</attribute>
9143
<attribute name="action">win.fullscreen</attribute>
9244
</item>
93-
<item>
94-
<attribute name="label" translatable="yes">Display control bar</attribute>
95-
<attribute name="action">win.control</attribute>
96-
</item>
97-
<item>
98-
<attribute name="label" translatable="yes">Info bar</attribute>
99-
<attribute name="action">win.info</attribute>
100-
</item>
101-
<item>
102-
<attribute name="label" translatable="yes">Properties</attribute>
103-
<attribute name="action">win.properties</attribute>
104-
</item>
10545
</section>
10646

10747
<section>
@@ -113,7 +53,7 @@
11353

11454
<section>
11555
<item>
116-
<attribute name='label' translatable='yes'>About vipsdisp</attribute>
56+
<attribute name='label' translatable='yes'>About nip4</attribute>
11757
<attribute name='action'>app.about</attribute>
11858
</item>
11959
</section>

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
int
88
main(int argc, char **argv)
99
{
10-
Nip4App *app;
10+
App *app;
1111
int status;
1212

1313
if (VIPS_INIT(argv[0]))
@@ -33,7 +33,7 @@ main(int argc, char **argv)
3333
printf("nip4.main: blocking VipsForeignLoadMagick\n");
3434
vips_operation_block_set("VipsForeignLoadMagick", TRUE);
3535

36-
app = nip4_app_new();
36+
app = app_new();
3737

3838
status = g_application_run(G_APPLICATION(app), argc, argv);
3939

0 commit comments

Comments
 (0)