| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629 |
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
- //
- // Authors:
- //
- // Alexander Olk [email protected]
- //
- // NOT COMPLETE - work in progress
- using System;
- using System.Drawing;
- using System.ComponentModel;
- using System.Resources;
- using System.IO;
- using System.Collections;
- using System.Collections.Specialized;
- using System.Xml;
- using System.Threading;
- namespace System.Windows.Forms {
- #region FileDialog
- [DefaultProperty ("FileName")]
- [DefaultEvent ("FileOk")]
- public abstract class FileDialog : CommonDialog
- {
- protected static readonly object EventFileOk = new object ();
-
- internal enum FileDialogType
- {
- OpenFileDialog,
- SaveFileDialog
- }
-
- private bool addExtension = true;
- private bool checkFileExists = false;
- private bool checkPathExists = true;
- private string defaultExt = String.Empty;
- private bool dereferenceLinks = true;
- private string fileName = String.Empty;
- private string[] fileNames;
- private string filter = "";
- private int filterIndex = 1;
- private string initialDirectory = String.Empty;
- private bool restoreDirectory = false;
- private bool showHelp = false;
- private string title = String.Empty;
- private bool validateNames = true;
-
- private Button cancelButton;
- private ToolBarButton upToolBarButton;
- private PopupButtonPanel popupButtonPanel;
- private Button openSaveButton;
- private Button helpButton;
- private Label fileTypeLabel;
- private ToolBarButton menueToolBarButton;
- private ContextMenu menueToolBarButtonContextMenu;
- private ToolBar smallButtonToolBar;
- private DirComboBox dirComboBox;
- private ComboBox fileNameComboBox;
- private Label fileNameLabel;
- private MWFFileView mwfFileView;
- private Label searchSaveLabel;
- private ToolBarButton newdirToolBarButton;
- private ToolBarButton backToolBarButton;
- private ComboBox fileTypeComboBox;
- private ImageList imageListTopToolbar;
- private CheckBox readonlyCheckBox;
-
- private bool multiSelect = false;
-
- private string restoreDirectoryString = String.Empty;
-
- internal FileDialogType fileDialogType;
-
- private bool do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
-
- private bool showReadOnly = false;
- private bool readOnlyChecked = false;
- internal bool createPrompt = false;
- internal bool overwritePrompt = true;
-
- internal FileFilter fileFilter;
-
- private string lastFolder = String.Empty;
-
- private MWFVFS vfs;
-
- private readonly string filedialog_string = "FileDialog";
- private readonly string lastfolder_string = "LastFolder";
- private readonly string width_string = "Width";
- private readonly string height_string = "Height";
- private readonly string filenames_string = "FileNames";
- private readonly string x_string = "X";
- private readonly string y_string = "Y";
-
- internal FileDialog ()
- {
- vfs = new MWFVFS ();
-
- Size formConfigSize = Size.Empty;
- Point formConfigLocation = Point.Empty;
- string[] configFileNames = null;
-
- object formWidth = MWFConfig.GetValue (filedialog_string, width_string);
-
- object formHeight = MWFConfig.GetValue (filedialog_string, height_string);
-
- if (formHeight != null && formWidth != null)
- formConfigSize = new Size ((int)formWidth, (int)formHeight);
-
- object formLocationX = MWFConfig.GetValue (filedialog_string, x_string);
- object formLocationY = MWFConfig.GetValue (filedialog_string, y_string);
-
- if (formLocationX != null && formLocationY != null)
- formConfigLocation = new Point ((int)formLocationX, (int)formLocationY);
-
- configFileNames = (string[])MWFConfig.GetValue (filedialog_string, filenames_string);
-
- fileTypeComboBox = new ComboBox ();
- backToolBarButton = new ToolBarButton ();
- newdirToolBarButton = new ToolBarButton ();
- searchSaveLabel = new Label ();
- mwfFileView = new MWFFileView (vfs);
- fileNameLabel = new Label ();
- fileNameComboBox = new ComboBox ();
- dirComboBox = new DirComboBox (vfs);
- smallButtonToolBar = new ToolBar ();
- menueToolBarButton = new ToolBarButton ();
- fileTypeLabel = new Label ();
- openSaveButton = new Button ();
- form.AcceptButton = openSaveButton;
- helpButton = new Button ();
- popupButtonPanel = new PopupButtonPanel ();
- upToolBarButton = new ToolBarButton ();
- cancelButton = new Button ();
- form.CancelButton = cancelButton;
- imageListTopToolbar = new ImageList ();
- menueToolBarButtonContextMenu = new ContextMenu ();
- readonlyCheckBox = new CheckBox ();
-
- form.SuspendLayout ();
-
- //imageListTopToolbar
- imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
- imageListTopToolbar.ImageSize = new Size (16, 16); // 16, 16
- imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-previous.png"));
- imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-top.png"));
- imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("folder-new.png"));
- imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("preferences-system-windows.png"));
- imageListTopToolbar.TransparentColor = Color.Transparent;
-
- // searchLabel
- searchSaveLabel.FlatStyle = FlatStyle.System;
- searchSaveLabel.Location = new Point (7, 8);
- searchSaveLabel.Size = new Size (72, 21);
- searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
-
- // dirComboBox
- dirComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
- dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- dirComboBox.Location = new Point (99, 8);
- dirComboBox.Size = new Size (260, 21);
- dirComboBox.TabIndex = 7;
-
- // smallButtonToolBar
- smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
- smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
- smallButtonToolBar.AutoSize = false;
- smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
- backToolBarButton,
- upToolBarButton,
- newdirToolBarButton,
- menueToolBarButton});
- smallButtonToolBar.ButtonSize = new Size (24, 24); // 21, 16
- smallButtonToolBar.Divider = false;
- smallButtonToolBar.Dock = DockStyle.None;
- smallButtonToolBar.DropDownArrows = true;
- smallButtonToolBar.ImageList = imageListTopToolbar;
- smallButtonToolBar.Location = new Point (372, 6);
- smallButtonToolBar.ShowToolTips = true;
- smallButtonToolBar.Size = new Size (140, 28);
- smallButtonToolBar.TabIndex = 8;
- smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
-
- // buttonPanel
- popupButtonPanel.Dock = DockStyle.None;
- popupButtonPanel.Location = new Point (7, 37);
- popupButtonPanel.TabIndex = 9;
-
- // mwfFileView
- mwfFileView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
- mwfFileView.Location = new Point (99, 37);
- mwfFileView.Size = new Size (449, 282);
- mwfFileView.Columns.Add (" Name", 170, HorizontalAlignment.Left);
- mwfFileView.Columns.Add ("Size ", 80, HorizontalAlignment.Right);
- mwfFileView.Columns.Add (" Type", 100, HorizontalAlignment.Left);
- mwfFileView.Columns.Add (" Last Access", 150, HorizontalAlignment.Left);
- mwfFileView.AllowColumnReorder = true;
- mwfFileView.MultiSelect = false;
- mwfFileView.TabIndex = 10;
- mwfFileView.RegisterSender (dirComboBox);
- mwfFileView.RegisterSender (popupButtonPanel);
-
- // fileNameLabel
- fileNameLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
- fileNameLabel.FlatStyle = FlatStyle.System;
- fileNameLabel.Location = new Point (102, 330);
- fileNameLabel.Size = new Size (70, 21);
- fileNameLabel.Text = "Filename:";
- fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
-
- // fileNameComboBox
- fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
- fileNameComboBox.Location = new Point (195, 330);
- fileNameComboBox.Size = new Size (245, 21);
- fileNameComboBox.TabIndex = 1;
- fileNameComboBox.MaxDropDownItems = 10;
- fileNameComboBox.Items.Add (" ");
-
- if (configFileNames != null) {
- fileNameComboBox.Items.Clear ();
-
- foreach (string configFileName in configFileNames) {
- if (configFileName != null)
- if (configFileName.Trim ().Length > 0)
- fileNameComboBox.Items.Add (configFileName);
- }
- }
-
-
- // fileTypeLabel
- fileTypeLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
- fileTypeLabel.FlatStyle = FlatStyle.System;
- fileTypeLabel.Location = new Point (102, 356);
- fileTypeLabel.Size = new Size (70, 21);
- fileTypeLabel.Text = "Filetype:";
- fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
-
- // fileTypeComboBox
- fileTypeComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
- fileTypeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- fileTypeComboBox.Location = new Point (195, 356);
- fileTypeComboBox.Size = new Size (245, 21);
- fileTypeComboBox.TabIndex = 2;
-
- // backToolBarButton
- backToolBarButton.ImageIndex = 0;
- backToolBarButton.Enabled = false;
- backToolBarButton.Style = ToolBarButtonStyle.PushButton;
- mwfFileView.AddControlToEnableDisableByDirStack (backToolBarButton);
-
- // upToolBarButton
- upToolBarButton.ImageIndex = 1;
- upToolBarButton.Style = ToolBarButtonStyle.PushButton;
- mwfFileView.SetFolderUpToolBarButton (upToolBarButton);
-
- // newdirToolBarButton
- newdirToolBarButton.ImageIndex = 2;
- newdirToolBarButton.Style = ToolBarButtonStyle.PushButton;
-
- // menueToolBarButton
- menueToolBarButton.ImageIndex = 3;
- menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
- menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
-
- // menueToolBarButtonContextMenu
- menueToolBarButtonContextMenu.MenuItems.AddRange (mwfFileView.ViewMenuItems);
-
- // openSaveButton
- openSaveButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
- openSaveButton.FlatStyle = FlatStyle.System;
- openSaveButton.Location = new Point (475, 330);
- openSaveButton.Size = new Size (72, 21);
- openSaveButton.TabIndex = 4;
- openSaveButton.FlatStyle = FlatStyle.System;
-
- // cancelButton
- cancelButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
- cancelButton.FlatStyle = FlatStyle.System;
- cancelButton.Location = new Point (475, 356);
- cancelButton.Size = new Size (72, 21);
- cancelButton.TabIndex = 5;
- cancelButton.Text = "Cancel";
- cancelButton.FlatStyle = FlatStyle.System;
-
- // helpButton
- helpButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
- helpButton.FlatStyle = FlatStyle.System;
- helpButton.Location = new Point (475, 350);
- helpButton.Size = new Size (72, 21);
- helpButton.TabIndex = 6;
- helpButton.Text = "Help";
- helpButton.FlatStyle = FlatStyle.System;
-
- // checkBox
- readonlyCheckBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
- readonlyCheckBox.Text = "Open Readonly";
- readonlyCheckBox.Location = new Point (195, 350);
- readonlyCheckBox.Size = new Size (245, 21);
- readonlyCheckBox.TabIndex = 3;
- readonlyCheckBox.FlatStyle = FlatStyle.System;
-
- form.SizeGripStyle = SizeGripStyle.Show;
-
- form.MaximizeBox = true;
- form.MinimizeBox = true;
- form.FormBorderStyle = FormBorderStyle.Sizable;
- form.MinimumSize = new Size (554, 405);
-
- form.ClientSize = new Size (554, 405); // 384
-
- form.Controls.Add (smallButtonToolBar);
- form.Controls.Add (cancelButton);
- form.Controls.Add (openSaveButton);
- form.Controls.Add (mwfFileView);
- form.Controls.Add (fileTypeLabel);
- form.Controls.Add (fileNameLabel);
- form.Controls.Add (fileTypeComboBox);
- form.Controls.Add (fileNameComboBox);
- form.Controls.Add (dirComboBox);
- form.Controls.Add (searchSaveLabel);
- form.Controls.Add (popupButtonPanel);
-
- form.ResumeLayout (false);
-
- if (formConfigSize != Size.Empty) {
- form.Size = formConfigSize;
- }
-
- if (formConfigLocation != Point.Empty) {
- form.Location = formConfigLocation;
- }
-
- openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
- cancelButton.Click += new EventHandler (OnClickCancelButton);
- helpButton.Click += new EventHandler (OnClickHelpButton);
-
- smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler (OnClickSmallButtonToolBar);
-
- fileTypeComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedFileTypeComboBox);
-
- mwfFileView.SelectedFileChanged += new EventHandler (OnSelectedFileChangedFileView);
- mwfFileView.ForceDialogEnd += new EventHandler (OnForceDialogEndFileView);
- mwfFileView.SelectedFilesChanged += new EventHandler (OnSelectedFilesChangedFileView);
-
- dirComboBox.DirectoryChanged += new EventHandler (OnDirectoryChangedDirComboBox);
- popupButtonPanel.DirectoryChanged += new EventHandler (OnDirectoryChangedPopupButtonPanel);
-
- readonlyCheckBox.CheckedChanged += new EventHandler (OnCheckCheckChanged);
- }
-
- [DefaultValue(true)]
- public bool AddExtension {
- get {
- return addExtension;
- }
-
- set {
- addExtension = value;
- }
- }
-
- [DefaultValue(false)]
- public virtual bool CheckFileExists {
- get {
- return checkFileExists;
- }
-
- set {
- checkFileExists = value;
- }
- }
-
- [DefaultValue(true)]
- public bool CheckPathExists {
- get {
- return checkPathExists;
- }
-
- set {
- checkPathExists = value;
- }
- }
-
- [DefaultValue("")]
- public string DefaultExt {
- get {
- return defaultExt;
- }
-
- set {
- defaultExt = value;
-
- // if there is a dot remove it and everything before it
- if (defaultExt.LastIndexOf ('.') != - 1) {
- string[] split = defaultExt.Split (new char [] { '.' });
- defaultExt = split [split.Length - 1];
- }
- }
- }
-
- // in MS.NET it doesn't make a difference if
- // DerefenceLinks is true or false
- // if the selected file is a link FileDialog
- // always returns the link
- [DefaultValue(true)]
- public bool DereferenceLinks {
- get {
- return dereferenceLinks;
- }
-
- set {
- dereferenceLinks = value;
- }
- }
-
- [DefaultValue("")]
- public string FileName {
- get {
- return fileName;
- }
-
- set {
- if (value != null) {
- if (SetFileName (value)) {
- fileName = value;
- if (fileNames == null) {
- fileNames = new string [1];
- fileNames [0] = value;
- }
- }
- } else {
- fileName = String.Empty;
- fileNames = new string [0];
- // this does not match ms exactly,
- // but there is no other way to clear that %#&?§ combobox
- fileNameComboBox.Text = " ";
- }
- }
- }
-
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public string[] FileNames {
- get {
- if (fileNames == null || fileNames.Length == 0) {
- string[] null_nada_nothing_filenames = new string [0];
- return null_nada_nothing_filenames;
- }
-
- string[] new_filenames = new string [fileNames.Length];
- fileNames.CopyTo (new_filenames, 0);
- return new_filenames;
- }
- }
-
- [DefaultValue("")]
- [Localizable(true)]
- public string Filter {
- get {
- return filter;
- }
-
- set {
- if (value == null) {
- filter = "";
- if (fileFilter != null)
- fileFilter.FilterArrayList.Clear ();
- } else {
- if (FileFilter.CheckFilter (value)) {
- filter = value;
-
- fileFilter = new FileFilter (filter);
- } else
- throw new ArgumentException ();
- }
-
- UpdateFilters ();
- }
- }
-
- [DefaultValue(1)]
- public int FilterIndex {
- get {
- return filterIndex;
- }
-
- set {
- filterIndex = value;
-
- SelectFilter ();
- }
- }
-
- [DefaultValue("")]
- public string InitialDirectory {
- get {
- return initialDirectory;
- }
-
- set {
- if (Directory.Exists (value)) {
- initialDirectory = value;
-
- mwfFileView.ChangeDirectory (null, initialDirectory);
- }
- }
- }
-
- [DefaultValue(false)]
- public bool RestoreDirectory {
- get {
- return restoreDirectory;
- }
-
- set {
- restoreDirectory = value;
- }
- }
-
- [DefaultValue(false)]
- public bool ShowHelp {
- get {
- return showHelp;
- }
-
- set {
- showHelp = value;
- ResizeAndRelocateForHelpOrReadOnly ();
- }
- }
-
- [DefaultValue("")]
- [Localizable(true)]
- public string Title {
- get {
- return title;
- }
-
- set {
- title = value;
-
- form.Text = title;
- }
- }
-
- // this one is a hard one ;)
- // Win32 filename:
- // - up to MAX_PATH characters (windef.h) = 260
- // - no trailing dots or spaces
- // - case preserving
- // - etc...
- // NTFS/Posix filename:
- // - up to 32,768 Unicode characters
- // - trailing periods or spaces
- // - case sensitive
- // - etc...
- [DefaultValue(true)]
- public bool ValidateNames {
- get {
- return validateNames;
- }
-
- set {
- validateNames = value;
- }
- }
-
- public override void Reset ()
- {
- addExtension = true;
- checkFileExists = false;
- checkPathExists = true;
- defaultExt = String.Empty;
- dereferenceLinks = true;
- FileName = String.Empty;
- Filter = String.Empty;
- filterIndex = 1;
- initialDirectory = String.Empty;
- restoreDirectory = false;
- ShowHelp = false;
- Title = String.Empty;
- validateNames = true;
-
- UpdateFilters ();
- }
-
- public override string ToString ()
- {
- return String.Format("{0}: Title: {1}, FileName: {2}", base.ToString (), Title, fileName);
- }
-
- public event CancelEventHandler FileOk {
- add { Events.AddHandler (EventFileOk, value); }
- remove { Events.RemoveHandler (EventFileOk, value); }
- }
-
- protected virtual IntPtr Instance {
- get {
- if (form == null)
- return IntPtr.Zero;
- return form.Handle;
- }
- }
-
- // This is just for internal use with MSs version, so it doesn't need to be implemented
- // as it can't really be accessed anyways
- protected int Options {
- get { return -1; }
- }
-
- [MonoTODO]
- protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
- {
- throw new NotImplementedException ();
- }
-
- protected void OnFileOk (CancelEventArgs e)
- {
- WriteConfigValues (e);
-
- CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
- if (fo != null)
- fo (this, e);
- }
-
- protected override bool RunDialog (IntPtr hWndOwner)
- {
- ReadConfigValues ();
-
- form.Refresh ();
-
- mwfFileView.ChangeDirectory (null, lastFolder);
-
- fileNameComboBox.Select ();
-
- return true;
- }
-
- internal virtual bool ShowReadOnly {
- set {
- showReadOnly = value;
- ResizeAndRelocateForHelpOrReadOnly ();
- }
-
- get {
- return showReadOnly;
- }
- }
-
- internal virtual bool ReadOnlyChecked {
- set {
- readOnlyChecked = value;
- readonlyCheckBox.Checked = value;
- }
-
- get {
- return readOnlyChecked;
- }
- }
-
- internal bool BMultiSelect {
- set {
- multiSelect = value;
- mwfFileView.MultiSelect = value;
- }
-
- get {
- return multiSelect;
- }
- }
-
- internal string OpenSaveButtonText {
- set {
- openSaveButton.Text = value;
- }
- }
-
- internal string SearchSaveLabel {
- set {
- searchSaveLabel.Text = value;
- }
- }
-
- private void SelectFilter ()
- {
- if (mwfFileView.FilterArrayList == null || FilterIndex > mwfFileView.FilterArrayList.Count)
- return;
-
- do_not_call_OnSelectedIndexChangedFileTypeComboBox = true;
- fileTypeComboBox.BeginUpdate ();
- fileTypeComboBox.SelectedIndex = FilterIndex - 1;
- fileTypeComboBox.EndUpdate ();
-
- mwfFileView.FilterIndex = FilterIndex;
- }
-
- private bool SetFileName (string fname)
- {
- bool rooted = Path.IsPathRooted (fname);
-
- if (!rooted) {
- string dir = mwfFileView.CurrentRealFolder ;
- if (dir == null) {
- dir = Environment.CurrentDirectory;
- }
- if (File.Exists (Path.Combine (dir, fname))) {
- fileNameComboBox.Text = fname;
- mwfFileView.SetSelectedIndexTo (fname);
-
- return true;
- }
- } else {
- if (File.Exists (fname)) {
- fileNameComboBox.Text = Path.GetFileName (fname);
- mwfFileView.ChangeDirectory (null, Path.GetDirectoryName (fname));
- mwfFileView.SetSelectedIndexTo (fname);
-
- return true;
- }
- }
-
- return false;
- }
-
- void OnClickOpenSaveButton (object sender, EventArgs e)
- {
- if (fileDialogType == FileDialogType.OpenFileDialog) {
- ListView.SelectedListViewItemCollection sl = mwfFileView.SelectedItems;
- if (sl.Count > 0 && sl [0] != null) {
- if (sl.Count == 1) {
- FileViewListViewItem item = sl [0] as FileViewListViewItem;
- FSEntry fsEntry = item.FSEntry;
-
- if (fsEntry.Attributes == FileAttributes.Directory) {
- mwfFileView.ChangeDirectory (null, fsEntry.FullName);
- return;
- }
- } else {
- foreach (FileViewListViewItem item in sl) {
- FSEntry fsEntry = item.FSEntry;
- if (fsEntry.Attributes == FileAttributes.Directory) {
- mwfFileView.ChangeDirectory (null, fsEntry.FullName);
- return;
- }
- }
- }
- }
- }
-
- string internalfullfilename = String.Empty;
-
- if (!multiSelect) {
- string fileFromComboBox = fileNameComboBox.Text.Trim ();
-
- if (fileFromComboBox.Length > 0) {
- if (!Path.IsPathRooted (fileFromComboBox)) {
- // on unix currentRealFolder for "Recently used files" is null,
- // because recently used files don't get saved as links in a directory
- // recently used files get saved in a xml file
- if (mwfFileView.CurrentRealFolder != null)
- fileFromComboBox = Path.Combine (mwfFileView.CurrentRealFolder, fileFromComboBox);
- else
- if (mwfFileView.CurrentFSEntry != null) {
- fileFromComboBox = mwfFileView.CurrentFSEntry.FullName;
- }
- }
-
- FileInfo fileInfo = new FileInfo (fileFromComboBox);
-
- if (fileInfo.Exists || fileDialogType == FileDialogType.SaveFileDialog) {
- internalfullfilename = fileFromComboBox;
- } else {
- DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
- if (dirInfo.Exists) {
- mwfFileView.ChangeDirectory (null, dirInfo.FullName);
-
- fileNameComboBox.Text = " ";
- return;
- } else {
- internalfullfilename = fileFromComboBox;
- }
- }
- } else
- return;
-
- if (fileDialogType == FileDialogType.OpenFileDialog) {
- if (checkFileExists) {
- if (!File.Exists (internalfullfilename)) {
- string message = "\"" + internalfullfilename + "\" doesn't exist. Please verify that you have entered the correct file name.";
- MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
-
- return;
- }
- }
- } else {
- if (overwritePrompt) {
- if (File.Exists (internalfullfilename)) {
- string message = "\"" + internalfullfilename + "\" exists. Overwrite ?";
- DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
-
- if (dr == DialogResult.Cancel)
- return;
- }
- }
-
- if (createPrompt) {
- if (!File.Exists (internalfullfilename)) {
- string message = "\"" + internalfullfilename + "\" doesn't exist. Create ?";
- DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
-
- if (dr == DialogResult.Cancel)
- return;
- }
- }
- }
-
- if (fileDialogType == FileDialogType.SaveFileDialog) {
- if (addExtension) {
- string extension_to_use = String.Empty;
- string filter_exentsion = String.Empty;
-
- if (fileFilter != null) {
- FilterStruct filterstruct = (FilterStruct)fileFilter.FilterArrayList [filterIndex - 1];
-
- for (int i = 0; i < filterstruct.filters.Count; i++) {
- string extension = filterstruct.filters [i];
-
- if (extension.StartsWith ("*"))
- extension = extension.Remove (0, 1);
-
- if (extension.IndexOf ('*') != -1)
- continue;
-
- filter_exentsion = extension;
- break;
- }
- }
-
- if (filter_exentsion != String.Empty)
- extension_to_use = filter_exentsion;
- else
- if (defaultExt != String.Empty)
- extension_to_use = "." + defaultExt;
-
- internalfullfilename += extension_to_use;
- }
- }
-
- fileNames = new string [1];
-
- fileNames [0] = internalfullfilename;
-
- fileName = internalfullfilename;
-
- mwfFileView.WriteRecentlyUsed (internalfullfilename);
- } else // multiSelect = true
- if (fileDialogType != FileDialogType.SaveFileDialog) {
- if (mwfFileView.SelectedItems.Count > 0) {
- // first remove all selected directories
- ArrayList al = new ArrayList ();
-
- foreach (FileViewListViewItem lvi in mwfFileView.SelectedItems) {
- FSEntry fsEntry = lvi.FSEntry;
-
- if (fsEntry.Attributes != FileAttributes.Directory) {
- al.Add (fsEntry);
- }
- }
-
- fileName = ((FSEntry)al [0]).FullName;
-
- fileNames = new string [al.Count];
-
- for (int i = 0; i < al.Count; i++) {
- fileNames [i] = ((FSEntry)al [i]).FullName;
- }
- }
- }
-
- if (checkPathExists && mwfFileView.CurrentRealFolder != null) {
- if (!Directory.Exists (mwfFileView.CurrentRealFolder)) {
- string message = "\"" + mwfFileView.CurrentRealFolder + "\" doesn't exist. Please verify that you have entered the correct directory name.";
- MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
-
- if (initialDirectory == String.Empty)
- mwfFileView.ChangeDirectory (null, lastFolder);
- else
- mwfFileView.ChangeDirectory (null, initialDirectory);
-
- return;
- }
- }
-
- if (restoreDirectory) {
- lastFolder = restoreDirectoryString;
- } else {
- lastFolder = mwfFileView.CurrentFolder;
- }
-
- if (fileNameComboBox.Items.Count > 0) {
- if (fileNameComboBox.Items.IndexOf (fileName) == -1) {
- fileNameComboBox.Items.Insert (0, fileName);
- }
- } else
- fileNameComboBox.Items.Add (fileName);
-
- if (fileNameComboBox.Items.Count == 11)
- fileNameComboBox.Items.RemoveAt (10);
-
- CancelEventArgs cancelEventArgs = new CancelEventArgs ();
-
- cancelEventArgs.Cancel = false;
-
- OnFileOk (cancelEventArgs);
-
- form.DialogResult = DialogResult.OK;
- }
-
- void OnClickCancelButton (object sender, EventArgs e)
- {
- if (restoreDirectory)
- mwfFileView.CurrentFolder = restoreDirectoryString;
-
- CancelEventArgs cancelEventArgs = new CancelEventArgs ();
-
- cancelEventArgs.Cancel = true;
-
- OnFileOk (cancelEventArgs);
-
- form.DialogResult = DialogResult.Cancel;
- }
-
- void OnClickHelpButton (object sender, EventArgs e)
- {
- OnHelpRequest (e);
- }
-
- void OnClickSmallButtonToolBar (object sender, ToolBarButtonClickEventArgs e)
- {
- if (e.Button == upToolBarButton) {
- mwfFileView.OneDirUp ();
- } else
- if (e.Button == backToolBarButton) {
- mwfFileView.PopDir ();
- } else
- if (e.Button == newdirToolBarButton) {
- mwfFileView.CreateNewFolder ();
- }
- }
-
- void OnSelectedIndexChangedFileTypeComboBox (object sender, EventArgs e)
- {
- if (do_not_call_OnSelectedIndexChangedFileTypeComboBox) {
- do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
- return;
- }
-
- filterIndex = fileTypeComboBox.SelectedIndex + 1;
-
- mwfFileView.FilterIndex = filterIndex;
- }
-
- void OnSelectedFileChangedFileView (object sender, EventArgs e)
- {
- fileNameComboBox.Text = mwfFileView.CurrentFSEntry.Name;
- }
-
- void OnSelectedFilesChangedFileView (object sender, EventArgs e)
- {
- fileNameComboBox.Text = mwfFileView.SelectedFilesString;
- }
-
- void OnForceDialogEndFileView (object sender, EventArgs e)
- {
- OnClickOpenSaveButton (this, EventArgs.Empty);
- }
-
- void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
- {
- mwfFileView.ChangeDirectory (sender, dirComboBox.CurrentFolder);
- }
-
- void OnDirectoryChangedPopupButtonPanel (object sender, EventArgs e)
- {
- mwfFileView.ChangeDirectory (sender, popupButtonPanel.CurrentFolder);
- }
-
- void OnCheckCheckChanged (object sender, EventArgs e)
- {
- ReadOnlyChecked = readonlyCheckBox.Checked;
- }
-
- private void UpdateFilters ()
- {
- if (fileFilter == null)
- fileFilter = new FileFilter ();
-
- ArrayList filters = fileFilter.FilterArrayList;
-
- fileTypeComboBox.BeginUpdate ();
-
- fileTypeComboBox.Items.Clear ();
-
- foreach (FilterStruct fs in filters) {
- fileTypeComboBox.Items.Add (fs.filterName);
- }
-
- if (filters.Count > 0 && FilterIndex <= filters.Count)
- fileTypeComboBox.SelectedIndex = FilterIndex - 1;
-
- fileTypeComboBox.EndUpdate ();
-
- mwfFileView.FilterArrayList = filters;
-
- mwfFileView.FilterIndex = FilterIndex;
- }
-
- private void ResizeAndRelocateForHelpOrReadOnly ()
- {
- form.SuspendLayout ();
- if (ShowHelp || ShowReadOnly) {
- mwfFileView.Size = new Size (449, 250);
- fileNameLabel.Location = new Point (102, 298);
- fileNameComboBox.Location = new Point (195, 298);
- fileTypeLabel.Location = new Point (102, 324);
- fileTypeComboBox.Location = new Point (195, 324);
- openSaveButton.Location = new Point (475, 298);
- cancelButton.Location = new Point (475, 324);
- } else {
- mwfFileView.Size = new Size (449, 282);
- fileNameLabel.Location = new Point (102, 330);
- fileNameComboBox.Location = new Point (195, 330);
- fileTypeLabel.Location = new Point (102, 356);
- fileTypeComboBox.Location = new Point (195, 356);
- openSaveButton.Location = new Point (475, 330);
- cancelButton.Location = new Point (475, 356);
- }
-
- if (ShowHelp)
- form.Controls.Add (helpButton);
- else
- form.Controls.Remove (helpButton);
-
- if (ShowReadOnly)
- form.Controls.Add (readonlyCheckBox);
- else
- form.Controls.Remove (readonlyCheckBox);
- form.ResumeLayout ();
- }
-
- private void WriteConfigValues (CancelEventArgs ce)
- {
- MWFConfig.SetValue (filedialog_string, width_string, form.Width);
- MWFConfig.SetValue (filedialog_string, height_string, form.Height);
- MWFConfig.SetValue (filedialog_string, x_string, form.Location.X);
- MWFConfig.SetValue (filedialog_string, y_string, form.Location.Y);
-
- if (!ce.Cancel) {
- MWFConfig.SetValue (filedialog_string, lastfolder_string, lastFolder);
-
- string[] fileNameCBItems = new string [fileNameComboBox.Items.Count];
-
- fileNameComboBox.Items.CopyTo (fileNameCBItems, 0);
-
- MWFConfig.SetValue (filedialog_string, filenames_string, fileNameCBItems);
- }
- }
-
- private void ReadConfigValues ()
- {
- lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
-
- if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
- if (!Directory.Exists (lastFolder)) {
- lastFolder = MWFVFS.DesktopPrefix;
- }
- }
-
- if (initialDirectory != String.Empty)
- lastFolder = initialDirectory;
- else
- if (lastFolder == null || lastFolder == String.Empty)
- lastFolder = Environment.CurrentDirectory;
-
- if (RestoreDirectory)
- restoreDirectoryString = lastFolder;
- }
- }
- #endregion
-
- #region PopupButtonPanel
- internal class PopupButtonPanel : Control, IUpdateFolder
- {
- #region PopupButton
- internal class PopupButton : Control
- {
- internal enum PopupButtonState
- { Normal, Down, Up}
-
- private Image image = null;
- private PopupButtonState popupButtonState = PopupButtonState.Normal;
- private StringFormat text_format = new StringFormat();
- private Rectangle text_rect = Rectangle.Empty;
-
- public PopupButton ()
- {
- text_format.Alignment = StringAlignment.Center;
- text_format.LineAlignment = StringAlignment.Near;
-
- SetStyle (ControlStyles.DoubleBuffer, true);
- SetStyle (ControlStyles.AllPaintingInWmPaint, true);
- SetStyle (ControlStyles.UserPaint, true);
- SetStyle (ControlStyles.Selectable, false);
- }
-
- public Image Image {
- set {
- image = value;
- Refresh ();
- }
-
- get {
- return image;
- }
- }
-
- public PopupButtonState ButtonState {
- set {
- popupButtonState = value;
- Refresh ();
- }
-
- get {
- return popupButtonState;
- }
- }
-
- protected override void OnPaint (PaintEventArgs pe)
- {
- Draw (pe);
-
- base.OnPaint (pe);
- }
-
- private void Draw (PaintEventArgs pe)
- {
- Graphics gr = pe.Graphics;
-
- gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
-
- // draw image
- if (image != null) {
- int i_x = (ClientSize.Width - image.Width) / 2;
- int i_y = 4;
- gr.DrawImage (image, i_x, i_y);
- }
-
- if (Text != String.Empty) {
- if (text_rect == Rectangle.Empty)
- text_rect = new Rectangle (0, Height - 30, Width, Height - 30);
-
- gr.DrawString (Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor), text_rect, text_format);
- }
-
- switch (popupButtonState) {
- case PopupButtonState.Up:
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, ClientSize.Width - 1, 0);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, 0, ClientSize.Height - 1);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
- break;
-
- case PopupButtonState.Down:
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, ClientSize.Width - 1, 0);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, 0, ClientSize.Height - 1);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
- gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
- break;
- }
- }
-
- protected override void OnMouseEnter (EventArgs e)
- {
- if (popupButtonState != PopupButtonState.Down)
- popupButtonState = PopupButtonState.Up;
-
- PopupButtonPanel panel = Parent as PopupButtonPanel;
-
- if (panel.focusButton != null && panel.focusButton.ButtonState == PopupButtonState.Up) {
- panel.focusButton.ButtonState = PopupButtonState.Normal;
- panel.focusButton = null;
- }
- Refresh ();
- base.OnMouseEnter (e);
- }
-
- protected override void OnMouseLeave (EventArgs e)
- {
- if (popupButtonState == PopupButtonState.Up)
- popupButtonState = PopupButtonState.Normal;
- Refresh ();
- base.OnMouseLeave (e);
- }
-
- protected override void OnClick (EventArgs e)
- {
- popupButtonState = PopupButtonState.Down;
- Refresh ();
- base.OnClick (e);
- }
- }
- #endregion
-
- private EventHandler on_directory_changed;
-
- private PopupButton recentlyusedButton;
- private PopupButton desktopButton;
- private PopupButton personalButton;
- private PopupButton mycomputerButton;
- private PopupButton networkButton;
-
- private PopupButton lastPopupButton = null;
- private PopupButton focusButton = null;
-
- private string currentPath;
-
- private int currentFocusIndex;
-
- public PopupButtonPanel ()
- {
- SuspendLayout ();
-
- //BackColor = Color.FromArgb (128, 128, 128);
- Size = new Size (85, 336);
-
- recentlyusedButton = new PopupButton ();
- desktopButton = new PopupButton ();
- personalButton = new PopupButton ();
- mycomputerButton = new PopupButton ();
- networkButton = new PopupButton ();
-
- recentlyusedButton.Size = new Size (81, 64);
- recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 32);
- recentlyusedButton.BackColor = BackColor;
- recentlyusedButton.ForeColor = Color.Black;
- recentlyusedButton.Location = new Point (2, 2);
- recentlyusedButton.Text = "Recently\nused";
- recentlyusedButton.Click += new EventHandler (OnClickButton);
-
- desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 32);
- desktopButton.BackColor = BackColor;
- desktopButton.ForeColor = Color.Black;
- desktopButton.Size = new Size (81, 64);
- desktopButton.Location = new Point (2, 66);
- desktopButton.Text = "Desktop";
- desktopButton.Click += new EventHandler (OnClickButton);
-
- personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 32);
- personalButton.BackColor = BackColor;
- personalButton.ForeColor = Color.Black;
- personalButton.Size = new Size (81, 64);
- personalButton.Location = new Point (2, 130);
- personalButton.Text = "Personal";
- personalButton.Click += new EventHandler (OnClickButton);
-
- mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 32);
- mycomputerButton.BackColor = BackColor;
- mycomputerButton.ForeColor = Color.Black;
- mycomputerButton.Size = new Size (81, 64);
- mycomputerButton.Location = new Point (2, 194);
- mycomputerButton.Text = "My Computer";
- mycomputerButton.Click += new EventHandler (OnClickButton);
-
- networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 32);
- networkButton.BackColor = BackColor;
- networkButton.ForeColor = Color.Black;
- networkButton.Size = new Size (81, 64);
- networkButton.Location = new Point (2, 258);
- networkButton.Text = "My Network";
- networkButton.Click += new EventHandler (OnClickButton);
-
- Controls.Add (recentlyusedButton);
- Controls.Add (desktopButton);
- Controls.Add (personalButton);
- Controls.Add (mycomputerButton);
- Controls.Add (networkButton);
-
- ResumeLayout (false);
-
- KeyDown += new KeyEventHandler (Key_Down);
-
- SetStyle (ControlStyles.StandardClick, false);
- }
-
- void OnClickButton (object sender, EventArgs e)
- {
- if (lastPopupButton != null && lastPopupButton != sender as PopupButton)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- lastPopupButton = sender as PopupButton;
-
- if (sender == recentlyusedButton) {
- currentPath = MWFVFS.RecentlyUsedPrefix;
- } else
- if (sender == desktopButton) {
- currentPath = MWFVFS.DesktopPrefix;
- } else
- if (sender == personalButton) {
- currentPath = MWFVFS.PersonalPrefix;
- } else
- if (sender == mycomputerButton) {
- currentPath = MWFVFS.MyComputerPrefix;
- } else
- if (sender == networkButton) {
- currentPath = MWFVFS.MyNetworkPrefix;
- }
-
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
- }
-
- public string CurrentFolder {
- set {
- string currentPath = value;
- if (currentPath == MWFVFS.RecentlyUsedPrefix) {
- if (lastPopupButton != recentlyusedButton) {
- if (lastPopupButton != null)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Down;
- lastPopupButton = recentlyusedButton;
- }
- } else
- if (currentPath == MWFVFS.DesktopPrefix) {
- if (lastPopupButton != desktopButton) {
- if (lastPopupButton != null)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- desktopButton.ButtonState = PopupButton.PopupButtonState.Down;
- lastPopupButton = desktopButton;
- }
- } else
- if (currentPath == MWFVFS.PersonalPrefix) {
- if (lastPopupButton != personalButton) {
- if (lastPopupButton != null)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- personalButton.ButtonState = PopupButton.PopupButtonState.Down;
- lastPopupButton = personalButton;
- }
- } else
- if (currentPath == MWFVFS.MyComputerPrefix) {
- if (lastPopupButton != mycomputerButton) {
- if (lastPopupButton != null)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- mycomputerButton.ButtonState = PopupButton.PopupButtonState.Down;
- lastPopupButton = mycomputerButton;
- }
- } else
- if (currentPath == MWFVFS.MyNetworkPrefix) {
- if (lastPopupButton != networkButton) {
- if (lastPopupButton != null)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- networkButton.ButtonState = PopupButton.PopupButtonState.Down;
- lastPopupButton = networkButton;
- }
- } else {
- if (lastPopupButton != null) {
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- lastPopupButton = null;
- }
- }
- }
- get {
- return currentPath;
- }
- }
-
- protected override void OnPaint (PaintEventArgs e)
- {
- ControlPaint.DrawBorder3D (e.Graphics, ClientRectangle, Border3DStyle.Sunken);
- base.OnPaint (e);
- }
-
- protected override void OnGotFocus (EventArgs e)
- {
- if (lastPopupButton != recentlyusedButton) {
- recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Up;
- focusButton = recentlyusedButton;
- }
- currentFocusIndex = 0;
-
- base.OnGotFocus (e);
- }
-
- protected override void OnLostFocus (EventArgs e)
- {
- if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
- focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
- base.OnLostFocus (e);
- }
-
- protected override bool IsInputKey (Keys key)
- {
- switch (key) {
- case Keys.Up:
- case Keys.Down:
- case Keys.Right:
- case Keys.Left:
- case Keys.Enter:
- return true;
- }
- return base.IsInputKey (key);
- }
-
- private void Key_Down (object sender, KeyEventArgs e)
- {
- bool update_focus = false;
-
- if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) {
- currentFocusIndex --;
-
- if (currentFocusIndex < 0)
- currentFocusIndex = Controls.Count - 1;
-
- update_focus = true;
- } else
- if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
- currentFocusIndex++;
-
- if (currentFocusIndex == Controls.Count)
- currentFocusIndex = 0;
-
- update_focus = true;
- } else
- if (e.KeyCode == Keys.Enter) {
- focusButton.ButtonState = PopupButton.PopupButtonState.Down;
- OnClickButton (focusButton, EventArgs.Empty);
- }
-
- if (update_focus) {
- PopupButton newfocusButton = Controls [currentFocusIndex] as PopupButton;
- if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
- focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
- if (newfocusButton.ButtonState != PopupButton.PopupButtonState.Down)
- newfocusButton.ButtonState = PopupButton.PopupButtonState.Up;
- focusButton = newfocusButton;
- }
-
- e.Handled = true;
- }
-
- public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
- }
- }
- #endregion
-
- #region DirComboBox
- internal class DirComboBox : ComboBox, IUpdateFolder
- {
- #region DirComboBoxItem
- internal class DirComboBoxItem
- {
- private int imageIndex;
- private string name;
- private string path;
- private int xPos;
- private ImageList imageList;
-
- public DirComboBoxItem (ImageList imageList, int imageIndex, string name, string path, int xPos)
- {
- this.imageList = imageList;
- this.imageIndex = imageIndex;
- this.name = name;
- this.path = path;
- this.xPos = xPos;
- }
-
- public int ImageIndex {
- get {
- return imageIndex;
- }
- }
-
- public string Name {
- get {
- return name;
- }
- }
-
- public string Path {
- get {
- return path;
- }
- }
-
- public int XPos {
- get {
- return xPos;
- }
- }
-
- public ImageList ImageList {
- set {
- imageList = value;
- }
-
- get {
- return imageList;
- }
- }
- }
- #endregion
-
- private ImageList imageList = new ImageList();
-
- private string currentPath;
-
- private EventHandler on_directory_changed;
-
- private Stack folderStack = new Stack();
-
- private static readonly int indent = 6;
-
- private DirComboBoxItem recentlyUsedDirComboboxItem;
- private DirComboBoxItem desktopDirComboboxItem;
- private DirComboBoxItem personalDirComboboxItem;
- private DirComboBoxItem myComputerDirComboboxItem;
- private DirComboBoxItem networkDirComboboxItem;
-
- private ArrayList myComputerItems = new ArrayList ();
-
- private DirComboBoxItem mainParentDirComboBoxItem = null;
- private DirComboBoxItem real_parent = null;
-
- private MWFVFS vfs;
-
- public DirComboBox (MWFVFS vfs)
- {
- SuspendLayout ();
-
- DrawMode = DrawMode.OwnerDrawFixed;
-
- imageList.ColorDepth = ColorDepth.Depth32Bit;
- imageList.ImageSize = new Size (16, 16);
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
- imageList.TransparentColor = Color.Transparent;
-
- recentlyUsedDirComboboxItem = new DirComboBoxItem (imageList, 0, "Recently used", MWFVFS.RecentlyUsedPrefix, 0);
- desktopDirComboboxItem = new DirComboBoxItem (imageList, 1, "Desktop", MWFVFS.DesktopPrefix, 0);
- personalDirComboboxItem = new DirComboBoxItem (imageList, 2, "Personal folder", MWFVFS.PersonalPrefix, indent);
- myComputerDirComboboxItem = new DirComboBoxItem (imageList, 3, "My Computer", MWFVFS.MyComputerPrefix, indent);
- networkDirComboboxItem = new DirComboBoxItem (imageList, 4, "My Network", MWFVFS.MyNetworkPrefix, indent);
-
- ArrayList al = vfs.GetMyComputerContent ();
-
- foreach (FSEntry fsEntry in al) {
- myComputerItems.Add (new DirComboBoxItem (MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName, indent * 2));
- }
-
- mainParentDirComboBoxItem = myComputerDirComboboxItem;
-
- ResumeLayout (false);
- }
-
- public string CurrentFolder {
- set {
- currentPath = value;
-
- CreateComboList ();
- }
- get {
- return currentPath;
- }
- }
-
- private void CreateComboList ()
- {
- real_parent = null;
- DirComboBoxItem selection = null;
-
- if (currentPath == MWFVFS.RecentlyUsedPrefix) {
- mainParentDirComboBoxItem = recentlyUsedDirComboboxItem;
- selection = recentlyUsedDirComboboxItem;
- } else
- if (currentPath == MWFVFS.DesktopPrefix) {
- selection = desktopDirComboboxItem;
- mainParentDirComboBoxItem = desktopDirComboboxItem;
- } else
- if (currentPath == MWFVFS.PersonalPrefix) {
- selection = personalDirComboboxItem;
- mainParentDirComboBoxItem = personalDirComboboxItem;
- } else
- if (currentPath == MWFVFS.MyComputerPrefix) {
- selection = myComputerDirComboboxItem;
- mainParentDirComboBoxItem = myComputerDirComboboxItem;
- } else
- if (currentPath == MWFVFS.MyNetworkPrefix) {
- selection = networkDirComboboxItem;
- mainParentDirComboBoxItem = networkDirComboboxItem;
- } else {
- foreach (DirComboBoxItem dci in myComputerItems) {
- if (dci.Path == currentPath) {
- mainParentDirComboBoxItem = selection = dci;
- break;
- }
- }
- }
-
- BeginUpdate ();
-
- Items.Clear ();
-
- Items.Add (recentlyUsedDirComboboxItem);
- Items.Add (desktopDirComboboxItem);
- Items.Add (personalDirComboboxItem);
- Items.Add (myComputerDirComboboxItem);
- Items.AddRange (myComputerItems);
- Items.Add (networkDirComboboxItem);
-
- if (selection == null) {
- real_parent = CreateFolderStack ();
- }
-
- if (real_parent != null) {
- int local_indent = 0;
-
- if (real_parent == desktopDirComboboxItem)
- local_indent = 1;
- else
- if (real_parent == personalDirComboboxItem || real_parent == networkDirComboboxItem)
- local_indent = 2;
- else
- local_indent = 3;
-
- selection = AppendToParent (local_indent, real_parent);
- }
-
- EndUpdate ();
-
- if (selection != null)
- SelectedItem = selection;
- }
-
- private DirComboBoxItem CreateFolderStack ()
- {
- folderStack.Clear ();
-
- DirectoryInfo di = new DirectoryInfo (currentPath);
-
- folderStack.Push (di);
-
- while (di.Parent != null) {
- di = di.Parent;
-
- if (mainParentDirComboBoxItem != personalDirComboboxItem && di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
- return desktopDirComboboxItem;
- else
- if (mainParentDirComboBoxItem == personalDirComboboxItem) {
- if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
- return personalDirComboboxItem;
- } else
- foreach (DirComboBoxItem dci in myComputerItems) {
- if (dci.Path == di.FullName) {
- return dci;
- }
- }
-
-
- folderStack.Push (di);
- }
-
- return null;
- }
-
- private DirComboBoxItem AppendToParent (int nr_indents, DirComboBoxItem parentDirComboBoxItem)
- {
- DirComboBoxItem selection = null;
-
- int index = Items.IndexOf (parentDirComboBoxItem) + 1;
-
- int xPos = indent * nr_indents;
-
- while (folderStack.Count != 0) {
- DirectoryInfo dii = folderStack.Pop () as DirectoryInfo;
-
- DirComboBoxItem dci = new DirComboBoxItem (imageList, 5, dii.Name, dii.FullName, xPos);
-
- Items.Insert (index, dci);
- index++;
- selection = dci;
- xPos += indent;
- }
-
- return selection;
- }
-
- protected override void OnDrawItem (DrawItemEventArgs e)
- {
- if (e.Index == -1)
- return;
-
- DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
-
- Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
- Graphics gr = Graphics.FromImage (bmp);
-
- Color backColor = e.BackColor;
- Color foreColor = e.ForeColor;
-
- int xPos = dcbi.XPos;
- if ((e.State & DrawItemState.ComboBoxEdit) != 0)
- xPos = 0;
- gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
- new Rectangle (0, 0, bmp.Width, bmp.Height));
-
- if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
- (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
- foreColor = ThemeEngine.Current.ColorHighlightText;
- int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
- gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
- new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
- if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
- ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
- e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
- }
- }
- gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
- gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
-
- e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
- gr.Dispose ();
- bmp.Dispose ();
- }
-
- protected override void OnSelectedIndexChanged (EventArgs e)
- {
- if (Items.Count > 0) {
- DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
-
- currentPath = dcbi.Path;
- }
- }
-
- protected override void OnSelectionChangeCommitted (EventArgs e)
- {
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
- }
-
- public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
- }
- }
- #endregion
-
- #region FilterStruct
- internal struct FilterStruct
- {
- public string filterName;
- public StringCollection filters;
-
- public FilterStruct (string filterName, string filter)
- {
- this.filterName = filterName;
-
- filters = new StringCollection ();
-
- SplitFilters (filter);
- }
-
- private void SplitFilters (string filter)
- {
- string[] split = filter.Split (new char [] {';'});
-
- filters.AddRange (split);
- }
- }
- #endregion
-
- #region FileFilter
- internal class FileFilter
- {
- private ArrayList filterArrayList = new ArrayList();
-
- private string filter;
-
- public FileFilter ()
- {}
-
- public FileFilter (string filter) : base ()
- {
- this.filter = filter;
-
- SplitFilter ();
- }
-
- public static bool CheckFilter (string val)
- {
- if (val.Length == 0)
- return true;
-
- string[] filters = val.Split (new char [] {'|'});
-
- if ((filters.Length % 2) != 0)
- return false;
-
- return true;
- }
-
- public ArrayList FilterArrayList {
- set {
- filterArrayList = value;
- }
-
- get {
- return filterArrayList;
- }
- }
-
- public string Filter {
- set {
- filter = value;
-
- SplitFilter ();
- }
-
- get {
- return filter;
- }
- }
-
- private void SplitFilter ()
- {
- filterArrayList.Clear ();
-
- if (filter.Length == 0)
- return;
-
- string[] filters = filter.Split (new char [] {'|'});
-
- for (int i = 0; i < filters.Length; i += 2) {
- FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
-
- filterArrayList.Add (filterStruct);
- }
- }
- }
- #endregion
-
- #region MWFFileView
- // MWFFileView
- internal class MWFFileView : ListView
- {
- private ArrayList filterArrayList;
-
- private bool showHiddenFiles = false;
-
- private EventHandler on_selected_file_changed;
- private EventHandler on_selected_files_changed;
- private EventHandler on_directory_changed;
- private EventHandler on_force_dialog_end;
-
- private string selectedFilesString;
-
- private int filterIndex = 1;
-
- private ToolTip toolTip;
- private int oldItemIndexForToolTip = -1;
-
- private ContextMenu contextMenu;
-
- private MenuItem menuItemView;
- private MenuItem menuItemNew;
-
- private MenuItem smallIconMenutItem;
- private MenuItem tilesMenutItem;
- private MenuItem largeIconMenutItem;
- private MenuItem listMenutItem;
- private MenuItem detailsMenutItem;
-
- private MenuItem newFolderMenuItem;
- private MenuItem showHiddenFilesMenuItem;
-
- private int previousCheckedMenuItemIndex;
-
- private ArrayList viewMenuItemClones = new ArrayList ();
-
- private FSEntry currentFSEntry = null;
-
- private string currentFolder;
- private string currentRealFolder;
- private FSEntry currentFolderFSEntry;
-
- // store DirectoryInfo for a back button for example
- private Stack directoryStack = new Stack();
-
- // list of controls(components to enable or disable depending on current directoryStack.Count
- private ArrayList dirStackControlsOrComponents = new ArrayList ();
-
- private ToolBarButton folderUpToolBarButton;
-
- private ArrayList registered_senders = new ArrayList ();
-
- private bool should_push = true;
-
- private MWFVFS vfs;
-
- private View old_view;
-
- private int old_menuitem_index;
- private bool do_update_view = false;
-
- private int platform = (int) Environment.OSVersion.Platform;
-
- public MWFFileView (MWFVFS vfs)
- {
- this.vfs = vfs;
- vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate (RealFileViewUpdate), this);
-
- SuspendLayout ();
-
- contextMenu = new ContextMenu ();
-
- toolTip = new ToolTip ();
- toolTip.InitialDelay = 300;
- toolTip.ReshowDelay = 0;
-
- // contextMenu
-
- // View menu item
- menuItemView = new MenuItem ("View");
-
- smallIconMenutItem = new MenuItem ("Small Icon", new EventHandler (OnClickViewMenuSubItem));
- smallIconMenutItem.RadioCheck = true;
- menuItemView.MenuItems.Add (smallIconMenutItem);
-
- tilesMenutItem = new MenuItem ("Tiles", new EventHandler (OnClickViewMenuSubItem));
- tilesMenutItem.RadioCheck = true;
- menuItemView.MenuItems.Add (tilesMenutItem);
-
- largeIconMenutItem = new MenuItem ("Large Icon", new EventHandler (OnClickViewMenuSubItem));
- largeIconMenutItem.RadioCheck = true;
- menuItemView.MenuItems.Add (largeIconMenutItem);
-
- listMenutItem = new MenuItem ("List", new EventHandler (OnClickViewMenuSubItem));
- listMenutItem.RadioCheck = true;
- listMenutItem.Checked = true;
- menuItemView.MenuItems.Add (listMenutItem);
- previousCheckedMenuItemIndex = listMenutItem.Index;
-
- detailsMenutItem = new MenuItem ("Details", new EventHandler (OnClickViewMenuSubItem));
- detailsMenutItem.RadioCheck = true;
- menuItemView.MenuItems.Add (detailsMenutItem);
-
- contextMenu.MenuItems.Add (menuItemView);
-
- contextMenu.MenuItems.Add (new MenuItem ("-"));
-
- // New menu item
- menuItemNew = new MenuItem ("New");
-
- newFolderMenuItem = new MenuItem ("New Folder", new EventHandler (OnClickNewFolderMenuItem));
- menuItemNew.MenuItems.Add (newFolderMenuItem);
-
- contextMenu.MenuItems.Add (menuItemNew);
-
- contextMenu.MenuItems.Add (new MenuItem ("-"));
-
- // Show hidden files menu item
- showHiddenFilesMenuItem = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
- showHiddenFilesMenuItem.Checked = showHiddenFiles;
- contextMenu.MenuItems.Add (showHiddenFilesMenuItem);
-
- LabelWrap = true;
-
- SmallImageList = MimeIconEngine.SmallIcons;
- LargeImageList = MimeIconEngine.LargeIcons;
-
- View = old_view = View.List;
- LabelEdit = true;
-
- ContextMenu = contextMenu;
-
- ResumeLayout (false);
-
- KeyDown += new KeyEventHandler (MWF_KeyDown);
- }
-
- public string CurrentFolder {
- get {
- return currentFolder;
- }
- set {
- currentFolder = value;
- }
- }
-
- public string CurrentRealFolder {
- get {
- return currentRealFolder;
- }
- }
-
- public FSEntry CurrentFSEntry {
- get {
- return currentFSEntry;
- }
- }
-
- public MenuItem[] ViewMenuItems {
- get {
- MenuItem[] menuItemClones = new MenuItem [] {
- smallIconMenutItem.CloneMenu (),
- tilesMenutItem.CloneMenu (),
- largeIconMenutItem.CloneMenu (),
- listMenutItem.CloneMenu (),
- detailsMenutItem.CloneMenu ()
- };
-
- viewMenuItemClones.Add (menuItemClones);
-
- return menuItemClones;
- }
- }
-
- public ArrayList FilterArrayList {
- set {
- filterArrayList = value;
- }
-
- get {
- return filterArrayList;
- }
- }
-
- public bool ShowHiddenFiles {
- set {
- showHiddenFiles = value;
- }
-
- get {
- return showHiddenFiles;
- }
- }
-
- public int FilterIndex {
- set {
- filterIndex = value;
- if (Visible)
- UpdateFileView ();
- }
-
- get {
- return filterIndex;
- }
- }
-
- public string SelectedFilesString {
- set {
- selectedFilesString = value;
- }
-
- get {
- return selectedFilesString;
- }
- }
-
- public void PushDir ()
- {
- if (currentFolder != null)
- directoryStack.Push (currentFolder);
-
- EnableOrDisableDirstackObjects ();
- }
-
- public void PopDir ()
- {
- if (directoryStack.Count == 0)
- return;
-
- string new_folder = directoryStack.Pop () as string;
-
- EnableOrDisableDirstackObjects ();
-
- should_push = false;
-
- ChangeDirectory (null, new_folder);
- }
-
- public void RegisterSender (IUpdateFolder iud)
- {
- registered_senders.Add (iud);
- }
-
- public void CreateNewFolder ()
- {
- if (currentFolder == MWFVFS.MyComputerPrefix ||
- currentFolder == MWFVFS.RecentlyUsedPrefix)
- return;
-
- FSEntry fsEntry = new FSEntry ();
- fsEntry.Attributes = FileAttributes.Directory;
- fsEntry.FileType = FSEntry.FSEntryType.Directory;
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
- fsEntry.LastAccessTime = DateTime.Now;
-
- // FIXME: when ListView.LabelEdit is available use it
- // listViewItem.BeginEdit();
-
- TextEntryDialog ted = new TextEntryDialog ();
- ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
-
- string folder = String.Empty;
-
- if (currentFolderFSEntry.RealName != null)
- folder = currentFolderFSEntry.RealName;
- else
- folder = currentFolder;
-
- string tmp_filename = "New Folder";
-
- if (Directory.Exists (Path.Combine (folder, tmp_filename))) {
- int i = 1;
-
- if ((platform == 4) || (platform == 128)) {
- tmp_filename = tmp_filename + "-" + i;
- } else {
- tmp_filename = tmp_filename + " (" + i + ")";
- }
-
- while (Directory.Exists (Path.Combine (folder, tmp_filename))) {
- i++;
- if ((platform == 4) || (platform == 128)) {
- tmp_filename = "New Folder" + "-" + i;
- } else {
- tmp_filename = "New Folder" + " (" + i + ")";
- }
- }
- }
-
- ted.FileName = tmp_filename;
-
- if (ted.ShowDialog () == DialogResult.OK) {
- string new_folder = Path.Combine (folder, ted.FileName);
-
- if (vfs.CreateFolder (new_folder)) {
- fsEntry.FullName = new_folder;
- fsEntry.Name = ted.FileName;
-
- FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
-
- BeginUpdate ();
- Items.Add (listViewItem);
- EndUpdate ();
-
- listViewItem.EnsureVisible ();
- }
- }
- }
-
- public void SetSelectedIndexTo (string fname)
- {
- foreach (FileViewListViewItem item in Items) {
- if (item.Text == fname) {
- BeginUpdate ();
- SelectedItems.Clear ();
- item.Selected = true;
- EndUpdate ();
- break;
- }
- }
- }
-
- public void OneDirUp ()
- {
- string parent_folder = vfs.GetParent ();
- if (parent_folder != null)
- ChangeDirectory (null, parent_folder);
- }
-
- public void ChangeDirectory (object sender, string folder)
- {
- if (folder == MWFVFS.DesktopPrefix || folder == MWFVFS.RecentlyUsedPrefix)
- folderUpToolBarButton.Enabled = false;
- else
- folderUpToolBarButton.Enabled = true;
-
- foreach (IUpdateFolder iuf in registered_senders) {
- iuf.CurrentFolder = folder;
- }
-
- if (should_push)
- PushDir ();
- else
- should_push = true;
-
- currentFolderFSEntry = vfs.ChangeDirectory (folder);
-
- currentFolder = folder;
-
- if (currentFolder.IndexOf ("://") != -1)
- currentRealFolder = currentFolderFSEntry.RealName;
- else
- currentRealFolder = currentFolder;
-
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
-
- if (folder == MWFVFS.RecentlyUsedPrefix) {
- old_view = View;
- View = View.Details;
- old_menuitem_index = previousCheckedMenuItemIndex;
- UpdateMenuItems (detailsMenutItem);
- do_update_view = true;
- } else
- if (View != old_view && do_update_view) {
- UpdateMenuItems (menuItemView.MenuItems [old_menuitem_index]);
- View = old_view;
- do_update_view = false;
- }
- EndUpdate ();
- try {
- UpdateFileView ();
- } catch (Exception e) {
- if (should_push)
- PopDir ();
- MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- public void UpdateFileView ()
- {
- if (filterArrayList != null && filterArrayList.Count != 0) {
- FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
-
- vfs.GetFolderContent (fs.filters);
- } else
- vfs.GetFolderContent ();
- }
-
- public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
- {
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
-
- foreach (FSEntry directoryFSEntry in directoriesArrayList) {
- if (!ShowHiddenFiles)
- if (directoryFSEntry.Name.StartsWith (".") || directoryFSEntry.Attributes == FileAttributes.Hidden)
- continue;
-
- FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
-
- Items.Add (listViewItem);
- }
-
- StringCollection collection = new StringCollection ();
-
- foreach (FSEntry fsEntry in fileArrayList) {
-
- // remove duplicates. that can happen when you read recently used files for example
- if (collection.Contains (fsEntry.Name)) {
-
- string fileName = fsEntry.Name;
-
- if (collection.Contains (fileName)) {
- int i = 1;
-
- while (collection.Contains (fileName + "(" + i + ")")) {
- i++;
- }
-
- fileName = fileName + "(" + i + ")";
- }
-
- fsEntry.Name = fileName;
- }
-
- collection.Add (fsEntry.Name);
-
- DoOneFSEntry (fsEntry);
- }
-
- EndUpdate ();
- }
-
- public void AddControlToEnableDisableByDirStack (object control)
- {
- dirStackControlsOrComponents.Add (control);
- }
-
- public void SetFolderUpToolBarButton (ToolBarButton tb)
- {
- folderUpToolBarButton = tb;
- }
-
- public void WriteRecentlyUsed (string fullfilename)
- {
- vfs.WriteRecentlyUsedFiles (fullfilename);
- }
-
- private void EnableOrDisableDirstackObjects ()
- {
- foreach (object o in dirStackControlsOrComponents) {
- if (o is Control) {
- Control c = o as Control;
- c.Enabled = (directoryStack.Count > 1);
- } else
- if (o is ToolBarButton) {
- ToolBarButton t = o as ToolBarButton;
- t.Enabled = (directoryStack.Count > 0);
- }
- }
- }
-
- private void DoOneFSEntry (FSEntry fsEntry)
- {
- if (!ShowHiddenFiles)
- if (fsEntry.Name.StartsWith (".") || fsEntry.Attributes == FileAttributes.Hidden)
- return;
-
- FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
-
- Items.Add (listViewItem);
- }
-
- private void MWF_KeyDown (object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Back) {
- OneDirUp ();
- }
- }
-
- protected override void OnClick (EventArgs e)
- {
- if (!MultiSelect) {
- if (SelectedItems.Count > 0) {
- FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
-
- FSEntry fsEntry = listViewItem.FSEntry;
-
- if (fsEntry.FileType == FSEntry.FSEntryType.File) {
- currentFSEntry = fsEntry;
-
- if (on_selected_file_changed != null)
- on_selected_file_changed (this, EventArgs.Empty);
- }
- }
- }
-
- base.OnClick (e);
- }
-
- protected override void OnDoubleClick (EventArgs e)
- {
- if (SelectedItems.Count > 0) {
- FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
-
- FSEntry fsEntry = listViewItem.FSEntry;
-
- if (fsEntry.Attributes == FileAttributes.Directory) {
-
- ChangeDirectory (null, fsEntry.FullName);
-
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
- } else {
- currentFSEntry = fsEntry;
-
- if (on_selected_file_changed != null)
- on_selected_file_changed (this, EventArgs.Empty);
-
- if (on_force_dialog_end != null)
- on_force_dialog_end (this, EventArgs.Empty);
-
- return;
- }
- }
-
- base.OnDoubleClick (e);
- }
-
- protected override void OnSelectedIndexChanged (EventArgs e)
- {
- if (SelectedItems.Count > 0) {
- selectedFilesString = String.Empty;
-
- if (SelectedItems.Count == 1) {
- FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
-
- FSEntry fsEntry = listViewItem.FSEntry;
-
- if (fsEntry.Attributes != FileAttributes.Directory)
- selectedFilesString = SelectedItems [0].Text;
- } else {
- foreach (FileViewListViewItem lvi in SelectedItems) {
- FSEntry fsEntry = lvi.FSEntry;
-
- if (fsEntry.Attributes != FileAttributes.Directory)
- selectedFilesString = selectedFilesString + "\"" + lvi.Text + " ";
- }
- }
-
- if (on_selected_files_changed != null)
- on_selected_files_changed (this, EventArgs.Empty);
- }
-
- base.OnSelectedIndexChanged (e);
- }
-
- protected override void OnMouseMove (MouseEventArgs e)
- {
- FileViewListViewItem item = GetItemAt (e.X, e.Y) as FileViewListViewItem;
-
- if (item != null) {
- int currentItemIndex = item.Index;
-
- if (currentItemIndex != oldItemIndexForToolTip) {
- oldItemIndexForToolTip = currentItemIndex;
-
- if (toolTip != null && toolTip.Active)
- toolTip.Active = false;
-
- FSEntry fsEntry = item.FSEntry;
-
- string output = String.Empty;
-
- if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
- output = "Directory: " + fsEntry.FullName;
- else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
- output = "Device: "+ fsEntry.FullName;
- else if (fsEntry.FileType == FSEntry.FSEntryType.Network)
- output = "Network: " + fsEntry.FullName;
- else
- output = "File: " + fsEntry.FullName;
-
- toolTip.SetToolTip (this, output);
-
- toolTip.Active = true;
- }
- } else
- toolTip.Active = false;
-
- base.OnMouseMove (e);
- }
-
- void OnClickContextMenu (object sender, EventArgs e)
- {
- MenuItem senderMenuItem = sender as MenuItem;
-
- if (senderMenuItem == showHiddenFilesMenuItem) {
- senderMenuItem.Checked = !senderMenuItem.Checked;
- showHiddenFiles = senderMenuItem.Checked;
- UpdateFileView ();
- }
- }
-
- void OnClickViewMenuSubItem (object sender, EventArgs e)
- {
- MenuItem senderMenuItem = (MenuItem)sender;
-
- UpdateMenuItems (senderMenuItem);
-
- // update me
-
- switch (senderMenuItem.Index) {
- case 0:
- View = View.SmallIcon;
- break;
- case 1:
- View = View.LargeIcon;
- break;
- case 2:
- View = View.LargeIcon;
- break;
- case 3:
- View = View.List;
- break;
- case 4:
- View = View.Details;
- break;
- default:
- break;
- }
- }
-
- private void UpdateMenuItems (MenuItem senderMenuItem)
- {
- menuItemView.MenuItems [previousCheckedMenuItemIndex].Checked = false;
- menuItemView.MenuItems [senderMenuItem.Index].Checked = true;
-
- foreach (MenuItem[] items in viewMenuItemClones) {
- items [previousCheckedMenuItemIndex].Checked = false;
- items [senderMenuItem.Index].Checked = true;
- }
-
- previousCheckedMenuItemIndex = senderMenuItem.Index;
- }
-
- void OnClickNewFolderMenuItem (object sender, EventArgs e)
- {
- CreateNewFolder ();
- }
-
- public event EventHandler SelectedFileChanged {
- add { on_selected_file_changed += value; }
- remove { on_selected_file_changed -= value; }
- }
-
- public event EventHandler SelectedFilesChanged {
- add { on_selected_files_changed += value; }
- remove { on_selected_files_changed -= value; }
- }
-
- public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
- }
-
- public event EventHandler ForceDialogEnd {
- add { on_force_dialog_end += value; }
- remove { on_force_dialog_end -= value; }
- }
- }
- #endregion
-
- #region FileListViewItem
- internal class FileViewListViewItem : ListViewItem
- {
- private FSEntry fsEntry;
-
- public FileViewListViewItem (FSEntry fsEntry)
- {
- this.fsEntry = fsEntry;
-
- ImageIndex = fsEntry.IconIndex;
-
- Text = fsEntry.Name;
-
- switch (fsEntry.FileType) {
- case FSEntry.FSEntryType.Directory:
- SubItems.Add (String.Empty);
- SubItems.Add ("Directory");
- SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
- break;
- case FSEntry.FSEntryType.File:
- long fileLen = 1;
- try {
- if (fsEntry.FileSize > 1024)
- fileLen = fsEntry.FileSize / 1024;
- } catch (Exception) {
- fileLen = 1;
- }
-
- SubItems.Add (fileLen.ToString () + " KB");
- SubItems.Add ("File");
- SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
- break;
- case FSEntry.FSEntryType.Device:
- SubItems.Add (String.Empty);
- SubItems.Add ("Device");
- SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
- break;
- case FSEntry.FSEntryType.RemovableDevice:
- SubItems.Add (String.Empty);
- SubItems.Add ("RemovableDevice");
- SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
- break;
- default:
- break;
- }
- }
-
- public FSEntry FSEntry {
- set {
- fsEntry = value;
- }
-
- get {
- return fsEntry;
- }
- }
- }
- #endregion
-
- #region IUpdateFolder
- internal interface IUpdateFolder
- {
- string CurrentFolder {get; set;}
- }
- #endregion
-
- #region TextEntryDialog
- // FIXME: When ListView.LabelEdit is implemented remove me
- internal class TextEntryDialog : Form
- {
- private Label label1;
- private Button okButton;
- private TextBox newNameTextBox;
- private PictureBox iconPictureBox;
- private Button cancelButton;
- private GroupBox groupBox1;
-
- public TextEntryDialog ()
- {
- groupBox1 = new GroupBox ();
- cancelButton = new Button ();
- iconPictureBox = new PictureBox ();
- newNameTextBox = new TextBox ();
- okButton = new Button ();
- label1 = new Label ();
- groupBox1.SuspendLayout ();
- SuspendLayout ();
-
- // groupBox1
- groupBox1.Controls.Add (newNameTextBox);
- groupBox1.Controls.Add (label1);
- groupBox1.Controls.Add (iconPictureBox);
- groupBox1.Location = new Point (8, 8);
- groupBox1.Size = new Size (232, 160);
- groupBox1.TabIndex = 5;
- groupBox1.TabStop = false;
- groupBox1.Text = "New Name";
-
- // cancelButton
- cancelButton.DialogResult = DialogResult.Cancel;
- cancelButton.Location = new Point (168, 176);
- cancelButton.TabIndex = 4;
- cancelButton.Text = "Cancel";
-
- // iconPictureBox
- iconPictureBox.BorderStyle = BorderStyle.Fixed3D;
- iconPictureBox.Location = new Point (86, 24);
- iconPictureBox.Size = new Size (60, 60);
- iconPictureBox.TabIndex = 3;
- iconPictureBox.TabStop = false;
- iconPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
-
- // newNameTextBox
- newNameTextBox.Location = new Point (16, 128);
- newNameTextBox.Size = new Size (200, 20);
- newNameTextBox.TabIndex = 5;
- newNameTextBox.Text = String.Empty;
-
- // okButton
- okButton.DialogResult = DialogResult.OK;
- okButton.Location = new Point (80, 176);
- okButton.TabIndex = 3;
- okButton.Text = "OK";
-
- // label1
- label1.Location = new Point (16, 96);
- label1.Size = new Size (200, 23);
- label1.TabIndex = 4;
- label1.Text = "Enter Name:";
- label1.TextAlign = ContentAlignment.MiddleCenter;
-
- // MainForm
- AcceptButton = okButton;
- AutoScaleBaseSize = new Size (5, 13);
- CancelButton = cancelButton;
- ClientSize = new Size (248, 205);
- Controls.Add (groupBox1);
- Controls.Add (cancelButton);
- Controls.Add (okButton);
- FormBorderStyle = FormBorderStyle.FixedDialog;
- Text = "New Folder or File";
- groupBox1.ResumeLayout (false);
- ResumeLayout (false);
-
- newNameTextBox.Select ();
- }
-
- public Image IconPictureBoxImage {
- set {
- iconPictureBox.Image = value;
- }
- }
-
- public string FileName {
- get {
- return newNameTextBox.Text;
- }
- set {
- newNameTextBox.Text = value;
- }
- }
- }
- #endregion
-
- #region MWFVFS
- internal class MWFVFS
- {
- private FileSystem fileSystem;
-
- private int platform = (int) Environment.OSVersion.Platform;
-
- public static readonly string DesktopPrefix = "Desktop://";
- public static readonly string PersonalPrefix = "Personal://";
- public static readonly string MyComputerPrefix = "MyComputer://";
- public static readonly string RecentlyUsedPrefix = "RecentlyUsed://";
- public static readonly string MyNetworkPrefix = "MyNetwork://";
- public static readonly string MyComputerPersonalPrefix = "MyComputerPersonal://";
-
- public static Hashtable MyComputerDevicesPrefix = new Hashtable ();
-
- public delegate void UpdateDelegate (ArrayList folders, ArrayList files);
- private UpdateDelegate updateDelegate;
- private Control calling_control;
-
- private ThreadStart get_folder_content_thread_start;
- private Thread worker;
- private WorkerThread workerThread = null;
- private StringCollection the_filters;
-
- public MWFVFS ()
- {
- if ((platform == 4) || (platform == 128)) {
- fileSystem = new UnixFileSystem ();
- } else {
- fileSystem = new WinFileSystem ();
- }
- }
-
- public FSEntry ChangeDirectory (string folder)
- {
- return fileSystem.ChangeDirectory (folder);
- }
-
- public void GetFolderContent ()
- {
- GetFolderContent (null);
- }
-
- public void GetFolderContent (StringCollection filters)
- {
- the_filters = filters;
- if (workerThread != null) {
- workerThread.Stop ();
- workerThread = null;
- }
- // Added next line to ensure the control is created before BeginInvoke is called on it
- calling_control.CreateControl();
- workerThread = new WorkerThread (fileSystem, the_filters, updateDelegate, calling_control);
-
- get_folder_content_thread_start = new ThreadStart (workerThread.GetFolderContentThread);
- worker = new Thread (get_folder_content_thread_start);
- worker.IsBackground = true;
- worker.Start();
- }
-
- internal class WorkerThread
- {
- private FileSystem fileSystem;
- private StringCollection the_filters;
- private UpdateDelegate updateDelegate;
- private Control calling_control;
- private readonly object lockobject = new object ();
- private bool stopped = false;
-
- public WorkerThread (FileSystem fileSystem, StringCollection the_filters, UpdateDelegate updateDelegate, Control calling_control)
- {
- this.fileSystem = fileSystem;
- this.the_filters = the_filters;
- this.updateDelegate = updateDelegate;
- this.calling_control = calling_control;
- }
-
- public void GetFolderContentThread()
- {
- ArrayList folders;
- ArrayList files;
-
- fileSystem.GetFolderContent (the_filters, out folders, out files);
-
- if (stopped)
- return;
-
- if (updateDelegate != null) {
- lock (this) {
- object[] objectArray = new object[2];
-
- objectArray[0] = folders;
- objectArray[1] = files;
-
- calling_control.BeginInvoke (updateDelegate, objectArray);
- }
- }
- }
-
- public void Stop ()
- {
- lock (lockobject) {
- stopped = true;
- }
- }
- }
-
- public ArrayList GetFoldersOnly ()
- {
- return fileSystem.GetFoldersOnly ();
- }
-
- public void WriteRecentlyUsedFiles (string filename)
- {
- fileSystem.WriteRecentlyUsedFiles (filename);
- }
-
- public ArrayList GetRecentlyUsedFiles ()
- {
- return fileSystem.GetRecentlyUsedFiles ();
- }
-
- public ArrayList GetMyComputerContent ()
- {
- return fileSystem.GetMyComputerContent ();
- }
-
- public ArrayList GetMyNetworkContent ()
- {
- return fileSystem.GetMyNetworkContent ();
- }
-
- public bool CreateFolder (string new_folder)
- {
- try {
- if (Directory.Exists (new_folder)) {
- string message = "Folder \"" + new_folder + "\" already exists.";
- MessageBox.Show (message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- } else
- Directory.CreateDirectory (new_folder);
- } catch (Exception e) {
- MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
-
- return true;
- }
-
- public string GetParent ()
- {
- return fileSystem.GetParent ();
- }
-
- public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
- {
- this.updateDelegate = updateDelegate;
- calling_control = control;
- }
- }
- #endregion
-
- #region FileSystem
- internal abstract class FileSystem
- {
- protected string currentTopFolder = String.Empty;
- protected FSEntry currentFolderFSEntry = null;
- protected FSEntry currentTopFolderFSEntry = null;
-
- public FSEntry ChangeDirectory (string folder)
- {
- if (folder == MWFVFS.DesktopPrefix) {
- currentTopFolder = MWFVFS.DesktopPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetDesktopFSEntry ();
- } else
- if (folder == MWFVFS.PersonalPrefix) {
- currentTopFolder = MWFVFS.PersonalPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetPersonalFSEntry ();
- } else
- if (folder == MWFVFS.MyComputerPersonalPrefix) {
- currentTopFolder = MWFVFS.MyComputerPersonalPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerPersonalFSEntry ();
- } else
- if (folder == MWFVFS.RecentlyUsedPrefix) {
- currentTopFolder = MWFVFS.RecentlyUsedPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetRecentlyUsedFSEntry ();
- } else
- if (folder == MWFVFS.MyComputerPrefix) {
- currentTopFolder = MWFVFS.MyComputerPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerFSEntry ();
- } else
- if (folder == MWFVFS.MyNetworkPrefix) {
- currentTopFolder = MWFVFS.MyNetworkPrefix;
- currentTopFolderFSEntry = currentFolderFSEntry = GetMyNetworkFSEntry ();
- } else {
- bool found = false;
-
- foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
- FSEntry fsEntry = entry.Value as FSEntry;
- if (folder == fsEntry.FullName) {
- currentTopFolder = entry.Key as string;
- currentTopFolderFSEntry = currentFolderFSEntry = fsEntry;
- found = true;
- break;
- }
- }
-
- if (!found) {
- currentFolderFSEntry = GetDirectoryFSEntry (new DirectoryInfo (folder), currentTopFolderFSEntry);
- }
- }
-
- return currentFolderFSEntry;
- }
-
- public string GetParent ()
- {
- return currentFolderFSEntry.Parent;
- }
-
- // directories_out and files_out contain FSEntry objects
- public void GetFolderContent (StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
- {
- directories_out = new ArrayList ();
- files_out = new ArrayList ();
-
- if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
- FSEntry personalFSEntry = GetPersonalFSEntry ();
-
- directories_out.Add (personalFSEntry);
-
- FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
-
- directories_out.Add (myComputerFSEntry);
-
- FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
-
- directories_out.Add (myNetworkFSEntry);
-
- ArrayList d_out = null;
- ArrayList f_out = null;
- GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesDesktop), filters, out d_out, out f_out);
- directories_out.AddRange (d_out);
- files_out.AddRange (f_out);
-
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
- files_out = GetRecentlyUsedFiles ();
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
- directories_out.AddRange (GetMyComputerContent ());
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
- ArrayList d_out = null;
- ArrayList f_out = null;
- GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesPersonal), filters, out d_out, out f_out);
- directories_out.AddRange (d_out);
- files_out.AddRange (f_out);
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
- directories_out.AddRange (GetMyNetworkContent ());
- } else {
- GetNormalFolderContent (currentFolderFSEntry.FullName, filters, out directories_out, out files_out);
- }
- }
-
- public ArrayList GetFoldersOnly ()
- {
- ArrayList directories_out = new ArrayList ();
-
- if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
- FSEntry personalFSEntry = GetPersonalFSEntry ();
-
- directories_out.Add (personalFSEntry);
-
- FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
-
- directories_out.Add (myComputerFSEntry);
-
- FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
-
- directories_out.Add (myNetworkFSEntry);
-
- ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
- directories_out.AddRange (d_out);
-
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
- //files_out = GetRecentlyUsedFiles ();
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
- directories_out.AddRange (GetMyComputerContent ());
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
- ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
- directories_out.AddRange (d_out);
- } else
- if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
- directories_out.AddRange (GetMyNetworkContent ());
- } else {
- directories_out = GetNormalFolders (currentFolderFSEntry.FullName);
- }
- return directories_out;
- }
-
- protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
- {
- DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
-
- directories_out = new ArrayList ();
-
- DirectoryInfo[] dirs = null;
-
- try {
- dirs = dirinfo.GetDirectories ();
- } catch (Exception) {}
-
- if (dirs != null)
- for (int i = 0; i < dirs.Length; i++) {
- directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
- }
-
- files_out = new ArrayList ();
-
- ArrayList files = new ArrayList ();
-
- try {
- if (filters == null) {
- files.AddRange (dirinfo.GetFiles ());
- } else {
- foreach (string s in filters)
- files.AddRange (dirinfo.GetFiles (s));
- }
- } catch (Exception) {}
-
- for (int i = 0; i < files.Count; i++) {
- FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
- if (fs != null)
- files_out.Add (fs);
- }
- }
-
- protected ArrayList GetNormalFolders (string from_folder)
- {
- DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
-
- ArrayList directories_out = new ArrayList ();
-
- DirectoryInfo[] dirs = null;
-
- try {
- dirs = dirinfo.GetDirectories ();
- } catch (Exception) {}
-
- if (dirs != null)
- for (int i = 0; i < dirs.Length; i++) {
- directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
- }
-
- return directories_out;
- }
-
- protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
- {
- FSEntry fs = new FSEntry ();
-
- fs.Attributes = dirinfo.Attributes;
- fs.FullName = dirinfo.FullName;
- fs.Name = dirinfo.Name;
- fs.MainTopNode = topFolderFSEntry;
- fs.FileType = FSEntry.FSEntryType.Directory;
- fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
- fs.LastAccessTime = dirinfo.LastAccessTime;
-
- return fs;
- }
-
- protected virtual FSEntry GetFileFSEntry (FileInfo fileinfo)
- {
- // *sigh* FileInfo gives us no usable information for links to directories
- // so, return null
- if ((fileinfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
- return null;
-
- FSEntry fs = new FSEntry ();
-
- fs.Attributes = fileinfo.Attributes;
- fs.FullName = fileinfo.FullName;
- fs.Name = fileinfo.Name;
- fs.FileType = FSEntry.FSEntryType.File;
- fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
- fs.FileSize = fileinfo.Length;
- fs.LastAccessTime = fileinfo.LastAccessTime;
-
- return fs;
- }
-
-
- protected abstract FSEntry GetDesktopFSEntry ();
-
- protected abstract FSEntry GetRecentlyUsedFSEntry ();
-
- protected abstract FSEntry GetPersonalFSEntry ();
-
- protected abstract FSEntry GetMyComputerPersonalFSEntry ();
-
- protected abstract FSEntry GetMyComputerFSEntry ();
-
- protected abstract FSEntry GetMyNetworkFSEntry ();
-
- public abstract void WriteRecentlyUsedFiles (string fileToAdd);
-
- public abstract ArrayList GetRecentlyUsedFiles ();
-
- public abstract ArrayList GetMyComputerContent ();
-
- public abstract ArrayList GetMyNetworkContent ();
- }
- #endregion
-
- #region UnixFileSystem
- internal class UnixFileSystem : FileSystem
- {
- private MasterMount masterMount = new MasterMount ();
- private FSEntry desktopFSEntry = null;
- private FSEntry recentlyusedFSEntry = null;
- private FSEntry personalFSEntry = null;
- private FSEntry mycomputerpersonalFSEntry = null;
- private FSEntry mycomputerFSEntry = null;
- private FSEntry mynetworkFSEntry = null;
-
- private string personal_folder;
- private string recently_used_path;
- private string full_kde_recent_document_dir;
-
- public UnixFileSystem ()
- {
- personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- recently_used_path = Path.Combine (personal_folder, ".recently-used");
-
- full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
-
- desktopFSEntry = new FSEntry ();
-
- desktopFSEntry.Attributes = FileAttributes.Directory;
- desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
- desktopFSEntry.Name = "Desktop";
- desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
- desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
- desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
- desktopFSEntry.LastAccessTime = DateTime.Now;
-
- recentlyusedFSEntry = new FSEntry ();
-
- recentlyusedFSEntry.Attributes = FileAttributes.Directory;
- recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
- recentlyusedFSEntry.Name = "Recently Used";
- recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
- recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
- recentlyusedFSEntry.LastAccessTime = DateTime.Now;
-
- personalFSEntry = new FSEntry ();
-
- personalFSEntry.Attributes = FileAttributes.Directory;
- personalFSEntry.FullName = MWFVFS.PersonalPrefix;
- personalFSEntry.Name = "Personal";
- personalFSEntry.MainTopNode = GetDesktopFSEntry ();
- personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
- personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
- personalFSEntry.LastAccessTime = DateTime.Now;
-
- mycomputerpersonalFSEntry = new FSEntry ();
-
- mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
- mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
- mycomputerpersonalFSEntry.Name = "Personal";
- mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
- mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
- mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
-
- mycomputerFSEntry = new FSEntry ();
-
- mycomputerFSEntry.Attributes = FileAttributes.Directory;
- mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
- mycomputerFSEntry.Name = "My Computer";
- mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
- mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
- mycomputerFSEntry.LastAccessTime = DateTime.Now;
-
- mynetworkFSEntry = new FSEntry ();
-
- mynetworkFSEntry.Attributes = FileAttributes.Directory;
- mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
- mynetworkFSEntry.Name = "My Network";
- mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
- mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
- mynetworkFSEntry.LastAccessTime = DateTime.Now;
- }
-
- public override void WriteRecentlyUsedFiles (string fileToAdd)
- {
- if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
- XmlDocument xml_doc = new XmlDocument ();
- xml_doc.Load (recently_used_path);
-
- XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
-
- if (grand_parent_node != null) {
- // create a new element
- XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
-
- XmlElement new_child = xml_doc.CreateElement ("URI");
- UriBuilder ub = new UriBuilder ();
- ub.Path = fileToAdd;
- ub.Host = null;
- ub.Scheme = "file";
- XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Mime-Type");
- new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Timestamp");
- long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
- new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Groups");
-
- new_recent_item_node.AppendChild (new_child);
-
- // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
- // so that the new node is the first one
- foreach (XmlNode n in grand_parent_node.ChildNodes) {
- XmlNode uri_node = n.SelectSingleNode ("URI");
- if (uri_node != null) {
- XmlNode uri_node_child = uri_node.FirstChild;
- if (uri_node_child is XmlText)
- if (ub.ToString () == ((XmlText)uri_node_child).Data) {
- grand_parent_node.RemoveChild (n);
- break;
- }
- }
- }
-
- // prepend the new recent item to the grand parent node list
- grand_parent_node.PrependChild (new_recent_item_node);
-
- // limit the # of RecentItems to 10
- if (grand_parent_node.ChildNodes.Count > 10) {
- while (grand_parent_node.ChildNodes.Count > 10)
- grand_parent_node.RemoveChild (grand_parent_node.LastChild);
- }
-
- try {
- xml_doc.Save (recently_used_path);
- } catch (Exception) {
- }
- }
- } else {
- XmlDocument xml_doc = new XmlDocument ();
- xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
-
- XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
-
- XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
-
- XmlElement new_child = xml_doc.CreateElement ("URI");
- UriBuilder ub = new UriBuilder ();
- ub.Path = fileToAdd;
- ub.Host = null;
- ub.Scheme = "file";
- XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Mime-Type");
- new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Timestamp");
- long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
- new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Groups");
-
- new_recent_item_node.AppendChild (new_child);
-
- recentFiles_element.AppendChild (new_recent_item_node);
-
- xml_doc.AppendChild (recentFiles_element);
-
- try {
- xml_doc.Save (recently_used_path);
- } catch (Exception) {
- }
- }
- }
-
- // return an ArrayList with FSEntry objects
- public override ArrayList GetRecentlyUsedFiles ()
- {
- // check for GNOME and KDE
-
- ArrayList files_al = new ArrayList ();
-
- // GNOME
- if (File.Exists (recently_used_path)) {
- try {
- XmlTextReader xtr = new XmlTextReader (recently_used_path);
- while (xtr.Read ()) {
- if (xtr.NodeType == XmlNodeType.Element && xtr.Name.ToUpper () == "URI") {
- xtr.Read ();
- Uri uri = new Uri (xtr.Value);
- if (!files_al.Contains (uri.LocalPath))
- if (File.Exists (uri.LocalPath)) {
- FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
- if (fs != null)
- files_al.Add (fs);
- }
- }
- }
- xtr.Close ();
- } catch (Exception) {
-
- }
- }
-
- // KDE
- if (Directory.Exists (full_kde_recent_document_dir)) {
- string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
-
- foreach (string file_name in files) {
- StreamReader sr = new StreamReader (file_name);
-
- string line = sr.ReadLine ();
-
- while (line != null) {
- line = line.Trim ();
-
- if (line.StartsWith ("URL=")) {
- line = line.Replace ("URL=", String.Empty);
- line = line.Replace ("$HOME", personal_folder);
-
- Uri uri = new Uri (line);
- if (!files_al.Contains (uri.LocalPath))
- if (File.Exists (uri.LocalPath)) {
- FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
- if (fs != null)
- files_al.Add (fs);
- }
- break;
- }
-
- line = sr.ReadLine ();
- }
-
- sr.Close ();
- }
- }
-
-
- return files_al;
- }
-
- // return an ArrayList with FSEntry objects
- public override ArrayList GetMyComputerContent ()
- {
- ArrayList my_computer_content_arraylist = new ArrayList ();
-
- if (masterMount.ProcMountAvailable) {
- masterMount.GetMounts ();
-
- foreach (MasterMount.Mount mount in masterMount.Block_devices) {
- FSEntry fsEntry = new FSEntry ();
- fsEntry.FileType = FSEntry.FSEntryType.Device;
-
- fsEntry.FullName = mount.mount_point;
-
- fsEntry.Name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
-
- fsEntry.FsType = mount.fsType;
- fsEntry.DeviceShort = mount.device_short;
-
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
-
- fsEntry.Attributes = FileAttributes.Directory;
-
- fsEntry.MainTopNode = GetMyComputerFSEntry ();
-
- my_computer_content_arraylist.Add (fsEntry);
-
- if (!MWFVFS.MyComputerDevicesPrefix.Contains (fsEntry.FullName + "://"))
- MWFVFS.MyComputerDevicesPrefix.Add (fsEntry.FullName + "://", fsEntry);
- }
-
- foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
- FSEntry fsEntry = new FSEntry ();
- fsEntry.FileType = FSEntry.FSEntryType.RemovableDevice;
-
- fsEntry.FullName = mount.mount_point;
-
- bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
- string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
- string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
-
- fsEntry.Name = type_name +" (" + mount.device_short + ")";
-
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType (mime_type);
-
- fsEntry.FsType = mount.fsType;
- fsEntry.DeviceShort = mount.device_short;
-
- fsEntry.Attributes = FileAttributes.Directory;
-
- fsEntry.MainTopNode = GetMyComputerFSEntry ();
-
- my_computer_content_arraylist.Add (fsEntry);
-
- string contain_string = fsEntry.FullName + "://";
- if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
- MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
- }
- }
-
- my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
-
- return my_computer_content_arraylist;
- }
-
- public override ArrayList GetMyNetworkContent ()
- {
- ArrayList fsEntries = new ArrayList ();
-
- foreach (MasterMount.Mount mount in masterMount.Network_devices) {
- FSEntry fsEntry = new FSEntry ();
- fsEntry.FileType = FSEntry.FSEntryType.Network;
-
- fsEntry.FullName = mount.mount_point;
-
- fsEntry.FsType = mount.fsType;
- fsEntry.DeviceShort = mount.device_short;
-
- fsEntry.Name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
-
- switch (mount.fsType) {
- case MasterMount.FsTypes.nfs:
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
- break;
- case MasterMount.FsTypes.smbfs:
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
- break;
- case MasterMount.FsTypes.ncpfs:
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
- break;
- case MasterMount.FsTypes.cifs:
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
- break;
- default:
- break;
- }
-
- fsEntry.Attributes = FileAttributes.Directory;
-
- fsEntry.MainTopNode = GetMyNetworkFSEntry ();
-
- fsEntries.Add (fsEntry);
- }
- return fsEntries;
- }
-
- protected override FSEntry GetDesktopFSEntry ()
- {
- return desktopFSEntry;
- }
-
- protected override FSEntry GetRecentlyUsedFSEntry ()
- {
- return recentlyusedFSEntry;
- }
-
- protected override FSEntry GetPersonalFSEntry ()
- {
- return personalFSEntry;
- }
-
- protected override FSEntry GetMyComputerPersonalFSEntry ()
- {
- return mycomputerpersonalFSEntry;
- }
-
- protected override FSEntry GetMyComputerFSEntry ()
- {
- return mycomputerFSEntry;
- }
-
- protected override FSEntry GetMyNetworkFSEntry ()
- {
- return mynetworkFSEntry;
- }
- }
- #endregion
-
- #region WinFileSystem
- internal class WinFileSystem : FileSystem
- {
- private FSEntry desktopFSEntry = null;
- private FSEntry recentlyusedFSEntry = null;
- private FSEntry personalFSEntry = null;
- private FSEntry mycomputerpersonalFSEntry = null;
- private FSEntry mycomputerFSEntry = null;
- private FSEntry mynetworkFSEntry = null;
-
- public WinFileSystem ()
- {
- desktopFSEntry = new FSEntry ();
-
- desktopFSEntry.Attributes = FileAttributes.Directory;
- desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
- desktopFSEntry.Name = "Desktop";
- desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
- desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
- desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
- desktopFSEntry.LastAccessTime = DateTime.Now;
-
- recentlyusedFSEntry = new FSEntry ();
-
- recentlyusedFSEntry.Attributes = FileAttributes.Directory;
- recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
- recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
- recentlyusedFSEntry.Name = "Recently Used";
- recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
- recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
- recentlyusedFSEntry.LastAccessTime = DateTime.Now;
-
- personalFSEntry = new FSEntry ();
-
- personalFSEntry.Attributes = FileAttributes.Directory;
- personalFSEntry.FullName = MWFVFS.PersonalPrefix;
- personalFSEntry.Name = "Personal";
- personalFSEntry.MainTopNode = GetDesktopFSEntry ();
- personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
- personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
- personalFSEntry.LastAccessTime = DateTime.Now;
-
- mycomputerpersonalFSEntry = new FSEntry ();
-
- mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
- mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
- mycomputerpersonalFSEntry.Name = "Personal";
- mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
- mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
- mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
-
- mycomputerFSEntry = new FSEntry ();
-
- mycomputerFSEntry.Attributes = FileAttributes.Directory;
- mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
- mycomputerFSEntry.Name = "My Computer";
- mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
- mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
- mycomputerFSEntry.LastAccessTime = DateTime.Now;
-
- mynetworkFSEntry = new FSEntry ();
-
- mynetworkFSEntry.Attributes = FileAttributes.Directory;
- mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
- mynetworkFSEntry.Name = "My Network";
- mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
- mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
- mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
- mynetworkFSEntry.LastAccessTime = DateTime.Now;
- }
-
- public override void WriteRecentlyUsedFiles (string fileToAdd)
- {
- // TODO: Implement this method
- // use SHAddToRecentDocs ?
- }
-
- public override ArrayList GetRecentlyUsedFiles ()
- {
- ArrayList al = new ArrayList ();
-
- DirectoryInfo di = new DirectoryInfo (recentlyusedFSEntry.RealName);
-
- FileInfo[] fileinfos = di.GetFiles ();
-
- foreach (FileInfo fi in fileinfos) {
- FSEntry fs = GetFileFSEntry (fi);
- if (fs != null)
- al.Add (fs);
- }
-
- return al;
- }
-
- public override ArrayList GetMyComputerContent ()
- {
- string[] logical_drives = Directory.GetLogicalDrives ();
-
- ArrayList my_computer_content_arraylist = new ArrayList ();
-
- foreach (string drive in logical_drives) {
- FSEntry fsEntry = new FSEntry ();
- fsEntry.FileType = FSEntry.FSEntryType.Device;
-
- fsEntry.FullName = drive;
-
- fsEntry.Name = drive;
-
- fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
-
- fsEntry.Attributes = FileAttributes.Directory;
-
- fsEntry.MainTopNode = GetMyComputerFSEntry ();
-
- my_computer_content_arraylist.Add (fsEntry);
-
- string contain_string = fsEntry.FullName + "://";
- if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
- MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
- }
-
- my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
-
- return my_computer_content_arraylist;
- }
-
- public override ArrayList GetMyNetworkContent ()
- {
- // TODO: Implement this method
- return new ArrayList ();
- }
- protected override FSEntry GetDesktopFSEntry ()
- {
- return desktopFSEntry;
- }
-
- protected override FSEntry GetRecentlyUsedFSEntry ()
- {
- return recentlyusedFSEntry;
- }
-
- protected override FSEntry GetPersonalFSEntry ()
- {
- return personalFSEntry;
- }
-
- protected override FSEntry GetMyComputerPersonalFSEntry ()
- {
- return mycomputerpersonalFSEntry;
- }
-
- protected override FSEntry GetMyComputerFSEntry ()
- {
- return mycomputerFSEntry;
- }
-
- protected override FSEntry GetMyNetworkFSEntry ()
- {
- return mynetworkFSEntry;
- }
- }
- #endregion
-
- #region FSEntry
- internal class FSEntry
- {
- public enum FSEntryType
- {
- Desktop,
- RecentlyUsed,
- MyComputer,
- File,
- Directory,
- Device,
- RemovableDevice,
- Network
- }
-
- private MasterMount.FsTypes fsType;
- private string device_short;
- private string fullName;
- private string name;
- private string realName = null;
- private FileAttributes attributes = FileAttributes.Normal;
- private long fileSize;
- private FSEntryType fileType;
- private DateTime lastAccessTime;
- private FSEntry mainTopNode = null;
-
- private int iconIndex;
-
- private string parent;
-
- public MasterMount.FsTypes FsType {
- set {
- fsType = value;
- }
-
- get {
- return fsType;
- }
- }
-
- public string DeviceShort {
- set {
- device_short = value;
- }
-
- get {
- return device_short;
- }
- }
-
- public string FullName {
- set {
- fullName = value;
- }
-
- get {
- return fullName;
- }
- }
-
- public string Name {
- set {
- name = value;
- }
-
- get {
- return name;
- }
- }
-
- public string RealName {
- set {
- realName = value;
- }
-
- get {
- return realName;
- }
- }
-
- public FileAttributes Attributes {
- set {
- attributes = value;
- }
-
- get {
- return attributes;
- }
- }
-
- public long FileSize {
- set {
- fileSize = value;
- }
-
- get {
- return fileSize;
- }
- }
-
- public FSEntryType FileType {
- set {
- fileType = value;
- }
-
- get {
- return fileType;
- }
- }
-
- public DateTime LastAccessTime {
- set {
- lastAccessTime = value;
- }
-
- get {
- return lastAccessTime;
- }
- }
-
- public int IconIndex {
- set {
- iconIndex = value;
- }
-
- get {
- return iconIndex;
- }
- }
-
- public FSEntry MainTopNode {
- set {
- mainTopNode = value;
- }
-
- get {
- return mainTopNode;
- }
- }
-
- public string Parent {
- set {
- parent = value;
- }
-
- get {
- parent = GetParent ();
-
- return parent;
- }
- }
-
- private string GetParent ()
- {
- if (fullName == MWFVFS.PersonalPrefix) {
- return MWFVFS.DesktopPrefix;
- } else
- if (fullName == MWFVFS.MyComputerPersonalPrefix) {
- return MWFVFS.MyComputerPrefix;
- } else
- if (fullName == MWFVFS.MyComputerPrefix) {
- return MWFVFS.DesktopPrefix;
- } else
- if (fullName == MWFVFS.MyNetworkPrefix) {
- return MWFVFS.DesktopPrefix;
- } else
- if (fullName == MWFVFS.DesktopPrefix) {
- return null;
- } else
- if (fullName == MWFVFS.RecentlyUsedPrefix) {
- return null;
- } else {
- foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
- FSEntry fsEntry = entry.Value as FSEntry;
- if (fullName == fsEntry.FullName) {
- return fsEntry.MainTopNode.FullName;
- }
- }
-
- DirectoryInfo dirInfo = new DirectoryInfo (fullName);
-
- DirectoryInfo dirInfoParent = dirInfo.Parent;
-
- if (dirInfoParent != null) {
- FSEntry fsEntry = MWFVFS.MyComputerDevicesPrefix [dirInfoParent.FullName + "://"] as FSEntry;
-
- if (fsEntry != null) {
- return fsEntry.FullName;
- }
-
- if (mainTopNode != null) {
- if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop) &&
- mainTopNode.FullName == MWFVFS.DesktopPrefix) {
- return mainTopNode.FullName;
- } else
- if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
- mainTopNode.FullName == MWFVFS.PersonalPrefix) {
- return mainTopNode.FullName;
- } else
- if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
- mainTopNode.FullName == MWFVFS.MyComputerPersonalPrefix) {
- return mainTopNode.FullName;
- }
- }
-
- return dirInfoParent.FullName;
- }
- }
-
- return null;
- }
- }
- #endregion
-
- #region MasterMount
- // Alexsantas little *nix helper
- internal class MasterMount
- {
- // add more...
- internal enum FsTypes
- {
- none,
- ext2,
- ext3,
- hpfs,
- iso9660,
- jfs,
- minix,
- msdos,
- ntfs,
- reiserfs,
- ufs,
- umsdos,
- vfat,
- sysv,
- xfs,
- ncpfs,
- nfs,
- smbfs,
- usbfs,
- cifs
- }
-
- internal struct Mount
- {
- public string device_or_filesystem;
- public string device_short;
- public string mount_point;
- public FsTypes fsType;
- }
-
- bool proc_mount_available = false;
-
- ArrayList block_devices = new ArrayList ();
- ArrayList network_devices = new ArrayList ();
- ArrayList removable_devices = new ArrayList ();
-
- private int platform = (int) Environment.OSVersion.Platform;
- private MountComparer mountComparer = new MountComparer ();
-
- public MasterMount ()
- {
- // maybe check if the current user can access /proc/mounts
- if ((platform == 4) || (platform == 128))
- if (File.Exists ("/proc/mounts"))
- proc_mount_available = true;
- }
-
- public ArrayList Block_devices {
- get {
- return block_devices;
- }
- }
-
- public ArrayList Network_devices {
- get {
- return network_devices;
- }
- }
-
- public ArrayList Removable_devices {
- get {
- return removable_devices;
- }
- }
-
- public bool ProcMountAvailable {
- get {
- return proc_mount_available;
- }
- }
-
- public void GetMounts ()
- {
- if (!proc_mount_available)
- return;
-
- block_devices.Clear ();
- network_devices.Clear ();
- removable_devices.Clear ();
-
- try {
- StreamReader sr = new StreamReader ("/proc/mounts");
-
- string line = sr.ReadLine ();
-
- ArrayList lines = new ArrayList ();
- while (line != null) {
- if (lines.IndexOf (line) == -1) { // Avoid duplicates
- ProcessProcMountLine (line);
- lines.Add (line);
- }
- line = sr.ReadLine ();
- }
-
- sr.Close ();
-
- block_devices.Sort (mountComparer);
- network_devices.Sort (mountComparer);
- removable_devices.Sort (mountComparer);
- } catch {
- // bla
- }
- }
-
- private void ProcessProcMountLine (string line)
- {
- string[] split = line.Split (new char [] {' '});
-
- if (split != null && split.Length > 0) {
- Mount mount = new Mount ();
-
- if (split [0].StartsWith ("/dev/"))
- mount.device_short = split [0].Replace ("/dev/", String.Empty);
- else
- mount.device_short = split [0];
-
- mount.device_or_filesystem = split [0];
- mount.mount_point = split [1];
-
- // TODO: other removable devices, floppy
- // ssh
-
- // network mount
- if (split [2] == "nfs") {
- mount.fsType = FsTypes.nfs;
- network_devices.Add (mount);
- } else if (split [2] == "smbfs") {
- mount.fsType = FsTypes.smbfs;
- network_devices.Add (mount);
- } else if (split [2] == "cifs") {
- mount.fsType = FsTypes.cifs;
- network_devices.Add (mount);
- } else if (split [2] == "ncpfs") {
- mount.fsType = FsTypes.ncpfs;
- network_devices.Add (mount);
-
- } else if (split [2] == "iso9660") { //cdrom
- mount.fsType = FsTypes.iso9660;
- removable_devices.Add (mount);
- } else if (split [2] == "usbfs") { //usb ? not tested
- mount.fsType = FsTypes.usbfs;
- removable_devices.Add (mount);
-
- } else if (split [0].StartsWith ("/")) { //block devices
- if (split [1].StartsWith ("/dev/")) // root static, do not add
- return;
-
- if (split [2] == "ext2")
- mount.fsType = FsTypes.ext2;
- else if (split [2] == "ext3")
- mount.fsType = FsTypes.ext3;
- else if (split [2] == "reiserfs")
- mount.fsType = FsTypes.reiserfs;
- else if (split [2] == "xfs")
- mount.fsType = FsTypes.xfs;
- else if (split [2] == "vfat")
- mount.fsType = FsTypes.vfat;
- else if (split [2] == "ntfs")
- mount.fsType = FsTypes.ntfs;
- else if (split [2] == "msdos")
- mount.fsType = FsTypes.msdos;
- else if (split [2] == "umsdos")
- mount.fsType = FsTypes.umsdos;
- else if (split [2] == "hpfs")
- mount.fsType = FsTypes.hpfs;
- else if (split [2] == "minix")
- mount.fsType = FsTypes.minix;
- else if (split [2] == "jfs")
- mount.fsType = FsTypes.jfs;
-
- block_devices.Add (mount);
- }
- }
- }
-
- public class MountComparer : IComparer
- {
- public int Compare (object mount1, object mount2)
- {
- return String.Compare (((Mount)mount1).device_short, ((Mount)mount2).device_short);
- }
- }
- }
- #endregion
-
- #region MWFConfig
- // easy to use class to store and read internal MWF config settings.
- // the config values are stored in the users home dir as a hidden xml file called "mwf_config".
- // currently supports int, string, byte, color and arrays (including byte arrays)
- // don't forget, when you read a value you still have to cast this value.
- //
- // usage:
- // MWFConfig.SetValue ("SomeClass", "What", value);
- // object o = MWFConfig.GetValue ("SomeClass", "What");
- //
- // example:
- //
- // string[] configFileNames = (string[])MWFConfig.GetValue ("FileDialog", "FileNames");
- // MWFConfig.SetValue ("FileDialog", "LastFolder", "/home/user");
-
- internal class MWFConfig
- {
- private static MWFConfigInstance Instance = new MWFConfigInstance ();
-
- private static object lock_object = new object();
-
- public static object GetValue (string class_name, string value_name)
- {
- lock (lock_object) {
- return Instance.GetValue (class_name, value_name);
- }
- }
-
- public static void SetValue (string class_name, string value_name, object value)
- {
- lock (lock_object) {
- Instance.SetValue (class_name, value_name, value);
- }
- }
-
- public static void Flush ()
- {
- lock (lock_object) {
- Instance.Flush ();
- }
- }
-
- public static void RemoveClass (string class_name)
- {
- lock (lock_object) {
- Instance.RemoveClass (class_name);
- }
- }
-
- public static void RemoveClassValue (string class_name, string value_name)
- {
- lock (lock_object) {
- Instance.RemoveClassValue (class_name, value_name);
- }
- }
-
- public static void RemoveAllClassValues (string class_name)
- {
- lock (lock_object) {
- Instance.RemoveAllClassValues (class_name);
- }
- }
-
- internal class MWFConfigInstance
- {
- Hashtable classes_hashtable = new Hashtable ();
- string path;
- static string full_file_name;
- XmlTextReader xtr;
- XmlTextWriter xtw;
- static string default_file_name;
- readonly string configName = "MWFConfig";
- static int platform = (int) Environment.OSVersion.Platform;
- static bool IsUnix ()
- {
- return (platform == 4 || platform == 128);
- }
- static MWFConfigInstance ()
- {
- string b = "mwf_config";
- string dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-
- if (IsUnix ()){
- dir = Path.Combine (dir, ".mono");
- try {
- Directory.CreateDirectory (dir);
- } catch {}
- }
- default_file_name = Path.Combine (dir, b);
- full_file_name = default_file_name;
- }
-
- public MWFConfigInstance ()
- {
- Open (default_file_name);
- }
-
- // only for testing
- public MWFConfigInstance (string filename)
- {
- path = Path.GetDirectoryName (filename);
- if (path == null || path == String.Empty) {
- path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-
- full_file_name = Path.Combine (path, filename);
- } else
- full_file_name = filename;
- Open (full_file_name);
- }
-
- ~MWFConfigInstance ()
- {
- Flush ();
- }
-
- public object GetValue (string class_name, string value_name)
- {
- ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
-
- if (class_entry != null)
- return class_entry.GetValue (value_name);
-
- return null;
- }
-
- public void SetValue (string class_name, string value_name, object value)
- {
- ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
-
- if (class_entry == null) {
- class_entry = new ClassEntry ();
- class_entry.ClassName = class_name;
- classes_hashtable [class_name] = class_entry;
- }
-
- class_entry.SetValue (value_name, value);
- }
-
- private void Open (string filename)
- {
- try {
- xtr = new XmlTextReader (filename);
-
- ReadConfig ();
-
- xtr.Close ();
- } catch (Exception) {
- }
- }
-
- public void Flush ()
- {
- try {
- xtw = new XmlTextWriter (full_file_name, null);
- xtw.Formatting = Formatting.Indented;
-
- WriteConfig ();
-
- xtw.Close ();
- if (!IsUnix ())
- File.SetAttributes (full_file_name, FileAttributes.Hidden);
- } catch (Exception){
- }
- }
-
- public void RemoveClass (string class_name)
- {
- ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
-
- if (class_entry != null) {
- class_entry.RemoveAllClassValues ();
-
- classes_hashtable.Remove (class_name);
- }
- }
-
- public void RemoveClassValue (string class_name, string value_name)
- {
- ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
-
- if (class_entry != null) {
- class_entry.RemoveClassValue (value_name);
- }
- }
-
- public void RemoveAllClassValues (string class_name)
- {
- ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
-
- if (class_entry != null) {
- class_entry.RemoveAllClassValues ();
- }
- }
-
- private void ReadConfig ()
- {
- if (!CheckForMWFConfig ())
- return;
-
- while (xtr.Read ()) {
- switch (xtr.NodeType) {
- case XmlNodeType.Element:
- ClassEntry class_entry = classes_hashtable [xtr.Name] as ClassEntry;
-
- if (class_entry == null) {
- class_entry = new ClassEntry ();
- class_entry.ClassName = xtr.Name;
- classes_hashtable [xtr.Name] = class_entry;
- }
-
- class_entry.ReadXml (xtr);
- break;
- }
- }
- }
-
- private bool CheckForMWFConfig ()
- {
- if (xtr.Read ()) {
- if (xtr.NodeType == XmlNodeType.Element) {
- if (xtr.Name == configName)
- return true;
- }
- }
-
- return false;
- }
-
- private void WriteConfig ()
- {
- if (classes_hashtable.Count == 0)
- return;
-
- xtw.WriteStartElement (configName);
- foreach (DictionaryEntry entry in classes_hashtable) {
- ClassEntry class_entry = entry.Value as ClassEntry;
-
- class_entry.WriteXml (xtw);
- }
- xtw.WriteEndElement ();
- }
-
- internal class ClassEntry
- {
- private Hashtable classvalues_hashtable = new Hashtable ();
- private string className;
-
- public string ClassName {
- set {
- className = value;
- }
-
- get {
- return className;
- }
- }
-
- public void SetValue (string value_name, object value)
- {
- ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
-
- if (class_value == null) {
- class_value = new ClassValue ();
- class_value.Name = value_name;
- classvalues_hashtable [value_name] = class_value;
- }
-
- class_value.SetValue (value);
- }
-
- public object GetValue (string value_name)
- {
- ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
-
- if (class_value == null) {
- return null;
- }
-
- return class_value.GetValue ();
- }
-
- public void RemoveAllClassValues ()
- {
- classvalues_hashtable.Clear ();
- }
-
- public void RemoveClassValue (string value_name)
- {
- ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
-
- if (class_value != null) {
- classvalues_hashtable.Remove (value_name);
- }
- }
-
- public void ReadXml (XmlTextReader xtr)
- {
- while (xtr.Read ()) {
- switch (xtr.NodeType) {
- case XmlNodeType.Element:
- string name = xtr.GetAttribute ("name");
-
- ClassValue class_value = classvalues_hashtable [name] as ClassValue;
-
- if (class_value == null) {
- class_value = new ClassValue ();
- class_value.Name = name;
- classvalues_hashtable [name] = class_value;
- }
-
- class_value.ReadXml (xtr);
- break;
-
- case XmlNodeType.EndElement:
- return;
- }
- }
- }
-
- public void WriteXml (XmlTextWriter xtw)
- {
- if (classvalues_hashtable.Count == 0)
- return;
-
- xtw.WriteStartElement (className);
-
- foreach (DictionaryEntry entry in classvalues_hashtable) {
- ClassValue class_value = entry.Value as ClassValue;
-
- class_value.WriteXml (xtw);
- }
-
- xtw.WriteEndElement ();
- }
- }
-
- internal class ClassValue
- {
- private object value;
- private string name;
-
- public string Name {
- set {
- name = value;
- }
-
- get {
- return name;
- }
- }
-
- public void SetValue (object value)
- {
- this.value = value;
- }
- public object GetValue ()
- {
- return value;
- }
-
- public void ReadXml (XmlTextReader xtr)
- {
- string type;
- string single_value;
-
- type = xtr.GetAttribute ("type");
-
- if (type == "byte_array" || type.IndexOf ("-array") == -1) {
- single_value = xtr.ReadString ();
-
- if (type == "string") {
- value = single_value;
- } else
- if (type == "int") {
- value = Int32.Parse (single_value);
- } else
- if (type == "byte") {
- value = Byte.Parse (single_value);
- } else
- if (type == "color") {
- int color = Int32.Parse (single_value);
- value = Color.FromArgb (color);
- } else
- if (type == "byte-array") {
- byte[] b_array = Convert.FromBase64String (single_value);
- value = b_array;
- }
- } else {
- ReadXmlArrayValues (xtr, type);
- }
- }
-
- private void ReadXmlArrayValues (XmlTextReader xtr, string type)
- {
- ArrayList al = new ArrayList ();
-
- while (xtr.Read ()) {
- switch (xtr.NodeType) {
- case XmlNodeType.Element:
- string single_value = xtr.ReadString ();
-
- if (type == "int-array") {
- int int_val = Int32.Parse (single_value);
- al.Add (int_val);
- } else
- if (type == "string-array") {
- string str_val = single_value;
- al.Add (str_val);
- }
- break;
-
- case XmlNodeType.EndElement:
- if (xtr.Name == "value") {
- if (type == "int-array") {
- value = al.ToArray (typeof(int));
- } else
- if (type == "string-array") {
- value = al.ToArray (typeof(string));
- }
- return;
- }
- break;
- }
- }
- }
-
- public void WriteXml (XmlTextWriter xtw)
- {
- xtw.WriteStartElement ("value");
- xtw.WriteAttributeString ("name", name);
- if (value is Array) {
- WriteArrayContent (xtw);
- } else {
- WriteSingleContent (xtw);
- }
- xtw.WriteEndElement ();
- }
-
- private void WriteSingleContent (XmlTextWriter xtw)
- {
- string type_string = String.Empty;
-
- if (value is string)
- type_string = "string";
- else
- if (value is int)
- type_string = "int";
- else
- if (value is byte)
- type_string = "byte";
- else
- if (value is Color)
- type_string = "color";
-
- xtw.WriteAttributeString ("type", type_string);
-
- if (value is Color)
- xtw.WriteString (((Color)value).ToArgb ().ToString ());
- else
- xtw.WriteString (value.ToString ());
- }
-
- private void WriteArrayContent (XmlTextWriter xtw)
- {
- string type_string = String.Empty;
- string type_name = String.Empty;
-
- if (value is string[]) {
- type_string = "string-array";
- type_name = "string";
- } else
- if (value is int[]) {
- type_string = "int-array";
- type_name = "int";
- } else
- if (value is byte[]) {
- type_string = "byte-array";
- type_name = "byte";
- }
-
- xtw.WriteAttributeString ("type", type_string);
-
- if (type_string != "byte-array") {
- Array array = value as Array;
-
- foreach (object o in array) {
- xtw.WriteStartElement (type_name);
- xtw.WriteString (o.ToString ());
- xtw.WriteEndElement ();
- }
- } else {
- byte[] b_array = value as byte [];
-
- xtw.WriteString (Convert.ToBase64String (b_array, 0, b_array.Length));
- }
- }
- }
- }
- }
- #endregion
- }
|