767 | | status = fTextView->WriteStyledEditFile(&file); |
| 770 | if (fSavePanel != NULL && |
| 771 | fSavePanelFormatMenu->IndexOf(fSavePanelFormatMenu->FindMarked()) != 0) { |
| 772 | int selected = fSavePanelFormatMenu->IndexOf(fSavePanelFormatMenu->FindMarked()); |
| 773 | |
| 774 | BTranslatorRoster* roster = new BTranslatorRoster; |
| 775 | roster->AddTranslators(NULL); |
| 776 | |
| 777 | const translation_format* translator_out; |
| 778 | roster->GetOutputFormats(fSTXTTranslators[selected], |
| 779 | &translator_out, NULL); |
| 780 | |
| 781 | BPath cachePath; |
| 782 | status = find_directory(B_COMMON_CACHE_DIRECTORY, &cachePath); |
| 783 | BDirectory cacheDir(cachePath.Path()); |
| 784 | |
| 785 | BEntry cacheEntry(&cacheDir, ".stylededitcache"); |
| 786 | BFile cache(&cacheEntry, B_READ_WRITE | B_CREATE_FILE); |
| 787 | |
| 788 | if (cacheEntry.InitCheck() != B_OK) { |
| 789 | BString alertText; |
| 790 | bs_printf(&alertText, B_TRANSLATE( |
| 791 | "Error creating cache file for export \"%s\":\n%s"), |
| 792 | name, strerror(status)); |
| 793 | |
| 794 | _ShowAlert(alertText, B_TRANSLATE("OK"), "", "", B_STOP_ALERT); |
| 795 | return status; |
| 796 | } |
| 797 | |
| 798 | status = fTextView->WriteStyledEditFile(&cache); |
| 799 | |
| 800 | if (status != B_OK) { |
| 801 | BString alertText; |
| 802 | bs_printf(&alertText, B_TRANSLATE( |
| 803 | "Error writing cache file for export \"%s\":\n%s"), |
| 804 | name, strerror(status)); |
| 805 | |
| 806 | _ShowAlert(alertText, B_TRANSLATE("OK"), "", "", B_STOP_ALERT); |
| 807 | return status; |
| 808 | } |
| 809 | |
| 810 | status = roster->Translate(fSTXTTranslators[selected], |
| 811 | &cache, NULL, &file, translator_out[0].type); |
| 812 | cacheEntry.Remove(); |
| 813 | |
| 814 | if (status != B_OK) { |
| 815 | BString alertText; |
| 816 | bs_printf(&alertText, B_TRANSLATE("Error exporting \"%s\":\n%s"), name, |
| 817 | strerror(status)); |
| 818 | |
| 819 | _ShowAlert(alertText, B_TRANSLATE("OK"), "", "", B_STOP_ALERT); |
| 820 | return status; |
| 821 | } |
| 822 | } |
| 823 | else |
| 824 | status = fTextView->WriteStyledEditFile(&file); |
| 903 | |
| 904 | // File format menu |
| 905 | fSavePanelFormatMenu = new BMenu(B_TRANSLATE("Document format")); |
| 906 | fSavePanelFormatMenu->SetRadioMode(true); |
| 907 | menuBar->AddItem(fSavePanelFormatMenu); |
| 908 | |
| 909 | BMenuItem* item = new BMenuItem(B_TRANSLATE("STXT (default)"), |
| 910 | new BMessage()); |
| 911 | item->SetMarked(true); |
| 912 | fSavePanelFormatMenu->AddItem(item); |
| 913 | |
| 914 | BTranslatorRoster* troster = new BTranslatorRoster; |
| 915 | troster->AddTranslators(NULL); |
| 916 | |
| 917 | int32 num_translators, num_formats; |
| 918 | translator_id* translators; |
| 919 | const char* translator_name; |
| 920 | const translation_format* translator_formats; |
| 921 | |
| 922 | fSTXTTranslators.push_back(NULL); |
| 923 | |
| 924 | troster->GetAllTranslators(&translators, &num_translators); |
| 925 | |
| 926 | for (int32 i = 0; i<num_translators; i++) { |
| 927 | troster->GetTranslatorInfo(translators[i], &translator_name, |
| 928 | NULL, NULL); |
| 929 | troster->GetInputFormats(translators[i], &translator_formats, |
| 930 | &num_formats); |
| 931 | |
| 932 | bool isSTXT = false; |
| 933 | for (int32 ix = 0; ix<num_formats; ix++) { |
| 934 | if (translator_formats[ix].type == B_TRANSLATOR_TEXT) { |
| 935 | isSTXT = true; |
| 936 | break; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | if (isSTXT) { |
| 941 | fSTXTTranslators.push_back(translators[i]); |
| 942 | BMenuItem* titem = new BMenuItem(translator_name, |
| 943 | new BMessage()); |
| 944 | fSavePanelFormatMenu->AddItem(titem); |
| 945 | } |
| 946 | } |