Ticket #9394: SE-Export.diff

File SE-Export.diff, 5.2 KB (added by siarzhuk, 11 years ago)

Most actual version of Export feature support implemented during GCI2012

  • src/apps/stylededit/StyledEditWindow.cpp

    commit 035bc0a0e3f6360146b533289a14100b1d158341
    Author: Przemysław Buczkowski <przemub@yahoo.pl>
    Date:   Thu Jan 10 19:24:19 2013 +0100
    
        in progress
    
    diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp
    index 3193bcf..55c15e7 100644
    a b  
    3131#include <Debug.h>
    3232#include <File.h>
    3333#include <FilePanel.h>
     34#include <FindDirectory.h>
    3435#include <fs_attr.h>
    3536#include <Locale.h>
    3637#include <Menu.h>
     
    4647#include <TextControl.h>
    4748#include <TextView.h>
    4849#include <TranslationUtils.h>
     50#include <TranslatorFormats.h>
     51#include <TranslatorRoster.h>
    4952#include <UnicodeChar.h>
    5053
    5154
    StyledEditWindow::Save(BMessage* message)  
    764767                }
    765768            }
    766769
    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);
    768825        }
    769826    }
    770827
    StyledEditWindow::SaveAs(BMessage* message)  
    821878        BMenuBar* menuBar = dynamic_cast<BMenuBar*>(
    822879            fSavePanel->Window()->FindView("MenuBar"));
    823880        if (menuBar != NULL) {
     881            // Encoding menu
    824882            fSavePanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding"));
    825883            fSavePanelEncodingMenu->SetRadioMode(true);
    826884            menuBar->AddItem(fSavePanelEncodingMenu);
    StyledEditWindow::SaveAs(BMessage* message)  
    842900                if (charset.GetFontID() == fTextView->GetEncoding())
    843901                    item->SetMarked(true);
    844902            }
     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            }
    845947        }
    846948    }
    847949
    StyledEditWindow::_InitWindow(uint32 encoding)  
    13001402
    13011403    fSavePanel = NULL;
    13021404    fSavePanelEncodingMenu = NULL;
     1405    fSavePanelFormatMenu = NULL;
    13031406        // build lazily
    13041407}
    13051408
  • src/apps/stylededit/StyledEditWindow.h

    diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h
    index ae8aac3..d9144a6 100644
    a b  
    1515#include <Node.h>
    1616#include <Window.h>
    1717
     18#include <vector>
     19
    1820struct entry_ref;
     21typedef long unsigned int translator_id;
    1922
    2023class BFilePanel;
    2124class BMenu;
    private:  
    166169
    167170            BFilePanel*         fSavePanel;
    168171            BMenu*              fSavePanelEncodingMenu;
     172            BMenu*              fSavePanelFormatMenu;
     173            vector <translator_id>  fSTXTTranslators;
    169174                // node monitoring
    170175            node_ref            fNodeRef;
    171176            node_ref            fFolderNodeRef;