Save as & global header
This commit is contained in:
parent
04f9086315
commit
22f249b10a
73
source/app.d
73
source/app.d
@ -24,6 +24,7 @@ import gtk.HBox;
|
|||||||
|
|
||||||
__gshared MainWindow window;
|
__gshared MainWindow window;
|
||||||
__gshared HBox statusbar;
|
__gshared HBox statusbar;
|
||||||
|
__gshared Object header;
|
||||||
|
|
||||||
void main(string[] args)
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
@ -41,6 +42,7 @@ void main(string[] args)
|
|||||||
|
|
||||||
version(Windows){
|
version(Windows){
|
||||||
auto buttonSave = new Button(StockID.SAVE, true);
|
auto buttonSave = new Button(StockID.SAVE, true);
|
||||||
|
auto buttonSaveAs = new Button(StockID.SAVE_AS, true);
|
||||||
auto buttonOpen = new Button(StockID.OPEN, true);
|
auto buttonOpen = new Button(StockID.OPEN, true);
|
||||||
auto buttonInsert = new Button(StockID.JUMP_TO, true);
|
auto buttonInsert = new Button(StockID.JUMP_TO, true);
|
||||||
auto buttonDelete = new Button(StockID.DELETE, true);
|
auto buttonDelete = new Button(StockID.DELETE, true);
|
||||||
@ -49,6 +51,7 @@ void main(string[] args)
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
auto buttonSave = new Button("document-save-symbolic", GtkIconSize.MENU);
|
auto buttonSave = new Button("document-save-symbolic", GtkIconSize.MENU);
|
||||||
|
auto buttonSaveAs = new Button("document-save-as-symbolic", GtkIconSize.MENU);
|
||||||
auto buttonOpen = new Button("document-open-symbolic", GtkIconSize.MENU);
|
auto buttonOpen = new Button("document-open-symbolic", GtkIconSize.MENU);
|
||||||
auto buttonInsert = new Button("format-text-direction-ltr-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
auto buttonInsert = new Button("format-text-direction-ltr-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
||||||
auto buttonDelete = new Button("user-trash-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
auto buttonDelete = new Button("user-trash-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
||||||
@ -56,35 +59,40 @@ void main(string[] args)
|
|||||||
auto buttonNewCol = new Button("tab-new-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
auto buttonNewCol = new Button("tab-new-symbolic", GtkIconSize.SMALL_TOOLBAR);
|
||||||
}
|
}
|
||||||
buttonSave.setTooltipText("Save");
|
buttonSave.setTooltipText("Save");
|
||||||
enum GDK_KEY_S = 0x053;
|
buttonSaveAs.setTooltipText("Save as");
|
||||||
buttonSave.addAccelerator("clicked", accel, GDK_KEY_S, GdkModifierType.CONTROL_MASK, GtkAccelFlags.VISIBLE);
|
|
||||||
buttonOpen.setTooltipText("Open 2DA");
|
buttonOpen.setTooltipText("Open 2DA");
|
||||||
buttonInsert.setTooltipText("Insert row after");
|
buttonInsert.setTooltipText("Insert row after");
|
||||||
buttonDelete.setTooltipText("Delete row");
|
buttonDelete.setTooltipText("Delete row");
|
||||||
buttonRenumber.setTooltipText("Renumber all rows");
|
buttonRenumber.setTooltipText("Renumber all rows");
|
||||||
buttonNewCol.setTooltipText("Add new column");
|
buttonNewCol.setTooltipText("Add new column");
|
||||||
|
|
||||||
|
enum GDK_KEY_S = 0x053;
|
||||||
|
buttonSave.addAccelerator("clicked", accel, GDK_KEY_S, GdkModifierType.CONTROL_MASK, GtkAccelFlags.VISIBLE);
|
||||||
|
buttonSaveAs.addAccelerator("clicked", accel, GDK_KEY_S, GdkModifierType.CONTROL_MASK|GdkModifierType.SHIFT_MASK, GtkAccelFlags.VISIBLE);
|
||||||
|
|
||||||
version(Windows){
|
version(Windows){
|
||||||
//Menu bar
|
//Menu bar
|
||||||
import gtk.HBox;
|
import gtk.HBox;
|
||||||
|
|
||||||
auto cont2 = new HBox(false, 0);
|
header = new HBox(false, 0);
|
||||||
cont.packStart(cont2, false, false, 0);
|
cont.packStart(header, false, false, 0);
|
||||||
|
|
||||||
cont2.packStart(buttonOpen, false, false, 0);
|
header.packStart(buttonOpen, false, false, 0);
|
||||||
cont2.packEnd(buttonSave, false, false, 0);
|
header.packEnd(buttonSaveAs, false, false, 0);
|
||||||
|
header.packEnd(buttonSave, false, false, 0);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//Header bar
|
//Header bar
|
||||||
import gtk.HeaderBar;
|
import gtk.HeaderBar;
|
||||||
|
|
||||||
auto header = new HeaderBar();
|
header = new HeaderBar();
|
||||||
window.setTitlebar(header);
|
window.setTitlebar(cast(HeaderBar)header);
|
||||||
header.setTitle("2DAEdit");
|
(cast(HeaderBar)header).setTitle("2DAEdit");
|
||||||
header.setProperty("show-close-button", true);
|
(cast(HeaderBar)header).setProperty("show-close-button", true);
|
||||||
|
|
||||||
header.packStart(buttonOpen);
|
(cast(HeaderBar)header).packStart(buttonOpen);
|
||||||
header.packEnd(buttonSave);
|
(cast(HeaderBar)header).packEnd(buttonSaveAs);
|
||||||
|
(cast(HeaderBar)header).packEnd(buttonSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Status bar
|
//Status bar
|
||||||
@ -128,6 +136,18 @@ void main(string[] args)
|
|||||||
buttonSave.addOnClicked((Button){
|
buttonSave.addOnClicked((Button){
|
||||||
Save(tree);
|
Save(tree);
|
||||||
});
|
});
|
||||||
|
buttonSaveAs.addOnClicked((Button){
|
||||||
|
import gtk.Dialog;
|
||||||
|
import gtk.FileChooserDialog;
|
||||||
|
|
||||||
|
auto fc = new FileChooserDialog("Save 2DA as", window, FileChooserAction.SAVE);
|
||||||
|
auto res = fc.run();
|
||||||
|
if(res==GtkResponseType.OK){
|
||||||
|
string filename = fc.getFilename();
|
||||||
|
Save(tree, filename);
|
||||||
|
}
|
||||||
|
fc.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
buttonOpen.addOnClicked((Button){
|
buttonOpen.addOnClicked((Button){
|
||||||
import gtk.Dialog;
|
import gtk.Dialog;
|
||||||
@ -137,8 +157,7 @@ void main(string[] args)
|
|||||||
auto res = fc.run();
|
auto res = fc.run();
|
||||||
if(res==GtkResponseType.OK){
|
if(res==GtkResponseType.OK){
|
||||||
string filename = fc.getFilename();
|
string filename = fc.getFilename();
|
||||||
version(Windows) Open(filename, tree, cast(Object)window);
|
Open(filename, tree);
|
||||||
else Open(filename, tree, cast(Object)header);
|
|
||||||
}
|
}
|
||||||
fc.destroy();
|
fc.destroy();
|
||||||
});
|
});
|
||||||
@ -230,8 +249,7 @@ void main(string[] args)
|
|||||||
|
|
||||||
//Open if exists
|
//Open if exists
|
||||||
if(args.length>=2 && exists(args[1])){
|
if(args.length>=2 && exists(args[1])){
|
||||||
version(Windows) Open(args[1], tree, cast(Object)window);
|
Open(args[1], tree);
|
||||||
else Open(args[1], tree, cast(Object)header);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.showAll();
|
window.showAll();
|
||||||
@ -273,9 +291,13 @@ void SaySomething(string msg){
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Save(ref TreeView tree){
|
void Save(ref TreeView tree, string newpath=""){
|
||||||
auto store = cast(ListStore)tree.getModel();
|
auto store = cast(ListStore)tree.getModel();
|
||||||
if(store !is null){
|
if(store !is null){
|
||||||
|
if(newpath!=""){
|
||||||
|
openedFile = newpath;
|
||||||
|
SetTitle(openedFile);
|
||||||
|
}
|
||||||
|
|
||||||
auto file = File(openedFile, "w");
|
auto file = File(openedFile, "w");
|
||||||
|
|
||||||
@ -303,18 +325,21 @@ void Save(ref TreeView tree){
|
|||||||
SaySomething("Nothing to save !");
|
SaySomething("Nothing to save !");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetTitle(string title){
|
||||||
|
version(Windows) (cast(MainWindow)header).setTitle(title);
|
||||||
|
else{
|
||||||
|
import gtk.HeaderBar;
|
||||||
|
(cast(HeaderBar)header).setSubtitle(title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string openedFile;
|
string openedFile;
|
||||||
void Open(string file, ref TreeView tree, Object header){
|
void Open(string file, ref TreeView tree){
|
||||||
|
|
||||||
auto twoda = new TwoDA(file);
|
auto twoda = new TwoDA(file);
|
||||||
|
|
||||||
openedFile = file;
|
openedFile = file;
|
||||||
|
SetTitle(openedFile);
|
||||||
version(Windows) (cast(MainWindow)header).setTitle(file);
|
|
||||||
else{
|
|
||||||
import gtk.HeaderBar;
|
|
||||||
(cast(HeaderBar)header).setSubtitle(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete old store
|
//Delete old store
|
||||||
auto oldstore = cast(ListStore)tree.getModel();
|
auto oldstore = cast(ListStore)tree.getModel();
|
||||||
|
Loading…
Reference in New Issue
Block a user