-
Notifications
You must be signed in to change notification settings - Fork 10
/
pp_menu_file.cpp
188 lines (150 loc) · 5.13 KB
/
pp_menu_file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <iostream>
#include <gtk/gtkstock.h>
#include <gtk/gtkmain.h>
#include "config.h"
#include "pp_menu_file.h"
#include "errordialogqueue.h"
#include "pp_mainwindow.h"
#include "dialogs.h"
#include "printpreview.h"
#include "miscwidgets/generaldialogs.h"
#include "progressbar.h"
#include "pathsupport.h"
#include "config.h"
#include "gettext.h"
#define _(x) gettext(x)
#define N_(x) gettext_noop(x)
using namespace std;
static void savegeometry(pp_MainWindow *mw)
{
gint x,y,w,h;
gtk_window_get_position(GTK_WINDOW(mw),&x,&y);
gtk_window_get_size(GTK_WINDOW(mw),&w,&h);
mw->state->SetInt("Win_X",x);
mw->state->SetInt("Win_Y",y);
mw->state->SetInt("Win_W",w);
mw->state->SetInt("Win_H",h);
}
static void file_open_preset(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
char *filename=File_Dialog(_("Open preset..."),mw->state->filename);
mw->state->layout->FlushHRPreviews();
if(filename)
{
mw->state->SetFilename(filename);
mw->state->ParseConfigFile();
g_free(filename);
pp_mainwindow_rebuild(mw);
}
}
static void file_save_preset(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
savegeometry(mw);
mw->state->SaveConfigFile();
}
static void file_save_as(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
savegeometry(mw);
char *filename=File_Save_Dialog(_("Save preset..."),mw->state->filename,GTK_WIDGET(&mw->window));
if(filename)
{
mw->state->SetFilename(filename);
mw->state->SaveConfigFile();
g_free(filename);
}
}
static void file_save_default(GtkWidget *wid,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
savegeometry(mw);
mw->state->SetDefaultFilename();
mw->state->SaveConfigFile();
}
static void file_export_tiff(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
ExportTiff_Dialog(GTK_WINDOW(mw),*mw->state);
}
static void file_export_jpeg(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
ExportJPEG_Dialog(GTK_WINDOW(mw),*mw->state);
}
static void file_print_setup(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
PrintSetup_Dialog(GTK_WINDOW(mw),*mw->state);
pp_mainwindow_refresh(mw);
}
static void file_print_preview(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
PrintPreview_Dialog(GTK_WINDOW(mw),*mw->state);
}
static void file_print(GtkAction *action,gpointer *ob)
{
pp_MainWindow *mw=(pp_MainWindow *)ob;
ProgressBar p(_("Generating print data..."),true,GTK_WIDGET(mw));
try
{
mw->state->layout->Print(&p);
}
catch (const char *err)
{
ErrorMessage_Dialog(err,GTK_WIDGET(mw));
}
}
static void file_quit(GtkAction *action,gpointer ob)
{
gtk_main_quit();
}
static GtkActionEntry filemenu_entries[] = {
{ "FileMenu", NULL, N_("_File") },
{ "OpenPreset", GTK_STOCK_OPEN, N_("_Open Preset..."), "<control>O", N_("Open a preset"), G_CALLBACK(file_open_preset) },
{ "SavePreset", GTK_STOCK_SAVE, N_("_Save Preset"), "<control>S", N_("Save a preset"), G_CALLBACK(file_save_preset) },
{ "SaveAs", NULL, N_("Save _As..."), NULL, N_("Save preset with a new filename"), G_CALLBACK(file_save_as) },
{ "SaveDefault", NULL, N_("Save _Default"), NULL, N_("Save preset as the default"), G_CALLBACK(file_save_default) },
{ "ExportMenu", NULL, N_("E_xport") },
{ "ExportTiff", NULL, N_("Export _TIFF..."), NULL, N_("Export pages as TIFF files"), G_CALLBACK(file_export_tiff) },
{ "ExportJPEG", NULL, N_("Export _JPEG..."), NULL, N_("Export pages as JPEG files"), G_CALLBACK(file_export_jpeg) },
{ "PrintPreview", NULL, N_("Print Pre_view..."), NULL, N_("Preview how the printed page will look"), G_CALLBACK(file_print_preview) },
{ "PrintSetup", NULL, N_("Print S_etup..."), NULL, N_("Set printer driver and options"), G_CALLBACK(file_print_setup) },
{ "Print", GTK_STOCK_PRINT, N_("_Print"), "<control>P", N_("Print pages"), G_CALLBACK(file_print) },
{ "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q", N_("Exit PhotoPrint"), G_CALLBACK(file_quit)},
};
static const char *filemenu_ui_description =
"<ui>"
" <menubar name='MainMenu'>"
" <menu action='FileMenu'>"
" <menuitem action='OpenPreset'/>"
" <menuitem action='SavePreset'/>"
" <menuitem action='SaveAs'/>"
" <menuitem action='SaveDefault'/>"
" <separator/>"
" <menu action='ExportMenu'>"
" <menuitem action='ExportTiff'/>"
" <menuitem action='ExportJPEG'/>"
" </menu>"
" <separator/>"
" <menuitem action='PrintSetup'/>"
" <menuitem action='PrintPreview'/>"
" <menuitem action='Print'/>"
" <separator/>"
" <menuitem action='Quit'/>"
" </menu>"
" </menubar>"
"</ui>";
void BuildFileMenu(void *userdata,GtkUIManager *ui_manager)
{
GError *error=NULL;
GtkActionGroup *action_group;
action_group = gtk_action_group_new ("FileMenuActions");
gtk_action_group_set_translation_domain(action_group,PACKAGE);
gtk_action_group_add_actions (action_group, filemenu_entries, G_N_ELEMENTS (filemenu_entries), userdata);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
if (!gtk_ui_manager_add_ui_from_string (ui_manager, filemenu_ui_description, -1, &error))
throw error->message;
}