FileDialog.cs 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Authors:
  23. //
  24. // Alexander Olk [email protected]
  25. //
  26. // NOT COMPLETE - work in progress
  27. using System;
  28. using System.Drawing;
  29. using System.ComponentModel;
  30. using System.Resources;
  31. using System.IO;
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.Xml;
  35. using System.Threading;
  36. namespace System.Windows.Forms {
  37. #region FileDialog
  38. [DefaultProperty ("FileName")]
  39. [DefaultEvent ("FileOk")]
  40. public abstract class FileDialog : CommonDialog
  41. {
  42. protected static readonly object EventFileOk = new object ();
  43. internal enum FileDialogType
  44. {
  45. OpenFileDialog,
  46. SaveFileDialog
  47. }
  48. private bool addExtension = true;
  49. private bool checkFileExists = false;
  50. private bool checkPathExists = true;
  51. private string defaultExt = String.Empty;
  52. private bool dereferenceLinks = true;
  53. private string fileName = String.Empty;
  54. private string[] fileNames;
  55. private string filter = "";
  56. private int filterIndex = 1;
  57. private string initialDirectory = String.Empty;
  58. private bool restoreDirectory = false;
  59. private bool showHelp = false;
  60. private string title = String.Empty;
  61. private bool validateNames = true;
  62. private Button cancelButton;
  63. private ToolBarButton upToolBarButton;
  64. private PopupButtonPanel popupButtonPanel;
  65. private Button openSaveButton;
  66. private Button helpButton;
  67. private Label fileTypeLabel;
  68. private ToolBarButton menueToolBarButton;
  69. private ContextMenu menueToolBarButtonContextMenu;
  70. private ToolBar smallButtonToolBar;
  71. private DirComboBox dirComboBox;
  72. private ComboBox fileNameComboBox;
  73. private Label fileNameLabel;
  74. private MWFFileView mwfFileView;
  75. private Label searchSaveLabel;
  76. private ToolBarButton newdirToolBarButton;
  77. private ToolBarButton backToolBarButton;
  78. private ComboBox fileTypeComboBox;
  79. private ImageList imageListTopToolbar;
  80. private CheckBox readonlyCheckBox;
  81. private bool multiSelect = false;
  82. private string restoreDirectoryString = String.Empty;
  83. internal FileDialogType fileDialogType;
  84. private bool do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
  85. private bool showReadOnly = false;
  86. private bool readOnlyChecked = false;
  87. internal bool createPrompt = false;
  88. internal bool overwritePrompt = true;
  89. internal FileFilter fileFilter;
  90. private string lastFolder = String.Empty;
  91. private MWFVFS vfs;
  92. private readonly string filedialog_string = "FileDialog";
  93. private readonly string lastfolder_string = "LastFolder";
  94. private readonly string width_string = "Width";
  95. private readonly string height_string = "Height";
  96. private readonly string filenames_string = "FileNames";
  97. private readonly string x_string = "X";
  98. private readonly string y_string = "Y";
  99. internal FileDialog ()
  100. {
  101. vfs = new MWFVFS ();
  102. Size formConfigSize = Size.Empty;
  103. Point formConfigLocation = Point.Empty;
  104. string[] configFileNames = null;
  105. object formWidth = MWFConfig.GetValue (filedialog_string, width_string);
  106. object formHeight = MWFConfig.GetValue (filedialog_string, height_string);
  107. if (formHeight != null && formWidth != null)
  108. formConfigSize = new Size ((int)formWidth, (int)formHeight);
  109. object formLocationX = MWFConfig.GetValue (filedialog_string, x_string);
  110. object formLocationY = MWFConfig.GetValue (filedialog_string, y_string);
  111. if (formLocationX != null && formLocationY != null)
  112. formConfigLocation = new Point ((int)formLocationX, (int)formLocationY);
  113. configFileNames = (string[])MWFConfig.GetValue (filedialog_string, filenames_string);
  114. fileTypeComboBox = new ComboBox ();
  115. backToolBarButton = new ToolBarButton ();
  116. newdirToolBarButton = new ToolBarButton ();
  117. searchSaveLabel = new Label ();
  118. mwfFileView = new MWFFileView (vfs);
  119. fileNameLabel = new Label ();
  120. fileNameComboBox = new ComboBox ();
  121. dirComboBox = new DirComboBox (vfs);
  122. smallButtonToolBar = new ToolBar ();
  123. menueToolBarButton = new ToolBarButton ();
  124. fileTypeLabel = new Label ();
  125. openSaveButton = new Button ();
  126. form.AcceptButton = openSaveButton;
  127. helpButton = new Button ();
  128. popupButtonPanel = new PopupButtonPanel ();
  129. upToolBarButton = new ToolBarButton ();
  130. cancelButton = new Button ();
  131. form.CancelButton = cancelButton;
  132. imageListTopToolbar = new ImageList ();
  133. menueToolBarButtonContextMenu = new ContextMenu ();
  134. readonlyCheckBox = new CheckBox ();
  135. form.SuspendLayout ();
  136. //imageListTopToolbar
  137. imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
  138. imageListTopToolbar.ImageSize = new Size (16, 16); // 16, 16
  139. imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-previous.png"));
  140. imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-top.png"));
  141. imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("folder-new.png"));
  142. imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("preferences-system-windows.png"));
  143. imageListTopToolbar.TransparentColor = Color.Transparent;
  144. // searchLabel
  145. searchSaveLabel.FlatStyle = FlatStyle.System;
  146. searchSaveLabel.Location = new Point (7, 8);
  147. searchSaveLabel.Size = new Size (72, 21);
  148. searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
  149. // dirComboBox
  150. dirComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
  151. dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  152. dirComboBox.Location = new Point (99, 8);
  153. dirComboBox.Size = new Size (260, 21);
  154. dirComboBox.TabIndex = 7;
  155. // smallButtonToolBar
  156. smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
  157. smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
  158. smallButtonToolBar.AutoSize = false;
  159. smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
  160. backToolBarButton,
  161. upToolBarButton,
  162. newdirToolBarButton,
  163. menueToolBarButton});
  164. smallButtonToolBar.ButtonSize = new Size (24, 24); // 21, 16
  165. smallButtonToolBar.Divider = false;
  166. smallButtonToolBar.Dock = DockStyle.None;
  167. smallButtonToolBar.DropDownArrows = true;
  168. smallButtonToolBar.ImageList = imageListTopToolbar;
  169. smallButtonToolBar.Location = new Point (372, 6);
  170. smallButtonToolBar.ShowToolTips = true;
  171. smallButtonToolBar.Size = new Size (140, 28);
  172. smallButtonToolBar.TabIndex = 8;
  173. smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
  174. // buttonPanel
  175. popupButtonPanel.Dock = DockStyle.None;
  176. popupButtonPanel.Location = new Point (7, 37);
  177. popupButtonPanel.TabIndex = 9;
  178. // mwfFileView
  179. mwfFileView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
  180. mwfFileView.Location = new Point (99, 37);
  181. mwfFileView.Size = new Size (449, 282);
  182. mwfFileView.Columns.Add (" Name", 170, HorizontalAlignment.Left);
  183. mwfFileView.Columns.Add ("Size ", 80, HorizontalAlignment.Right);
  184. mwfFileView.Columns.Add (" Type", 100, HorizontalAlignment.Left);
  185. mwfFileView.Columns.Add (" Last Access", 150, HorizontalAlignment.Left);
  186. mwfFileView.AllowColumnReorder = true;
  187. mwfFileView.MultiSelect = false;
  188. mwfFileView.TabIndex = 10;
  189. mwfFileView.RegisterSender (dirComboBox);
  190. mwfFileView.RegisterSender (popupButtonPanel);
  191. // fileNameLabel
  192. fileNameLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
  193. fileNameLabel.FlatStyle = FlatStyle.System;
  194. fileNameLabel.Location = new Point (102, 330);
  195. fileNameLabel.Size = new Size (70, 21);
  196. fileNameLabel.Text = "Filename:";
  197. fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
  198. // fileNameComboBox
  199. fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
  200. fileNameComboBox.Location = new Point (195, 330);
  201. fileNameComboBox.Size = new Size (245, 21);
  202. fileNameComboBox.TabIndex = 1;
  203. fileNameComboBox.MaxDropDownItems = 10;
  204. fileNameComboBox.Items.Add (" ");
  205. if (configFileNames != null) {
  206. fileNameComboBox.Items.Clear ();
  207. foreach (string configFileName in configFileNames) {
  208. if (configFileName != null)
  209. if (configFileName.Trim ().Length > 0)
  210. fileNameComboBox.Items.Add (configFileName);
  211. }
  212. }
  213. // fileTypeLabel
  214. fileTypeLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
  215. fileTypeLabel.FlatStyle = FlatStyle.System;
  216. fileTypeLabel.Location = new Point (102, 356);
  217. fileTypeLabel.Size = new Size (70, 21);
  218. fileTypeLabel.Text = "Filetype:";
  219. fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
  220. // fileTypeComboBox
  221. fileTypeComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
  222. fileTypeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  223. fileTypeComboBox.Location = new Point (195, 356);
  224. fileTypeComboBox.Size = new Size (245, 21);
  225. fileTypeComboBox.TabIndex = 2;
  226. // backToolBarButton
  227. backToolBarButton.ImageIndex = 0;
  228. backToolBarButton.Enabled = false;
  229. backToolBarButton.Style = ToolBarButtonStyle.PushButton;
  230. mwfFileView.AddControlToEnableDisableByDirStack (backToolBarButton);
  231. // upToolBarButton
  232. upToolBarButton.ImageIndex = 1;
  233. upToolBarButton.Style = ToolBarButtonStyle.PushButton;
  234. mwfFileView.SetFolderUpToolBarButton (upToolBarButton);
  235. // newdirToolBarButton
  236. newdirToolBarButton.ImageIndex = 2;
  237. newdirToolBarButton.Style = ToolBarButtonStyle.PushButton;
  238. // menueToolBarButton
  239. menueToolBarButton.ImageIndex = 3;
  240. menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
  241. menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
  242. // menueToolBarButtonContextMenu
  243. menueToolBarButtonContextMenu.MenuItems.AddRange (mwfFileView.ViewMenuItems);
  244. // openSaveButton
  245. openSaveButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
  246. openSaveButton.FlatStyle = FlatStyle.System;
  247. openSaveButton.Location = new Point (475, 330);
  248. openSaveButton.Size = new Size (72, 21);
  249. openSaveButton.TabIndex = 4;
  250. openSaveButton.FlatStyle = FlatStyle.System;
  251. // cancelButton
  252. cancelButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
  253. cancelButton.FlatStyle = FlatStyle.System;
  254. cancelButton.Location = new Point (475, 356);
  255. cancelButton.Size = new Size (72, 21);
  256. cancelButton.TabIndex = 5;
  257. cancelButton.Text = "Cancel";
  258. cancelButton.FlatStyle = FlatStyle.System;
  259. // helpButton
  260. helpButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
  261. helpButton.FlatStyle = FlatStyle.System;
  262. helpButton.Location = new Point (475, 350);
  263. helpButton.Size = new Size (72, 21);
  264. helpButton.TabIndex = 6;
  265. helpButton.Text = "Help";
  266. helpButton.FlatStyle = FlatStyle.System;
  267. // checkBox
  268. readonlyCheckBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
  269. readonlyCheckBox.Text = "Open Readonly";
  270. readonlyCheckBox.Location = new Point (195, 350);
  271. readonlyCheckBox.Size = new Size (245, 21);
  272. readonlyCheckBox.TabIndex = 3;
  273. readonlyCheckBox.FlatStyle = FlatStyle.System;
  274. form.SizeGripStyle = SizeGripStyle.Show;
  275. form.MaximizeBox = true;
  276. form.MinimizeBox = true;
  277. form.FormBorderStyle = FormBorderStyle.Sizable;
  278. form.MinimumSize = new Size (554, 405);
  279. form.ClientSize = new Size (554, 405); // 384
  280. form.Controls.Add (smallButtonToolBar);
  281. form.Controls.Add (cancelButton);
  282. form.Controls.Add (openSaveButton);
  283. form.Controls.Add (mwfFileView);
  284. form.Controls.Add (fileTypeLabel);
  285. form.Controls.Add (fileNameLabel);
  286. form.Controls.Add (fileTypeComboBox);
  287. form.Controls.Add (fileNameComboBox);
  288. form.Controls.Add (dirComboBox);
  289. form.Controls.Add (searchSaveLabel);
  290. form.Controls.Add (popupButtonPanel);
  291. form.ResumeLayout (false);
  292. if (formConfigSize != Size.Empty) {
  293. form.Size = formConfigSize;
  294. }
  295. if (formConfigLocation != Point.Empty) {
  296. form.Location = formConfigLocation;
  297. }
  298. openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
  299. cancelButton.Click += new EventHandler (OnClickCancelButton);
  300. helpButton.Click += new EventHandler (OnClickHelpButton);
  301. smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler (OnClickSmallButtonToolBar);
  302. fileTypeComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedFileTypeComboBox);
  303. mwfFileView.SelectedFileChanged += new EventHandler (OnSelectedFileChangedFileView);
  304. mwfFileView.ForceDialogEnd += new EventHandler (OnForceDialogEndFileView);
  305. mwfFileView.SelectedFilesChanged += new EventHandler (OnSelectedFilesChangedFileView);
  306. dirComboBox.DirectoryChanged += new EventHandler (OnDirectoryChangedDirComboBox);
  307. popupButtonPanel.DirectoryChanged += new EventHandler (OnDirectoryChangedPopupButtonPanel);
  308. readonlyCheckBox.CheckedChanged += new EventHandler (OnCheckCheckChanged);
  309. }
  310. [DefaultValue(true)]
  311. public bool AddExtension {
  312. get {
  313. return addExtension;
  314. }
  315. set {
  316. addExtension = value;
  317. }
  318. }
  319. [DefaultValue(false)]
  320. public virtual bool CheckFileExists {
  321. get {
  322. return checkFileExists;
  323. }
  324. set {
  325. checkFileExists = value;
  326. }
  327. }
  328. [DefaultValue(true)]
  329. public bool CheckPathExists {
  330. get {
  331. return checkPathExists;
  332. }
  333. set {
  334. checkPathExists = value;
  335. }
  336. }
  337. [DefaultValue("")]
  338. public string DefaultExt {
  339. get {
  340. return defaultExt;
  341. }
  342. set {
  343. defaultExt = value;
  344. // if there is a dot remove it and everything before it
  345. if (defaultExt.LastIndexOf ('.') != - 1) {
  346. string[] split = defaultExt.Split (new char [] { '.' });
  347. defaultExt = split [split.Length - 1];
  348. }
  349. }
  350. }
  351. // in MS.NET it doesn't make a difference if
  352. // DerefenceLinks is true or false
  353. // if the selected file is a link FileDialog
  354. // always returns the link
  355. [DefaultValue(true)]
  356. public bool DereferenceLinks {
  357. get {
  358. return dereferenceLinks;
  359. }
  360. set {
  361. dereferenceLinks = value;
  362. }
  363. }
  364. [DefaultValue("")]
  365. public string FileName {
  366. get {
  367. return fileName;
  368. }
  369. set {
  370. if (value != null) {
  371. if (SetFileName (value)) {
  372. fileName = value;
  373. if (fileNames == null) {
  374. fileNames = new string [1];
  375. fileNames [0] = value;
  376. }
  377. }
  378. } else {
  379. fileName = String.Empty;
  380. fileNames = new string [0];
  381. // this does not match ms exactly,
  382. // but there is no other way to clear that %#&?§ combobox
  383. fileNameComboBox.Text = " ";
  384. }
  385. }
  386. }
  387. [Browsable(false)]
  388. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  389. public string[] FileNames {
  390. get {
  391. if (fileNames == null || fileNames.Length == 0) {
  392. string[] null_nada_nothing_filenames = new string [0];
  393. return null_nada_nothing_filenames;
  394. }
  395. string[] new_filenames = new string [fileNames.Length];
  396. fileNames.CopyTo (new_filenames, 0);
  397. return new_filenames;
  398. }
  399. }
  400. [DefaultValue("")]
  401. [Localizable(true)]
  402. public string Filter {
  403. get {
  404. return filter;
  405. }
  406. set {
  407. if (value == null) {
  408. filter = "";
  409. if (fileFilter != null)
  410. fileFilter.FilterArrayList.Clear ();
  411. } else {
  412. if (FileFilter.CheckFilter (value)) {
  413. filter = value;
  414. fileFilter = new FileFilter (filter);
  415. } else
  416. throw new ArgumentException ();
  417. }
  418. UpdateFilters ();
  419. }
  420. }
  421. [DefaultValue(1)]
  422. public int FilterIndex {
  423. get {
  424. return filterIndex;
  425. }
  426. set {
  427. filterIndex = value;
  428. SelectFilter ();
  429. }
  430. }
  431. [DefaultValue("")]
  432. public string InitialDirectory {
  433. get {
  434. return initialDirectory;
  435. }
  436. set {
  437. if (Directory.Exists (value)) {
  438. initialDirectory = value;
  439. mwfFileView.ChangeDirectory (null, initialDirectory);
  440. }
  441. }
  442. }
  443. [DefaultValue(false)]
  444. public bool RestoreDirectory {
  445. get {
  446. return restoreDirectory;
  447. }
  448. set {
  449. restoreDirectory = value;
  450. }
  451. }
  452. [DefaultValue(false)]
  453. public bool ShowHelp {
  454. get {
  455. return showHelp;
  456. }
  457. set {
  458. showHelp = value;
  459. ResizeAndRelocateForHelpOrReadOnly ();
  460. }
  461. }
  462. [DefaultValue("")]
  463. [Localizable(true)]
  464. public string Title {
  465. get {
  466. return title;
  467. }
  468. set {
  469. title = value;
  470. form.Text = title;
  471. }
  472. }
  473. // this one is a hard one ;)
  474. // Win32 filename:
  475. // - up to MAX_PATH characters (windef.h) = 260
  476. // - no trailing dots or spaces
  477. // - case preserving
  478. // - etc...
  479. // NTFS/Posix filename:
  480. // - up to 32,768 Unicode characters
  481. // - trailing periods or spaces
  482. // - case sensitive
  483. // - etc...
  484. [DefaultValue(true)]
  485. public bool ValidateNames {
  486. get {
  487. return validateNames;
  488. }
  489. set {
  490. validateNames = value;
  491. }
  492. }
  493. public override void Reset ()
  494. {
  495. addExtension = true;
  496. checkFileExists = false;
  497. checkPathExists = true;
  498. defaultExt = String.Empty;
  499. dereferenceLinks = true;
  500. FileName = String.Empty;
  501. Filter = String.Empty;
  502. filterIndex = 1;
  503. initialDirectory = String.Empty;
  504. restoreDirectory = false;
  505. ShowHelp = false;
  506. Title = String.Empty;
  507. validateNames = true;
  508. UpdateFilters ();
  509. }
  510. public override string ToString ()
  511. {
  512. return String.Format("{0}: Title: {1}, FileName: {2}", base.ToString (), Title, fileName);
  513. }
  514. public event CancelEventHandler FileOk {
  515. add { Events.AddHandler (EventFileOk, value); }
  516. remove { Events.RemoveHandler (EventFileOk, value); }
  517. }
  518. protected virtual IntPtr Instance {
  519. get {
  520. if (form == null)
  521. return IntPtr.Zero;
  522. return form.Handle;
  523. }
  524. }
  525. // This is just for internal use with MSs version, so it doesn't need to be implemented
  526. // as it can't really be accessed anyways
  527. protected int Options {
  528. get { return -1; }
  529. }
  530. [MonoTODO]
  531. protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
  532. {
  533. throw new NotImplementedException ();
  534. }
  535. protected void OnFileOk (CancelEventArgs e)
  536. {
  537. WriteConfigValues (e);
  538. CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
  539. if (fo != null)
  540. fo (this, e);
  541. }
  542. protected override bool RunDialog (IntPtr hWndOwner)
  543. {
  544. ReadConfigValues ();
  545. form.Refresh ();
  546. mwfFileView.ChangeDirectory (null, lastFolder);
  547. fileNameComboBox.Select ();
  548. return true;
  549. }
  550. internal virtual bool ShowReadOnly {
  551. set {
  552. showReadOnly = value;
  553. ResizeAndRelocateForHelpOrReadOnly ();
  554. }
  555. get {
  556. return showReadOnly;
  557. }
  558. }
  559. internal virtual bool ReadOnlyChecked {
  560. set {
  561. readOnlyChecked = value;
  562. readonlyCheckBox.Checked = value;
  563. }
  564. get {
  565. return readOnlyChecked;
  566. }
  567. }
  568. internal bool BMultiSelect {
  569. set {
  570. multiSelect = value;
  571. mwfFileView.MultiSelect = value;
  572. }
  573. get {
  574. return multiSelect;
  575. }
  576. }
  577. internal string OpenSaveButtonText {
  578. set {
  579. openSaveButton.Text = value;
  580. }
  581. }
  582. internal string SearchSaveLabel {
  583. set {
  584. searchSaveLabel.Text = value;
  585. }
  586. }
  587. private void SelectFilter ()
  588. {
  589. if (mwfFileView.FilterArrayList == null || FilterIndex > mwfFileView.FilterArrayList.Count)
  590. return;
  591. do_not_call_OnSelectedIndexChangedFileTypeComboBox = true;
  592. fileTypeComboBox.BeginUpdate ();
  593. fileTypeComboBox.SelectedIndex = FilterIndex - 1;
  594. fileTypeComboBox.EndUpdate ();
  595. mwfFileView.FilterIndex = FilterIndex;
  596. }
  597. private bool SetFileName (string fname)
  598. {
  599. bool rooted = Path.IsPathRooted (fname);
  600. if (!rooted) {
  601. string dir = mwfFileView.CurrentRealFolder ;
  602. if (dir == null) {
  603. dir = Environment.CurrentDirectory;
  604. }
  605. if (File.Exists (Path.Combine (dir, fname))) {
  606. fileNameComboBox.Text = fname;
  607. mwfFileView.SetSelectedIndexTo (fname);
  608. return true;
  609. }
  610. } else {
  611. if (File.Exists (fname)) {
  612. fileNameComboBox.Text = Path.GetFileName (fname);
  613. mwfFileView.ChangeDirectory (null, Path.GetDirectoryName (fname));
  614. mwfFileView.SetSelectedIndexTo (fname);
  615. return true;
  616. }
  617. }
  618. return false;
  619. }
  620. void OnClickOpenSaveButton (object sender, EventArgs e)
  621. {
  622. if (fileDialogType == FileDialogType.OpenFileDialog) {
  623. ListView.SelectedListViewItemCollection sl = mwfFileView.SelectedItems;
  624. if (sl.Count > 0 && sl [0] != null) {
  625. if (sl.Count == 1) {
  626. FileViewListViewItem item = sl [0] as FileViewListViewItem;
  627. FSEntry fsEntry = item.FSEntry;
  628. if (fsEntry.Attributes == FileAttributes.Directory) {
  629. mwfFileView.ChangeDirectory (null, fsEntry.FullName);
  630. return;
  631. }
  632. } else {
  633. foreach (FileViewListViewItem item in sl) {
  634. FSEntry fsEntry = item.FSEntry;
  635. if (fsEntry.Attributes == FileAttributes.Directory) {
  636. mwfFileView.ChangeDirectory (null, fsEntry.FullName);
  637. return;
  638. }
  639. }
  640. }
  641. }
  642. }
  643. string internalfullfilename = String.Empty;
  644. if (!multiSelect) {
  645. string fileFromComboBox = fileNameComboBox.Text.Trim ();
  646. if (fileFromComboBox.Length > 0) {
  647. if (!Path.IsPathRooted (fileFromComboBox)) {
  648. // on unix currentRealFolder for "Recently used files" is null,
  649. // because recently used files don't get saved as links in a directory
  650. // recently used files get saved in a xml file
  651. if (mwfFileView.CurrentRealFolder != null)
  652. fileFromComboBox = Path.Combine (mwfFileView.CurrentRealFolder, fileFromComboBox);
  653. else
  654. if (mwfFileView.CurrentFSEntry != null) {
  655. fileFromComboBox = mwfFileView.CurrentFSEntry.FullName;
  656. }
  657. }
  658. FileInfo fileInfo = new FileInfo (fileFromComboBox);
  659. if (fileInfo.Exists || fileDialogType == FileDialogType.SaveFileDialog) {
  660. internalfullfilename = fileFromComboBox;
  661. } else {
  662. DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
  663. if (dirInfo.Exists) {
  664. mwfFileView.ChangeDirectory (null, dirInfo.FullName);
  665. fileNameComboBox.Text = " ";
  666. return;
  667. } else {
  668. internalfullfilename = fileFromComboBox;
  669. }
  670. }
  671. } else
  672. return;
  673. if (fileDialogType == FileDialogType.OpenFileDialog) {
  674. if (checkFileExists) {
  675. if (!File.Exists (internalfullfilename)) {
  676. string message = "\"" + internalfullfilename + "\" doesn't exist. Please verify that you have entered the correct file name.";
  677. MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  678. return;
  679. }
  680. }
  681. } else {
  682. if (overwritePrompt) {
  683. if (File.Exists (internalfullfilename)) {
  684. string message = "\"" + internalfullfilename + "\" exists. Overwrite ?";
  685. DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  686. if (dr == DialogResult.Cancel)
  687. return;
  688. }
  689. }
  690. if (createPrompt) {
  691. if (!File.Exists (internalfullfilename)) {
  692. string message = "\"" + internalfullfilename + "\" doesn't exist. Create ?";
  693. DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  694. if (dr == DialogResult.Cancel)
  695. return;
  696. }
  697. }
  698. }
  699. if (fileDialogType == FileDialogType.SaveFileDialog) {
  700. if (addExtension) {
  701. string extension_to_use = String.Empty;
  702. string filter_exentsion = String.Empty;
  703. if (fileFilter != null) {
  704. FilterStruct filterstruct = (FilterStruct)fileFilter.FilterArrayList [filterIndex - 1];
  705. for (int i = 0; i < filterstruct.filters.Count; i++) {
  706. string extension = filterstruct.filters [i];
  707. if (extension.StartsWith ("*"))
  708. extension = extension.Remove (0, 1);
  709. if (extension.IndexOf ('*') != -1)
  710. continue;
  711. filter_exentsion = extension;
  712. break;
  713. }
  714. }
  715. if (filter_exentsion != String.Empty)
  716. extension_to_use = filter_exentsion;
  717. else
  718. if (defaultExt != String.Empty)
  719. extension_to_use = "." + defaultExt;
  720. internalfullfilename += extension_to_use;
  721. }
  722. }
  723. fileNames = new string [1];
  724. fileNames [0] = internalfullfilename;
  725. fileName = internalfullfilename;
  726. mwfFileView.WriteRecentlyUsed (internalfullfilename);
  727. } else // multiSelect = true
  728. if (fileDialogType != FileDialogType.SaveFileDialog) {
  729. if (mwfFileView.SelectedItems.Count > 0) {
  730. // first remove all selected directories
  731. ArrayList al = new ArrayList ();
  732. foreach (FileViewListViewItem lvi in mwfFileView.SelectedItems) {
  733. FSEntry fsEntry = lvi.FSEntry;
  734. if (fsEntry.Attributes != FileAttributes.Directory) {
  735. al.Add (fsEntry);
  736. }
  737. }
  738. fileName = ((FSEntry)al [0]).FullName;
  739. fileNames = new string [al.Count];
  740. for (int i = 0; i < al.Count; i++) {
  741. fileNames [i] = ((FSEntry)al [i]).FullName;
  742. }
  743. }
  744. }
  745. if (checkPathExists && mwfFileView.CurrentRealFolder != null) {
  746. if (!Directory.Exists (mwfFileView.CurrentRealFolder)) {
  747. string message = "\"" + mwfFileView.CurrentRealFolder + "\" doesn't exist. Please verify that you have entered the correct directory name.";
  748. MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  749. if (initialDirectory == String.Empty)
  750. mwfFileView.ChangeDirectory (null, lastFolder);
  751. else
  752. mwfFileView.ChangeDirectory (null, initialDirectory);
  753. return;
  754. }
  755. }
  756. if (restoreDirectory) {
  757. lastFolder = restoreDirectoryString;
  758. } else {
  759. lastFolder = mwfFileView.CurrentFolder;
  760. }
  761. if (fileNameComboBox.Items.Count > 0) {
  762. if (fileNameComboBox.Items.IndexOf (fileName) == -1) {
  763. fileNameComboBox.Items.Insert (0, fileName);
  764. }
  765. } else
  766. fileNameComboBox.Items.Add (fileName);
  767. if (fileNameComboBox.Items.Count == 11)
  768. fileNameComboBox.Items.RemoveAt (10);
  769. CancelEventArgs cancelEventArgs = new CancelEventArgs ();
  770. cancelEventArgs.Cancel = false;
  771. OnFileOk (cancelEventArgs);
  772. form.DialogResult = DialogResult.OK;
  773. }
  774. void OnClickCancelButton (object sender, EventArgs e)
  775. {
  776. if (restoreDirectory)
  777. mwfFileView.CurrentFolder = restoreDirectoryString;
  778. CancelEventArgs cancelEventArgs = new CancelEventArgs ();
  779. cancelEventArgs.Cancel = true;
  780. OnFileOk (cancelEventArgs);
  781. form.DialogResult = DialogResult.Cancel;
  782. }
  783. void OnClickHelpButton (object sender, EventArgs e)
  784. {
  785. OnHelpRequest (e);
  786. }
  787. void OnClickSmallButtonToolBar (object sender, ToolBarButtonClickEventArgs e)
  788. {
  789. if (e.Button == upToolBarButton) {
  790. mwfFileView.OneDirUp ();
  791. } else
  792. if (e.Button == backToolBarButton) {
  793. mwfFileView.PopDir ();
  794. } else
  795. if (e.Button == newdirToolBarButton) {
  796. mwfFileView.CreateNewFolder ();
  797. }
  798. }
  799. void OnSelectedIndexChangedFileTypeComboBox (object sender, EventArgs e)
  800. {
  801. if (do_not_call_OnSelectedIndexChangedFileTypeComboBox) {
  802. do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
  803. return;
  804. }
  805. filterIndex = fileTypeComboBox.SelectedIndex + 1;
  806. mwfFileView.FilterIndex = filterIndex;
  807. }
  808. void OnSelectedFileChangedFileView (object sender, EventArgs e)
  809. {
  810. fileNameComboBox.Text = mwfFileView.CurrentFSEntry.Name;
  811. }
  812. void OnSelectedFilesChangedFileView (object sender, EventArgs e)
  813. {
  814. fileNameComboBox.Text = mwfFileView.SelectedFilesString;
  815. }
  816. void OnForceDialogEndFileView (object sender, EventArgs e)
  817. {
  818. OnClickOpenSaveButton (this, EventArgs.Empty);
  819. }
  820. void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
  821. {
  822. mwfFileView.ChangeDirectory (sender, dirComboBox.CurrentFolder);
  823. }
  824. void OnDirectoryChangedPopupButtonPanel (object sender, EventArgs e)
  825. {
  826. mwfFileView.ChangeDirectory (sender, popupButtonPanel.CurrentFolder);
  827. }
  828. void OnCheckCheckChanged (object sender, EventArgs e)
  829. {
  830. ReadOnlyChecked = readonlyCheckBox.Checked;
  831. }
  832. private void UpdateFilters ()
  833. {
  834. if (fileFilter == null)
  835. fileFilter = new FileFilter ();
  836. ArrayList filters = fileFilter.FilterArrayList;
  837. fileTypeComboBox.BeginUpdate ();
  838. fileTypeComboBox.Items.Clear ();
  839. foreach (FilterStruct fs in filters) {
  840. fileTypeComboBox.Items.Add (fs.filterName);
  841. }
  842. if (filters.Count > 0 && FilterIndex <= filters.Count)
  843. fileTypeComboBox.SelectedIndex = FilterIndex - 1;
  844. fileTypeComboBox.EndUpdate ();
  845. mwfFileView.FilterArrayList = filters;
  846. mwfFileView.FilterIndex = FilterIndex;
  847. }
  848. private void ResizeAndRelocateForHelpOrReadOnly ()
  849. {
  850. form.SuspendLayout ();
  851. if (ShowHelp || ShowReadOnly) {
  852. mwfFileView.Size = new Size (449, 250);
  853. fileNameLabel.Location = new Point (102, 298);
  854. fileNameComboBox.Location = new Point (195, 298);
  855. fileTypeLabel.Location = new Point (102, 324);
  856. fileTypeComboBox.Location = new Point (195, 324);
  857. openSaveButton.Location = new Point (475, 298);
  858. cancelButton.Location = new Point (475, 324);
  859. } else {
  860. mwfFileView.Size = new Size (449, 282);
  861. fileNameLabel.Location = new Point (102, 330);
  862. fileNameComboBox.Location = new Point (195, 330);
  863. fileTypeLabel.Location = new Point (102, 356);
  864. fileTypeComboBox.Location = new Point (195, 356);
  865. openSaveButton.Location = new Point (475, 330);
  866. cancelButton.Location = new Point (475, 356);
  867. }
  868. if (ShowHelp)
  869. form.Controls.Add (helpButton);
  870. else
  871. form.Controls.Remove (helpButton);
  872. if (ShowReadOnly)
  873. form.Controls.Add (readonlyCheckBox);
  874. else
  875. form.Controls.Remove (readonlyCheckBox);
  876. form.ResumeLayout ();
  877. }
  878. private void WriteConfigValues (CancelEventArgs ce)
  879. {
  880. MWFConfig.SetValue (filedialog_string, width_string, form.Width);
  881. MWFConfig.SetValue (filedialog_string, height_string, form.Height);
  882. MWFConfig.SetValue (filedialog_string, x_string, form.Location.X);
  883. MWFConfig.SetValue (filedialog_string, y_string, form.Location.Y);
  884. if (!ce.Cancel) {
  885. MWFConfig.SetValue (filedialog_string, lastfolder_string, lastFolder);
  886. string[] fileNameCBItems = new string [fileNameComboBox.Items.Count];
  887. fileNameComboBox.Items.CopyTo (fileNameCBItems, 0);
  888. MWFConfig.SetValue (filedialog_string, filenames_string, fileNameCBItems);
  889. }
  890. }
  891. private void ReadConfigValues ()
  892. {
  893. lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
  894. if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
  895. if (!Directory.Exists (lastFolder)) {
  896. lastFolder = MWFVFS.DesktopPrefix;
  897. }
  898. }
  899. if (initialDirectory != String.Empty)
  900. lastFolder = initialDirectory;
  901. else
  902. if (lastFolder == null || lastFolder == String.Empty)
  903. lastFolder = Environment.CurrentDirectory;
  904. if (RestoreDirectory)
  905. restoreDirectoryString = lastFolder;
  906. }
  907. }
  908. #endregion
  909. #region PopupButtonPanel
  910. internal class PopupButtonPanel : Control, IUpdateFolder
  911. {
  912. #region PopupButton
  913. internal class PopupButton : Control
  914. {
  915. internal enum PopupButtonState
  916. { Normal, Down, Up}
  917. private Image image = null;
  918. private PopupButtonState popupButtonState = PopupButtonState.Normal;
  919. private StringFormat text_format = new StringFormat();
  920. private Rectangle text_rect = Rectangle.Empty;
  921. public PopupButton ()
  922. {
  923. text_format.Alignment = StringAlignment.Center;
  924. text_format.LineAlignment = StringAlignment.Near;
  925. SetStyle (ControlStyles.DoubleBuffer, true);
  926. SetStyle (ControlStyles.AllPaintingInWmPaint, true);
  927. SetStyle (ControlStyles.UserPaint, true);
  928. SetStyle (ControlStyles.Selectable, false);
  929. }
  930. public Image Image {
  931. set {
  932. image = value;
  933. Refresh ();
  934. }
  935. get {
  936. return image;
  937. }
  938. }
  939. public PopupButtonState ButtonState {
  940. set {
  941. popupButtonState = value;
  942. Refresh ();
  943. }
  944. get {
  945. return popupButtonState;
  946. }
  947. }
  948. protected override void OnPaint (PaintEventArgs pe)
  949. {
  950. Draw (pe);
  951. base.OnPaint (pe);
  952. }
  953. private void Draw (PaintEventArgs pe)
  954. {
  955. Graphics gr = pe.Graphics;
  956. gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  957. // draw image
  958. if (image != null) {
  959. int i_x = (ClientSize.Width - image.Width) / 2;
  960. int i_y = 4;
  961. gr.DrawImage (image, i_x, i_y);
  962. }
  963. if (Text != String.Empty) {
  964. if (text_rect == Rectangle.Empty)
  965. text_rect = new Rectangle (0, Height - 30, Width, Height - 30);
  966. gr.DrawString (Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor), text_rect, text_format);
  967. }
  968. switch (popupButtonState) {
  969. case PopupButtonState.Up:
  970. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, ClientSize.Width - 1, 0);
  971. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, 0, ClientSize.Height - 1);
  972. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
  973. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
  974. break;
  975. case PopupButtonState.Down:
  976. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, ClientSize.Width - 1, 0);
  977. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, 0, ClientSize.Height - 1);
  978. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
  979. gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
  980. break;
  981. }
  982. }
  983. protected override void OnMouseEnter (EventArgs e)
  984. {
  985. if (popupButtonState != PopupButtonState.Down)
  986. popupButtonState = PopupButtonState.Up;
  987. PopupButtonPanel panel = Parent as PopupButtonPanel;
  988. if (panel.focusButton != null && panel.focusButton.ButtonState == PopupButtonState.Up) {
  989. panel.focusButton.ButtonState = PopupButtonState.Normal;
  990. panel.focusButton = null;
  991. }
  992. Refresh ();
  993. base.OnMouseEnter (e);
  994. }
  995. protected override void OnMouseLeave (EventArgs e)
  996. {
  997. if (popupButtonState == PopupButtonState.Up)
  998. popupButtonState = PopupButtonState.Normal;
  999. Refresh ();
  1000. base.OnMouseLeave (e);
  1001. }
  1002. protected override void OnClick (EventArgs e)
  1003. {
  1004. popupButtonState = PopupButtonState.Down;
  1005. Refresh ();
  1006. base.OnClick (e);
  1007. }
  1008. }
  1009. #endregion
  1010. private EventHandler on_directory_changed;
  1011. private PopupButton recentlyusedButton;
  1012. private PopupButton desktopButton;
  1013. private PopupButton personalButton;
  1014. private PopupButton mycomputerButton;
  1015. private PopupButton networkButton;
  1016. private PopupButton lastPopupButton = null;
  1017. private PopupButton focusButton = null;
  1018. private string currentPath;
  1019. private int currentFocusIndex;
  1020. public PopupButtonPanel ()
  1021. {
  1022. SuspendLayout ();
  1023. //BackColor = Color.FromArgb (128, 128, 128);
  1024. Size = new Size (85, 336);
  1025. recentlyusedButton = new PopupButton ();
  1026. desktopButton = new PopupButton ();
  1027. personalButton = new PopupButton ();
  1028. mycomputerButton = new PopupButton ();
  1029. networkButton = new PopupButton ();
  1030. recentlyusedButton.Size = new Size (81, 64);
  1031. recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 32);
  1032. recentlyusedButton.BackColor = BackColor;
  1033. recentlyusedButton.ForeColor = Color.Black;
  1034. recentlyusedButton.Location = new Point (2, 2);
  1035. recentlyusedButton.Text = "Recently\nused";
  1036. recentlyusedButton.Click += new EventHandler (OnClickButton);
  1037. desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 32);
  1038. desktopButton.BackColor = BackColor;
  1039. desktopButton.ForeColor = Color.Black;
  1040. desktopButton.Size = new Size (81, 64);
  1041. desktopButton.Location = new Point (2, 66);
  1042. desktopButton.Text = "Desktop";
  1043. desktopButton.Click += new EventHandler (OnClickButton);
  1044. personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 32);
  1045. personalButton.BackColor = BackColor;
  1046. personalButton.ForeColor = Color.Black;
  1047. personalButton.Size = new Size (81, 64);
  1048. personalButton.Location = new Point (2, 130);
  1049. personalButton.Text = "Personal";
  1050. personalButton.Click += new EventHandler (OnClickButton);
  1051. mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 32);
  1052. mycomputerButton.BackColor = BackColor;
  1053. mycomputerButton.ForeColor = Color.Black;
  1054. mycomputerButton.Size = new Size (81, 64);
  1055. mycomputerButton.Location = new Point (2, 194);
  1056. mycomputerButton.Text = "My Computer";
  1057. mycomputerButton.Click += new EventHandler (OnClickButton);
  1058. networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 32);
  1059. networkButton.BackColor = BackColor;
  1060. networkButton.ForeColor = Color.Black;
  1061. networkButton.Size = new Size (81, 64);
  1062. networkButton.Location = new Point (2, 258);
  1063. networkButton.Text = "My Network";
  1064. networkButton.Click += new EventHandler (OnClickButton);
  1065. Controls.Add (recentlyusedButton);
  1066. Controls.Add (desktopButton);
  1067. Controls.Add (personalButton);
  1068. Controls.Add (mycomputerButton);
  1069. Controls.Add (networkButton);
  1070. ResumeLayout (false);
  1071. KeyDown += new KeyEventHandler (Key_Down);
  1072. SetStyle (ControlStyles.StandardClick, false);
  1073. }
  1074. void OnClickButton (object sender, EventArgs e)
  1075. {
  1076. if (lastPopupButton != null && lastPopupButton != sender as PopupButton)
  1077. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1078. lastPopupButton = sender as PopupButton;
  1079. if (sender == recentlyusedButton) {
  1080. currentPath = MWFVFS.RecentlyUsedPrefix;
  1081. } else
  1082. if (sender == desktopButton) {
  1083. currentPath = MWFVFS.DesktopPrefix;
  1084. } else
  1085. if (sender == personalButton) {
  1086. currentPath = MWFVFS.PersonalPrefix;
  1087. } else
  1088. if (sender == mycomputerButton) {
  1089. currentPath = MWFVFS.MyComputerPrefix;
  1090. } else
  1091. if (sender == networkButton) {
  1092. currentPath = MWFVFS.MyNetworkPrefix;
  1093. }
  1094. if (on_directory_changed != null)
  1095. on_directory_changed (this, EventArgs.Empty);
  1096. }
  1097. public string CurrentFolder {
  1098. set {
  1099. string currentPath = value;
  1100. if (currentPath == MWFVFS.RecentlyUsedPrefix) {
  1101. if (lastPopupButton != recentlyusedButton) {
  1102. if (lastPopupButton != null)
  1103. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1104. recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Down;
  1105. lastPopupButton = recentlyusedButton;
  1106. }
  1107. } else
  1108. if (currentPath == MWFVFS.DesktopPrefix) {
  1109. if (lastPopupButton != desktopButton) {
  1110. if (lastPopupButton != null)
  1111. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1112. desktopButton.ButtonState = PopupButton.PopupButtonState.Down;
  1113. lastPopupButton = desktopButton;
  1114. }
  1115. } else
  1116. if (currentPath == MWFVFS.PersonalPrefix) {
  1117. if (lastPopupButton != personalButton) {
  1118. if (lastPopupButton != null)
  1119. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1120. personalButton.ButtonState = PopupButton.PopupButtonState.Down;
  1121. lastPopupButton = personalButton;
  1122. }
  1123. } else
  1124. if (currentPath == MWFVFS.MyComputerPrefix) {
  1125. if (lastPopupButton != mycomputerButton) {
  1126. if (lastPopupButton != null)
  1127. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1128. mycomputerButton.ButtonState = PopupButton.PopupButtonState.Down;
  1129. lastPopupButton = mycomputerButton;
  1130. }
  1131. } else
  1132. if (currentPath == MWFVFS.MyNetworkPrefix) {
  1133. if (lastPopupButton != networkButton) {
  1134. if (lastPopupButton != null)
  1135. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1136. networkButton.ButtonState = PopupButton.PopupButtonState.Down;
  1137. lastPopupButton = networkButton;
  1138. }
  1139. } else {
  1140. if (lastPopupButton != null) {
  1141. lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1142. lastPopupButton = null;
  1143. }
  1144. }
  1145. }
  1146. get {
  1147. return currentPath;
  1148. }
  1149. }
  1150. protected override void OnPaint (PaintEventArgs e)
  1151. {
  1152. ControlPaint.DrawBorder3D (e.Graphics, ClientRectangle, Border3DStyle.Sunken);
  1153. base.OnPaint (e);
  1154. }
  1155. protected override void OnGotFocus (EventArgs e)
  1156. {
  1157. if (lastPopupButton != recentlyusedButton) {
  1158. recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Up;
  1159. focusButton = recentlyusedButton;
  1160. }
  1161. currentFocusIndex = 0;
  1162. base.OnGotFocus (e);
  1163. }
  1164. protected override void OnLostFocus (EventArgs e)
  1165. {
  1166. if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
  1167. focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1168. base.OnLostFocus (e);
  1169. }
  1170. protected override bool IsInputKey (Keys key)
  1171. {
  1172. switch (key) {
  1173. case Keys.Up:
  1174. case Keys.Down:
  1175. case Keys.Right:
  1176. case Keys.Left:
  1177. case Keys.Enter:
  1178. return true;
  1179. }
  1180. return base.IsInputKey (key);
  1181. }
  1182. private void Key_Down (object sender, KeyEventArgs e)
  1183. {
  1184. bool update_focus = false;
  1185. if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) {
  1186. currentFocusIndex --;
  1187. if (currentFocusIndex < 0)
  1188. currentFocusIndex = Controls.Count - 1;
  1189. update_focus = true;
  1190. } else
  1191. if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
  1192. currentFocusIndex++;
  1193. if (currentFocusIndex == Controls.Count)
  1194. currentFocusIndex = 0;
  1195. update_focus = true;
  1196. } else
  1197. if (e.KeyCode == Keys.Enter) {
  1198. focusButton.ButtonState = PopupButton.PopupButtonState.Down;
  1199. OnClickButton (focusButton, EventArgs.Empty);
  1200. }
  1201. if (update_focus) {
  1202. PopupButton newfocusButton = Controls [currentFocusIndex] as PopupButton;
  1203. if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
  1204. focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
  1205. if (newfocusButton.ButtonState != PopupButton.PopupButtonState.Down)
  1206. newfocusButton.ButtonState = PopupButton.PopupButtonState.Up;
  1207. focusButton = newfocusButton;
  1208. }
  1209. e.Handled = true;
  1210. }
  1211. public event EventHandler DirectoryChanged {
  1212. add { on_directory_changed += value; }
  1213. remove { on_directory_changed -= value; }
  1214. }
  1215. }
  1216. #endregion
  1217. #region DirComboBox
  1218. internal class DirComboBox : ComboBox, IUpdateFolder
  1219. {
  1220. #region DirComboBoxItem
  1221. internal class DirComboBoxItem
  1222. {
  1223. private int imageIndex;
  1224. private string name;
  1225. private string path;
  1226. private int xPos;
  1227. private ImageList imageList;
  1228. public DirComboBoxItem (ImageList imageList, int imageIndex, string name, string path, int xPos)
  1229. {
  1230. this.imageList = imageList;
  1231. this.imageIndex = imageIndex;
  1232. this.name = name;
  1233. this.path = path;
  1234. this.xPos = xPos;
  1235. }
  1236. public int ImageIndex {
  1237. get {
  1238. return imageIndex;
  1239. }
  1240. }
  1241. public string Name {
  1242. get {
  1243. return name;
  1244. }
  1245. }
  1246. public string Path {
  1247. get {
  1248. return path;
  1249. }
  1250. }
  1251. public int XPos {
  1252. get {
  1253. return xPos;
  1254. }
  1255. }
  1256. public ImageList ImageList {
  1257. set {
  1258. imageList = value;
  1259. }
  1260. get {
  1261. return imageList;
  1262. }
  1263. }
  1264. }
  1265. #endregion
  1266. private ImageList imageList = new ImageList();
  1267. private string currentPath;
  1268. private EventHandler on_directory_changed;
  1269. private Stack folderStack = new Stack();
  1270. private static readonly int indent = 6;
  1271. private DirComboBoxItem recentlyUsedDirComboboxItem;
  1272. private DirComboBoxItem desktopDirComboboxItem;
  1273. private DirComboBoxItem personalDirComboboxItem;
  1274. private DirComboBoxItem myComputerDirComboboxItem;
  1275. private DirComboBoxItem networkDirComboboxItem;
  1276. private ArrayList myComputerItems = new ArrayList ();
  1277. private DirComboBoxItem mainParentDirComboBoxItem = null;
  1278. private DirComboBoxItem real_parent = null;
  1279. private MWFVFS vfs;
  1280. public DirComboBox (MWFVFS vfs)
  1281. {
  1282. SuspendLayout ();
  1283. DrawMode = DrawMode.OwnerDrawFixed;
  1284. imageList.ColorDepth = ColorDepth.Depth32Bit;
  1285. imageList.ImageSize = new Size (16, 16);
  1286. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
  1287. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
  1288. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
  1289. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
  1290. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
  1291. imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
  1292. imageList.TransparentColor = Color.Transparent;
  1293. recentlyUsedDirComboboxItem = new DirComboBoxItem (imageList, 0, "Recently used", MWFVFS.RecentlyUsedPrefix, 0);
  1294. desktopDirComboboxItem = new DirComboBoxItem (imageList, 1, "Desktop", MWFVFS.DesktopPrefix, 0);
  1295. personalDirComboboxItem = new DirComboBoxItem (imageList, 2, "Personal folder", MWFVFS.PersonalPrefix, indent);
  1296. myComputerDirComboboxItem = new DirComboBoxItem (imageList, 3, "My Computer", MWFVFS.MyComputerPrefix, indent);
  1297. networkDirComboboxItem = new DirComboBoxItem (imageList, 4, "My Network", MWFVFS.MyNetworkPrefix, indent);
  1298. ArrayList al = vfs.GetMyComputerContent ();
  1299. foreach (FSEntry fsEntry in al) {
  1300. myComputerItems.Add (new DirComboBoxItem (MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName, indent * 2));
  1301. }
  1302. mainParentDirComboBoxItem = myComputerDirComboboxItem;
  1303. ResumeLayout (false);
  1304. }
  1305. public string CurrentFolder {
  1306. set {
  1307. currentPath = value;
  1308. CreateComboList ();
  1309. }
  1310. get {
  1311. return currentPath;
  1312. }
  1313. }
  1314. private void CreateComboList ()
  1315. {
  1316. real_parent = null;
  1317. DirComboBoxItem selection = null;
  1318. if (currentPath == MWFVFS.RecentlyUsedPrefix) {
  1319. mainParentDirComboBoxItem = recentlyUsedDirComboboxItem;
  1320. selection = recentlyUsedDirComboboxItem;
  1321. } else
  1322. if (currentPath == MWFVFS.DesktopPrefix) {
  1323. selection = desktopDirComboboxItem;
  1324. mainParentDirComboBoxItem = desktopDirComboboxItem;
  1325. } else
  1326. if (currentPath == MWFVFS.PersonalPrefix) {
  1327. selection = personalDirComboboxItem;
  1328. mainParentDirComboBoxItem = personalDirComboboxItem;
  1329. } else
  1330. if (currentPath == MWFVFS.MyComputerPrefix) {
  1331. selection = myComputerDirComboboxItem;
  1332. mainParentDirComboBoxItem = myComputerDirComboboxItem;
  1333. } else
  1334. if (currentPath == MWFVFS.MyNetworkPrefix) {
  1335. selection = networkDirComboboxItem;
  1336. mainParentDirComboBoxItem = networkDirComboboxItem;
  1337. } else {
  1338. foreach (DirComboBoxItem dci in myComputerItems) {
  1339. if (dci.Path == currentPath) {
  1340. mainParentDirComboBoxItem = selection = dci;
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. BeginUpdate ();
  1346. Items.Clear ();
  1347. Items.Add (recentlyUsedDirComboboxItem);
  1348. Items.Add (desktopDirComboboxItem);
  1349. Items.Add (personalDirComboboxItem);
  1350. Items.Add (myComputerDirComboboxItem);
  1351. Items.AddRange (myComputerItems);
  1352. Items.Add (networkDirComboboxItem);
  1353. if (selection == null) {
  1354. real_parent = CreateFolderStack ();
  1355. }
  1356. if (real_parent != null) {
  1357. int local_indent = 0;
  1358. if (real_parent == desktopDirComboboxItem)
  1359. local_indent = 1;
  1360. else
  1361. if (real_parent == personalDirComboboxItem || real_parent == networkDirComboboxItem)
  1362. local_indent = 2;
  1363. else
  1364. local_indent = 3;
  1365. selection = AppendToParent (local_indent, real_parent);
  1366. }
  1367. EndUpdate ();
  1368. if (selection != null)
  1369. SelectedItem = selection;
  1370. }
  1371. private DirComboBoxItem CreateFolderStack ()
  1372. {
  1373. folderStack.Clear ();
  1374. DirectoryInfo di = new DirectoryInfo (currentPath);
  1375. folderStack.Push (di);
  1376. while (di.Parent != null) {
  1377. di = di.Parent;
  1378. if (mainParentDirComboBoxItem != personalDirComboboxItem && di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
  1379. return desktopDirComboboxItem;
  1380. else
  1381. if (mainParentDirComboBoxItem == personalDirComboboxItem) {
  1382. if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
  1383. return personalDirComboboxItem;
  1384. } else
  1385. foreach (DirComboBoxItem dci in myComputerItems) {
  1386. if (dci.Path == di.FullName) {
  1387. return dci;
  1388. }
  1389. }
  1390. folderStack.Push (di);
  1391. }
  1392. return null;
  1393. }
  1394. private DirComboBoxItem AppendToParent (int nr_indents, DirComboBoxItem parentDirComboBoxItem)
  1395. {
  1396. DirComboBoxItem selection = null;
  1397. int index = Items.IndexOf (parentDirComboBoxItem) + 1;
  1398. int xPos = indent * nr_indents;
  1399. while (folderStack.Count != 0) {
  1400. DirectoryInfo dii = folderStack.Pop () as DirectoryInfo;
  1401. DirComboBoxItem dci = new DirComboBoxItem (imageList, 5, dii.Name, dii.FullName, xPos);
  1402. Items.Insert (index, dci);
  1403. index++;
  1404. selection = dci;
  1405. xPos += indent;
  1406. }
  1407. return selection;
  1408. }
  1409. protected override void OnDrawItem (DrawItemEventArgs e)
  1410. {
  1411. if (e.Index == -1)
  1412. return;
  1413. DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
  1414. Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
  1415. Graphics gr = Graphics.FromImage (bmp);
  1416. Color backColor = e.BackColor;
  1417. Color foreColor = e.ForeColor;
  1418. int xPos = dcbi.XPos;
  1419. if ((e.State & DrawItemState.ComboBoxEdit) != 0)
  1420. xPos = 0;
  1421. gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
  1422. new Rectangle (0, 0, bmp.Width, bmp.Height));
  1423. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
  1424. (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
  1425. foreColor = ThemeEngine.Current.ColorHighlightText;
  1426. int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
  1427. gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
  1428. new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
  1429. if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
  1430. ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
  1431. e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
  1432. }
  1433. }
  1434. gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
  1435. gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
  1436. e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
  1437. gr.Dispose ();
  1438. bmp.Dispose ();
  1439. }
  1440. protected override void OnSelectedIndexChanged (EventArgs e)
  1441. {
  1442. if (Items.Count > 0) {
  1443. DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
  1444. currentPath = dcbi.Path;
  1445. }
  1446. }
  1447. protected override void OnSelectionChangeCommitted (EventArgs e)
  1448. {
  1449. if (on_directory_changed != null)
  1450. on_directory_changed (this, EventArgs.Empty);
  1451. }
  1452. public event EventHandler DirectoryChanged {
  1453. add { on_directory_changed += value; }
  1454. remove { on_directory_changed -= value; }
  1455. }
  1456. }
  1457. #endregion
  1458. #region FilterStruct
  1459. internal struct FilterStruct
  1460. {
  1461. public string filterName;
  1462. public StringCollection filters;
  1463. public FilterStruct (string filterName, string filter)
  1464. {
  1465. this.filterName = filterName;
  1466. filters = new StringCollection ();
  1467. SplitFilters (filter);
  1468. }
  1469. private void SplitFilters (string filter)
  1470. {
  1471. string[] split = filter.Split (new char [] {';'});
  1472. filters.AddRange (split);
  1473. }
  1474. }
  1475. #endregion
  1476. #region FileFilter
  1477. internal class FileFilter
  1478. {
  1479. private ArrayList filterArrayList = new ArrayList();
  1480. private string filter;
  1481. public FileFilter ()
  1482. {}
  1483. public FileFilter (string filter) : base ()
  1484. {
  1485. this.filter = filter;
  1486. SplitFilter ();
  1487. }
  1488. public static bool CheckFilter (string val)
  1489. {
  1490. if (val.Length == 0)
  1491. return true;
  1492. string[] filters = val.Split (new char [] {'|'});
  1493. if ((filters.Length % 2) != 0)
  1494. return false;
  1495. return true;
  1496. }
  1497. public ArrayList FilterArrayList {
  1498. set {
  1499. filterArrayList = value;
  1500. }
  1501. get {
  1502. return filterArrayList;
  1503. }
  1504. }
  1505. public string Filter {
  1506. set {
  1507. filter = value;
  1508. SplitFilter ();
  1509. }
  1510. get {
  1511. return filter;
  1512. }
  1513. }
  1514. private void SplitFilter ()
  1515. {
  1516. filterArrayList.Clear ();
  1517. if (filter.Length == 0)
  1518. return;
  1519. string[] filters = filter.Split (new char [] {'|'});
  1520. for (int i = 0; i < filters.Length; i += 2) {
  1521. FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
  1522. filterArrayList.Add (filterStruct);
  1523. }
  1524. }
  1525. }
  1526. #endregion
  1527. #region MWFFileView
  1528. // MWFFileView
  1529. internal class MWFFileView : ListView
  1530. {
  1531. private ArrayList filterArrayList;
  1532. private bool showHiddenFiles = false;
  1533. private EventHandler on_selected_file_changed;
  1534. private EventHandler on_selected_files_changed;
  1535. private EventHandler on_directory_changed;
  1536. private EventHandler on_force_dialog_end;
  1537. private string selectedFilesString;
  1538. private int filterIndex = 1;
  1539. private ToolTip toolTip;
  1540. private int oldItemIndexForToolTip = -1;
  1541. private ContextMenu contextMenu;
  1542. private MenuItem menuItemView;
  1543. private MenuItem menuItemNew;
  1544. private MenuItem smallIconMenutItem;
  1545. private MenuItem tilesMenutItem;
  1546. private MenuItem largeIconMenutItem;
  1547. private MenuItem listMenutItem;
  1548. private MenuItem detailsMenutItem;
  1549. private MenuItem newFolderMenuItem;
  1550. private MenuItem showHiddenFilesMenuItem;
  1551. private int previousCheckedMenuItemIndex;
  1552. private ArrayList viewMenuItemClones = new ArrayList ();
  1553. private FSEntry currentFSEntry = null;
  1554. private string currentFolder;
  1555. private string currentRealFolder;
  1556. private FSEntry currentFolderFSEntry;
  1557. // store DirectoryInfo for a back button for example
  1558. private Stack directoryStack = new Stack();
  1559. // list of controls(components to enable or disable depending on current directoryStack.Count
  1560. private ArrayList dirStackControlsOrComponents = new ArrayList ();
  1561. private ToolBarButton folderUpToolBarButton;
  1562. private ArrayList registered_senders = new ArrayList ();
  1563. private bool should_push = true;
  1564. private MWFVFS vfs;
  1565. private View old_view;
  1566. private int old_menuitem_index;
  1567. private bool do_update_view = false;
  1568. private int platform = (int) Environment.OSVersion.Platform;
  1569. public MWFFileView (MWFVFS vfs)
  1570. {
  1571. this.vfs = vfs;
  1572. vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate (RealFileViewUpdate), this);
  1573. SuspendLayout ();
  1574. contextMenu = new ContextMenu ();
  1575. toolTip = new ToolTip ();
  1576. toolTip.InitialDelay = 300;
  1577. toolTip.ReshowDelay = 0;
  1578. // contextMenu
  1579. // View menu item
  1580. menuItemView = new MenuItem ("View");
  1581. smallIconMenutItem = new MenuItem ("Small Icon", new EventHandler (OnClickViewMenuSubItem));
  1582. smallIconMenutItem.RadioCheck = true;
  1583. menuItemView.MenuItems.Add (smallIconMenutItem);
  1584. tilesMenutItem = new MenuItem ("Tiles", new EventHandler (OnClickViewMenuSubItem));
  1585. tilesMenutItem.RadioCheck = true;
  1586. menuItemView.MenuItems.Add (tilesMenutItem);
  1587. largeIconMenutItem = new MenuItem ("Large Icon", new EventHandler (OnClickViewMenuSubItem));
  1588. largeIconMenutItem.RadioCheck = true;
  1589. menuItemView.MenuItems.Add (largeIconMenutItem);
  1590. listMenutItem = new MenuItem ("List", new EventHandler (OnClickViewMenuSubItem));
  1591. listMenutItem.RadioCheck = true;
  1592. listMenutItem.Checked = true;
  1593. menuItemView.MenuItems.Add (listMenutItem);
  1594. previousCheckedMenuItemIndex = listMenutItem.Index;
  1595. detailsMenutItem = new MenuItem ("Details", new EventHandler (OnClickViewMenuSubItem));
  1596. detailsMenutItem.RadioCheck = true;
  1597. menuItemView.MenuItems.Add (detailsMenutItem);
  1598. contextMenu.MenuItems.Add (menuItemView);
  1599. contextMenu.MenuItems.Add (new MenuItem ("-"));
  1600. // New menu item
  1601. menuItemNew = new MenuItem ("New");
  1602. newFolderMenuItem = new MenuItem ("New Folder", new EventHandler (OnClickNewFolderMenuItem));
  1603. menuItemNew.MenuItems.Add (newFolderMenuItem);
  1604. contextMenu.MenuItems.Add (menuItemNew);
  1605. contextMenu.MenuItems.Add (new MenuItem ("-"));
  1606. // Show hidden files menu item
  1607. showHiddenFilesMenuItem = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
  1608. showHiddenFilesMenuItem.Checked = showHiddenFiles;
  1609. contextMenu.MenuItems.Add (showHiddenFilesMenuItem);
  1610. LabelWrap = true;
  1611. SmallImageList = MimeIconEngine.SmallIcons;
  1612. LargeImageList = MimeIconEngine.LargeIcons;
  1613. View = old_view = View.List;
  1614. LabelEdit = true;
  1615. ContextMenu = contextMenu;
  1616. ResumeLayout (false);
  1617. KeyDown += new KeyEventHandler (MWF_KeyDown);
  1618. }
  1619. public string CurrentFolder {
  1620. get {
  1621. return currentFolder;
  1622. }
  1623. set {
  1624. currentFolder = value;
  1625. }
  1626. }
  1627. public string CurrentRealFolder {
  1628. get {
  1629. return currentRealFolder;
  1630. }
  1631. }
  1632. public FSEntry CurrentFSEntry {
  1633. get {
  1634. return currentFSEntry;
  1635. }
  1636. }
  1637. public MenuItem[] ViewMenuItems {
  1638. get {
  1639. MenuItem[] menuItemClones = new MenuItem [] {
  1640. smallIconMenutItem.CloneMenu (),
  1641. tilesMenutItem.CloneMenu (),
  1642. largeIconMenutItem.CloneMenu (),
  1643. listMenutItem.CloneMenu (),
  1644. detailsMenutItem.CloneMenu ()
  1645. };
  1646. viewMenuItemClones.Add (menuItemClones);
  1647. return menuItemClones;
  1648. }
  1649. }
  1650. public ArrayList FilterArrayList {
  1651. set {
  1652. filterArrayList = value;
  1653. }
  1654. get {
  1655. return filterArrayList;
  1656. }
  1657. }
  1658. public bool ShowHiddenFiles {
  1659. set {
  1660. showHiddenFiles = value;
  1661. }
  1662. get {
  1663. return showHiddenFiles;
  1664. }
  1665. }
  1666. public int FilterIndex {
  1667. set {
  1668. filterIndex = value;
  1669. if (Visible)
  1670. UpdateFileView ();
  1671. }
  1672. get {
  1673. return filterIndex;
  1674. }
  1675. }
  1676. public string SelectedFilesString {
  1677. set {
  1678. selectedFilesString = value;
  1679. }
  1680. get {
  1681. return selectedFilesString;
  1682. }
  1683. }
  1684. public void PushDir ()
  1685. {
  1686. if (currentFolder != null)
  1687. directoryStack.Push (currentFolder);
  1688. EnableOrDisableDirstackObjects ();
  1689. }
  1690. public void PopDir ()
  1691. {
  1692. if (directoryStack.Count == 0)
  1693. return;
  1694. string new_folder = directoryStack.Pop () as string;
  1695. EnableOrDisableDirstackObjects ();
  1696. should_push = false;
  1697. ChangeDirectory (null, new_folder);
  1698. }
  1699. public void RegisterSender (IUpdateFolder iud)
  1700. {
  1701. registered_senders.Add (iud);
  1702. }
  1703. public void CreateNewFolder ()
  1704. {
  1705. if (currentFolder == MWFVFS.MyComputerPrefix ||
  1706. currentFolder == MWFVFS.RecentlyUsedPrefix)
  1707. return;
  1708. FSEntry fsEntry = new FSEntry ();
  1709. fsEntry.Attributes = FileAttributes.Directory;
  1710. fsEntry.FileType = FSEntry.FSEntryType.Directory;
  1711. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
  1712. fsEntry.LastAccessTime = DateTime.Now;
  1713. // FIXME: when ListView.LabelEdit is available use it
  1714. // listViewItem.BeginEdit();
  1715. TextEntryDialog ted = new TextEntryDialog ();
  1716. ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
  1717. string folder = String.Empty;
  1718. if (currentFolderFSEntry.RealName != null)
  1719. folder = currentFolderFSEntry.RealName;
  1720. else
  1721. folder = currentFolder;
  1722. string tmp_filename = "New Folder";
  1723. if (Directory.Exists (Path.Combine (folder, tmp_filename))) {
  1724. int i = 1;
  1725. if ((platform == 4) || (platform == 128)) {
  1726. tmp_filename = tmp_filename + "-" + i;
  1727. } else {
  1728. tmp_filename = tmp_filename + " (" + i + ")";
  1729. }
  1730. while (Directory.Exists (Path.Combine (folder, tmp_filename))) {
  1731. i++;
  1732. if ((platform == 4) || (platform == 128)) {
  1733. tmp_filename = "New Folder" + "-" + i;
  1734. } else {
  1735. tmp_filename = "New Folder" + " (" + i + ")";
  1736. }
  1737. }
  1738. }
  1739. ted.FileName = tmp_filename;
  1740. if (ted.ShowDialog () == DialogResult.OK) {
  1741. string new_folder = Path.Combine (folder, ted.FileName);
  1742. if (vfs.CreateFolder (new_folder)) {
  1743. fsEntry.FullName = new_folder;
  1744. fsEntry.Name = ted.FileName;
  1745. FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
  1746. BeginUpdate ();
  1747. Items.Add (listViewItem);
  1748. EndUpdate ();
  1749. listViewItem.EnsureVisible ();
  1750. }
  1751. }
  1752. }
  1753. public void SetSelectedIndexTo (string fname)
  1754. {
  1755. foreach (FileViewListViewItem item in Items) {
  1756. if (item.Text == fname) {
  1757. BeginUpdate ();
  1758. SelectedItems.Clear ();
  1759. item.Selected = true;
  1760. EndUpdate ();
  1761. break;
  1762. }
  1763. }
  1764. }
  1765. public void OneDirUp ()
  1766. {
  1767. string parent_folder = vfs.GetParent ();
  1768. if (parent_folder != null)
  1769. ChangeDirectory (null, parent_folder);
  1770. }
  1771. public void ChangeDirectory (object sender, string folder)
  1772. {
  1773. if (folder == MWFVFS.DesktopPrefix || folder == MWFVFS.RecentlyUsedPrefix)
  1774. folderUpToolBarButton.Enabled = false;
  1775. else
  1776. folderUpToolBarButton.Enabled = true;
  1777. foreach (IUpdateFolder iuf in registered_senders) {
  1778. iuf.CurrentFolder = folder;
  1779. }
  1780. if (should_push)
  1781. PushDir ();
  1782. else
  1783. should_push = true;
  1784. currentFolderFSEntry = vfs.ChangeDirectory (folder);
  1785. currentFolder = folder;
  1786. if (currentFolder.IndexOf ("://") != -1)
  1787. currentRealFolder = currentFolderFSEntry.RealName;
  1788. else
  1789. currentRealFolder = currentFolder;
  1790. BeginUpdate ();
  1791. Items.Clear ();
  1792. SelectedItems.Clear ();
  1793. if (folder == MWFVFS.RecentlyUsedPrefix) {
  1794. old_view = View;
  1795. View = View.Details;
  1796. old_menuitem_index = previousCheckedMenuItemIndex;
  1797. UpdateMenuItems (detailsMenutItem);
  1798. do_update_view = true;
  1799. } else
  1800. if (View != old_view && do_update_view) {
  1801. UpdateMenuItems (menuItemView.MenuItems [old_menuitem_index]);
  1802. View = old_view;
  1803. do_update_view = false;
  1804. }
  1805. EndUpdate ();
  1806. try {
  1807. UpdateFileView ();
  1808. } catch (Exception e) {
  1809. if (should_push)
  1810. PopDir ();
  1811. MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1812. }
  1813. }
  1814. public void UpdateFileView ()
  1815. {
  1816. if (filterArrayList != null && filterArrayList.Count != 0) {
  1817. FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
  1818. vfs.GetFolderContent (fs.filters);
  1819. } else
  1820. vfs.GetFolderContent ();
  1821. }
  1822. public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
  1823. {
  1824. BeginUpdate ();
  1825. Items.Clear ();
  1826. SelectedItems.Clear ();
  1827. foreach (FSEntry directoryFSEntry in directoriesArrayList) {
  1828. if (!ShowHiddenFiles)
  1829. if (directoryFSEntry.Name.StartsWith (".") || directoryFSEntry.Attributes == FileAttributes.Hidden)
  1830. continue;
  1831. FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
  1832. Items.Add (listViewItem);
  1833. }
  1834. StringCollection collection = new StringCollection ();
  1835. foreach (FSEntry fsEntry in fileArrayList) {
  1836. // remove duplicates. that can happen when you read recently used files for example
  1837. if (collection.Contains (fsEntry.Name)) {
  1838. string fileName = fsEntry.Name;
  1839. if (collection.Contains (fileName)) {
  1840. int i = 1;
  1841. while (collection.Contains (fileName + "(" + i + ")")) {
  1842. i++;
  1843. }
  1844. fileName = fileName + "(" + i + ")";
  1845. }
  1846. fsEntry.Name = fileName;
  1847. }
  1848. collection.Add (fsEntry.Name);
  1849. DoOneFSEntry (fsEntry);
  1850. }
  1851. EndUpdate ();
  1852. }
  1853. public void AddControlToEnableDisableByDirStack (object control)
  1854. {
  1855. dirStackControlsOrComponents.Add (control);
  1856. }
  1857. public void SetFolderUpToolBarButton (ToolBarButton tb)
  1858. {
  1859. folderUpToolBarButton = tb;
  1860. }
  1861. public void WriteRecentlyUsed (string fullfilename)
  1862. {
  1863. vfs.WriteRecentlyUsedFiles (fullfilename);
  1864. }
  1865. private void EnableOrDisableDirstackObjects ()
  1866. {
  1867. foreach (object o in dirStackControlsOrComponents) {
  1868. if (o is Control) {
  1869. Control c = o as Control;
  1870. c.Enabled = (directoryStack.Count > 1);
  1871. } else
  1872. if (o is ToolBarButton) {
  1873. ToolBarButton t = o as ToolBarButton;
  1874. t.Enabled = (directoryStack.Count > 0);
  1875. }
  1876. }
  1877. }
  1878. private void DoOneFSEntry (FSEntry fsEntry)
  1879. {
  1880. if (!ShowHiddenFiles)
  1881. if (fsEntry.Name.StartsWith (".") || fsEntry.Attributes == FileAttributes.Hidden)
  1882. return;
  1883. FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
  1884. Items.Add (listViewItem);
  1885. }
  1886. private void MWF_KeyDown (object sender, KeyEventArgs e)
  1887. {
  1888. if (e.KeyCode == Keys.Back) {
  1889. OneDirUp ();
  1890. }
  1891. }
  1892. protected override void OnClick (EventArgs e)
  1893. {
  1894. if (!MultiSelect) {
  1895. if (SelectedItems.Count > 0) {
  1896. FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
  1897. FSEntry fsEntry = listViewItem.FSEntry;
  1898. if (fsEntry.FileType == FSEntry.FSEntryType.File) {
  1899. currentFSEntry = fsEntry;
  1900. if (on_selected_file_changed != null)
  1901. on_selected_file_changed (this, EventArgs.Empty);
  1902. }
  1903. }
  1904. }
  1905. base.OnClick (e);
  1906. }
  1907. protected override void OnDoubleClick (EventArgs e)
  1908. {
  1909. if (SelectedItems.Count > 0) {
  1910. FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
  1911. FSEntry fsEntry = listViewItem.FSEntry;
  1912. if (fsEntry.Attributes == FileAttributes.Directory) {
  1913. ChangeDirectory (null, fsEntry.FullName);
  1914. if (on_directory_changed != null)
  1915. on_directory_changed (this, EventArgs.Empty);
  1916. } else {
  1917. currentFSEntry = fsEntry;
  1918. if (on_selected_file_changed != null)
  1919. on_selected_file_changed (this, EventArgs.Empty);
  1920. if (on_force_dialog_end != null)
  1921. on_force_dialog_end (this, EventArgs.Empty);
  1922. return;
  1923. }
  1924. }
  1925. base.OnDoubleClick (e);
  1926. }
  1927. protected override void OnSelectedIndexChanged (EventArgs e)
  1928. {
  1929. if (SelectedItems.Count > 0) {
  1930. selectedFilesString = String.Empty;
  1931. if (SelectedItems.Count == 1) {
  1932. FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
  1933. FSEntry fsEntry = listViewItem.FSEntry;
  1934. if (fsEntry.Attributes != FileAttributes.Directory)
  1935. selectedFilesString = SelectedItems [0].Text;
  1936. } else {
  1937. foreach (FileViewListViewItem lvi in SelectedItems) {
  1938. FSEntry fsEntry = lvi.FSEntry;
  1939. if (fsEntry.Attributes != FileAttributes.Directory)
  1940. selectedFilesString = selectedFilesString + "\"" + lvi.Text + " ";
  1941. }
  1942. }
  1943. if (on_selected_files_changed != null)
  1944. on_selected_files_changed (this, EventArgs.Empty);
  1945. }
  1946. base.OnSelectedIndexChanged (e);
  1947. }
  1948. protected override void OnMouseMove (MouseEventArgs e)
  1949. {
  1950. FileViewListViewItem item = GetItemAt (e.X, e.Y) as FileViewListViewItem;
  1951. if (item != null) {
  1952. int currentItemIndex = item.Index;
  1953. if (currentItemIndex != oldItemIndexForToolTip) {
  1954. oldItemIndexForToolTip = currentItemIndex;
  1955. if (toolTip != null && toolTip.Active)
  1956. toolTip.Active = false;
  1957. FSEntry fsEntry = item.FSEntry;
  1958. string output = String.Empty;
  1959. if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
  1960. output = "Directory: " + fsEntry.FullName;
  1961. else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
  1962. output = "Device: "+ fsEntry.FullName;
  1963. else if (fsEntry.FileType == FSEntry.FSEntryType.Network)
  1964. output = "Network: " + fsEntry.FullName;
  1965. else
  1966. output = "File: " + fsEntry.FullName;
  1967. toolTip.SetToolTip (this, output);
  1968. toolTip.Active = true;
  1969. }
  1970. } else
  1971. toolTip.Active = false;
  1972. base.OnMouseMove (e);
  1973. }
  1974. void OnClickContextMenu (object sender, EventArgs e)
  1975. {
  1976. MenuItem senderMenuItem = sender as MenuItem;
  1977. if (senderMenuItem == showHiddenFilesMenuItem) {
  1978. senderMenuItem.Checked = !senderMenuItem.Checked;
  1979. showHiddenFiles = senderMenuItem.Checked;
  1980. UpdateFileView ();
  1981. }
  1982. }
  1983. void OnClickViewMenuSubItem (object sender, EventArgs e)
  1984. {
  1985. MenuItem senderMenuItem = (MenuItem)sender;
  1986. UpdateMenuItems (senderMenuItem);
  1987. // update me
  1988. switch (senderMenuItem.Index) {
  1989. case 0:
  1990. View = View.SmallIcon;
  1991. break;
  1992. case 1:
  1993. View = View.LargeIcon;
  1994. break;
  1995. case 2:
  1996. View = View.LargeIcon;
  1997. break;
  1998. case 3:
  1999. View = View.List;
  2000. break;
  2001. case 4:
  2002. View = View.Details;
  2003. break;
  2004. default:
  2005. break;
  2006. }
  2007. }
  2008. private void UpdateMenuItems (MenuItem senderMenuItem)
  2009. {
  2010. menuItemView.MenuItems [previousCheckedMenuItemIndex].Checked = false;
  2011. menuItemView.MenuItems [senderMenuItem.Index].Checked = true;
  2012. foreach (MenuItem[] items in viewMenuItemClones) {
  2013. items [previousCheckedMenuItemIndex].Checked = false;
  2014. items [senderMenuItem.Index].Checked = true;
  2015. }
  2016. previousCheckedMenuItemIndex = senderMenuItem.Index;
  2017. }
  2018. void OnClickNewFolderMenuItem (object sender, EventArgs e)
  2019. {
  2020. CreateNewFolder ();
  2021. }
  2022. public event EventHandler SelectedFileChanged {
  2023. add { on_selected_file_changed += value; }
  2024. remove { on_selected_file_changed -= value; }
  2025. }
  2026. public event EventHandler SelectedFilesChanged {
  2027. add { on_selected_files_changed += value; }
  2028. remove { on_selected_files_changed -= value; }
  2029. }
  2030. public event EventHandler DirectoryChanged {
  2031. add { on_directory_changed += value; }
  2032. remove { on_directory_changed -= value; }
  2033. }
  2034. public event EventHandler ForceDialogEnd {
  2035. add { on_force_dialog_end += value; }
  2036. remove { on_force_dialog_end -= value; }
  2037. }
  2038. }
  2039. #endregion
  2040. #region FileListViewItem
  2041. internal class FileViewListViewItem : ListViewItem
  2042. {
  2043. private FSEntry fsEntry;
  2044. public FileViewListViewItem (FSEntry fsEntry)
  2045. {
  2046. this.fsEntry = fsEntry;
  2047. ImageIndex = fsEntry.IconIndex;
  2048. Text = fsEntry.Name;
  2049. switch (fsEntry.FileType) {
  2050. case FSEntry.FSEntryType.Directory:
  2051. SubItems.Add (String.Empty);
  2052. SubItems.Add ("Directory");
  2053. SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
  2054. break;
  2055. case FSEntry.FSEntryType.File:
  2056. long fileLen = 1;
  2057. try {
  2058. if (fsEntry.FileSize > 1024)
  2059. fileLen = fsEntry.FileSize / 1024;
  2060. } catch (Exception) {
  2061. fileLen = 1;
  2062. }
  2063. SubItems.Add (fileLen.ToString () + " KB");
  2064. SubItems.Add ("File");
  2065. SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
  2066. break;
  2067. case FSEntry.FSEntryType.Device:
  2068. SubItems.Add (String.Empty);
  2069. SubItems.Add ("Device");
  2070. SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
  2071. break;
  2072. case FSEntry.FSEntryType.RemovableDevice:
  2073. SubItems.Add (String.Empty);
  2074. SubItems.Add ("RemovableDevice");
  2075. SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
  2076. break;
  2077. default:
  2078. break;
  2079. }
  2080. }
  2081. public FSEntry FSEntry {
  2082. set {
  2083. fsEntry = value;
  2084. }
  2085. get {
  2086. return fsEntry;
  2087. }
  2088. }
  2089. }
  2090. #endregion
  2091. #region IUpdateFolder
  2092. internal interface IUpdateFolder
  2093. {
  2094. string CurrentFolder {get; set;}
  2095. }
  2096. #endregion
  2097. #region TextEntryDialog
  2098. // FIXME: When ListView.LabelEdit is implemented remove me
  2099. internal class TextEntryDialog : Form
  2100. {
  2101. private Label label1;
  2102. private Button okButton;
  2103. private TextBox newNameTextBox;
  2104. private PictureBox iconPictureBox;
  2105. private Button cancelButton;
  2106. private GroupBox groupBox1;
  2107. public TextEntryDialog ()
  2108. {
  2109. groupBox1 = new GroupBox ();
  2110. cancelButton = new Button ();
  2111. iconPictureBox = new PictureBox ();
  2112. newNameTextBox = new TextBox ();
  2113. okButton = new Button ();
  2114. label1 = new Label ();
  2115. groupBox1.SuspendLayout ();
  2116. SuspendLayout ();
  2117. // groupBox1
  2118. groupBox1.Controls.Add (newNameTextBox);
  2119. groupBox1.Controls.Add (label1);
  2120. groupBox1.Controls.Add (iconPictureBox);
  2121. groupBox1.Location = new Point (8, 8);
  2122. groupBox1.Size = new Size (232, 160);
  2123. groupBox1.TabIndex = 5;
  2124. groupBox1.TabStop = false;
  2125. groupBox1.Text = "New Name";
  2126. // cancelButton
  2127. cancelButton.DialogResult = DialogResult.Cancel;
  2128. cancelButton.Location = new Point (168, 176);
  2129. cancelButton.TabIndex = 4;
  2130. cancelButton.Text = "Cancel";
  2131. // iconPictureBox
  2132. iconPictureBox.BorderStyle = BorderStyle.Fixed3D;
  2133. iconPictureBox.Location = new Point (86, 24);
  2134. iconPictureBox.Size = new Size (60, 60);
  2135. iconPictureBox.TabIndex = 3;
  2136. iconPictureBox.TabStop = false;
  2137. iconPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
  2138. // newNameTextBox
  2139. newNameTextBox.Location = new Point (16, 128);
  2140. newNameTextBox.Size = new Size (200, 20);
  2141. newNameTextBox.TabIndex = 5;
  2142. newNameTextBox.Text = String.Empty;
  2143. // okButton
  2144. okButton.DialogResult = DialogResult.OK;
  2145. okButton.Location = new Point (80, 176);
  2146. okButton.TabIndex = 3;
  2147. okButton.Text = "OK";
  2148. // label1
  2149. label1.Location = new Point (16, 96);
  2150. label1.Size = new Size (200, 23);
  2151. label1.TabIndex = 4;
  2152. label1.Text = "Enter Name:";
  2153. label1.TextAlign = ContentAlignment.MiddleCenter;
  2154. // MainForm
  2155. AcceptButton = okButton;
  2156. AutoScaleBaseSize = new Size (5, 13);
  2157. CancelButton = cancelButton;
  2158. ClientSize = new Size (248, 205);
  2159. Controls.Add (groupBox1);
  2160. Controls.Add (cancelButton);
  2161. Controls.Add (okButton);
  2162. FormBorderStyle = FormBorderStyle.FixedDialog;
  2163. Text = "New Folder or File";
  2164. groupBox1.ResumeLayout (false);
  2165. ResumeLayout (false);
  2166. newNameTextBox.Select ();
  2167. }
  2168. public Image IconPictureBoxImage {
  2169. set {
  2170. iconPictureBox.Image = value;
  2171. }
  2172. }
  2173. public string FileName {
  2174. get {
  2175. return newNameTextBox.Text;
  2176. }
  2177. set {
  2178. newNameTextBox.Text = value;
  2179. }
  2180. }
  2181. }
  2182. #endregion
  2183. #region MWFVFS
  2184. internal class MWFVFS
  2185. {
  2186. private FileSystem fileSystem;
  2187. private int platform = (int) Environment.OSVersion.Platform;
  2188. public static readonly string DesktopPrefix = "Desktop://";
  2189. public static readonly string PersonalPrefix = "Personal://";
  2190. public static readonly string MyComputerPrefix = "MyComputer://";
  2191. public static readonly string RecentlyUsedPrefix = "RecentlyUsed://";
  2192. public static readonly string MyNetworkPrefix = "MyNetwork://";
  2193. public static readonly string MyComputerPersonalPrefix = "MyComputerPersonal://";
  2194. public static Hashtable MyComputerDevicesPrefix = new Hashtable ();
  2195. public delegate void UpdateDelegate (ArrayList folders, ArrayList files);
  2196. private UpdateDelegate updateDelegate;
  2197. private Control calling_control;
  2198. private ThreadStart get_folder_content_thread_start;
  2199. private Thread worker;
  2200. private WorkerThread workerThread = null;
  2201. private StringCollection the_filters;
  2202. public MWFVFS ()
  2203. {
  2204. if ((platform == 4) || (platform == 128)) {
  2205. fileSystem = new UnixFileSystem ();
  2206. } else {
  2207. fileSystem = new WinFileSystem ();
  2208. }
  2209. }
  2210. public FSEntry ChangeDirectory (string folder)
  2211. {
  2212. return fileSystem.ChangeDirectory (folder);
  2213. }
  2214. public void GetFolderContent ()
  2215. {
  2216. GetFolderContent (null);
  2217. }
  2218. public void GetFolderContent (StringCollection filters)
  2219. {
  2220. the_filters = filters;
  2221. if (workerThread != null) {
  2222. workerThread.Stop ();
  2223. workerThread = null;
  2224. }
  2225. // Added next line to ensure the control is created before BeginInvoke is called on it
  2226. calling_control.CreateControl();
  2227. workerThread = new WorkerThread (fileSystem, the_filters, updateDelegate, calling_control);
  2228. get_folder_content_thread_start = new ThreadStart (workerThread.GetFolderContentThread);
  2229. worker = new Thread (get_folder_content_thread_start);
  2230. worker.IsBackground = true;
  2231. worker.Start();
  2232. }
  2233. internal class WorkerThread
  2234. {
  2235. private FileSystem fileSystem;
  2236. private StringCollection the_filters;
  2237. private UpdateDelegate updateDelegate;
  2238. private Control calling_control;
  2239. private readonly object lockobject = new object ();
  2240. private bool stopped = false;
  2241. public WorkerThread (FileSystem fileSystem, StringCollection the_filters, UpdateDelegate updateDelegate, Control calling_control)
  2242. {
  2243. this.fileSystem = fileSystem;
  2244. this.the_filters = the_filters;
  2245. this.updateDelegate = updateDelegate;
  2246. this.calling_control = calling_control;
  2247. }
  2248. public void GetFolderContentThread()
  2249. {
  2250. ArrayList folders;
  2251. ArrayList files;
  2252. fileSystem.GetFolderContent (the_filters, out folders, out files);
  2253. if (stopped)
  2254. return;
  2255. if (updateDelegate != null) {
  2256. lock (this) {
  2257. object[] objectArray = new object[2];
  2258. objectArray[0] = folders;
  2259. objectArray[1] = files;
  2260. calling_control.BeginInvoke (updateDelegate, objectArray);
  2261. }
  2262. }
  2263. }
  2264. public void Stop ()
  2265. {
  2266. lock (lockobject) {
  2267. stopped = true;
  2268. }
  2269. }
  2270. }
  2271. public ArrayList GetFoldersOnly ()
  2272. {
  2273. return fileSystem.GetFoldersOnly ();
  2274. }
  2275. public void WriteRecentlyUsedFiles (string filename)
  2276. {
  2277. fileSystem.WriteRecentlyUsedFiles (filename);
  2278. }
  2279. public ArrayList GetRecentlyUsedFiles ()
  2280. {
  2281. return fileSystem.GetRecentlyUsedFiles ();
  2282. }
  2283. public ArrayList GetMyComputerContent ()
  2284. {
  2285. return fileSystem.GetMyComputerContent ();
  2286. }
  2287. public ArrayList GetMyNetworkContent ()
  2288. {
  2289. return fileSystem.GetMyNetworkContent ();
  2290. }
  2291. public bool CreateFolder (string new_folder)
  2292. {
  2293. try {
  2294. if (Directory.Exists (new_folder)) {
  2295. string message = "Folder \"" + new_folder + "\" already exists.";
  2296. MessageBox.Show (message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  2297. return false;
  2298. } else
  2299. Directory.CreateDirectory (new_folder);
  2300. } catch (Exception e) {
  2301. MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
  2302. return false;
  2303. }
  2304. return true;
  2305. }
  2306. public string GetParent ()
  2307. {
  2308. return fileSystem.GetParent ();
  2309. }
  2310. public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
  2311. {
  2312. this.updateDelegate = updateDelegate;
  2313. calling_control = control;
  2314. }
  2315. }
  2316. #endregion
  2317. #region FileSystem
  2318. internal abstract class FileSystem
  2319. {
  2320. protected string currentTopFolder = String.Empty;
  2321. protected FSEntry currentFolderFSEntry = null;
  2322. protected FSEntry currentTopFolderFSEntry = null;
  2323. public FSEntry ChangeDirectory (string folder)
  2324. {
  2325. if (folder == MWFVFS.DesktopPrefix) {
  2326. currentTopFolder = MWFVFS.DesktopPrefix;
  2327. currentTopFolderFSEntry = currentFolderFSEntry = GetDesktopFSEntry ();
  2328. } else
  2329. if (folder == MWFVFS.PersonalPrefix) {
  2330. currentTopFolder = MWFVFS.PersonalPrefix;
  2331. currentTopFolderFSEntry = currentFolderFSEntry = GetPersonalFSEntry ();
  2332. } else
  2333. if (folder == MWFVFS.MyComputerPersonalPrefix) {
  2334. currentTopFolder = MWFVFS.MyComputerPersonalPrefix;
  2335. currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerPersonalFSEntry ();
  2336. } else
  2337. if (folder == MWFVFS.RecentlyUsedPrefix) {
  2338. currentTopFolder = MWFVFS.RecentlyUsedPrefix;
  2339. currentTopFolderFSEntry = currentFolderFSEntry = GetRecentlyUsedFSEntry ();
  2340. } else
  2341. if (folder == MWFVFS.MyComputerPrefix) {
  2342. currentTopFolder = MWFVFS.MyComputerPrefix;
  2343. currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerFSEntry ();
  2344. } else
  2345. if (folder == MWFVFS.MyNetworkPrefix) {
  2346. currentTopFolder = MWFVFS.MyNetworkPrefix;
  2347. currentTopFolderFSEntry = currentFolderFSEntry = GetMyNetworkFSEntry ();
  2348. } else {
  2349. bool found = false;
  2350. foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
  2351. FSEntry fsEntry = entry.Value as FSEntry;
  2352. if (folder == fsEntry.FullName) {
  2353. currentTopFolder = entry.Key as string;
  2354. currentTopFolderFSEntry = currentFolderFSEntry = fsEntry;
  2355. found = true;
  2356. break;
  2357. }
  2358. }
  2359. if (!found) {
  2360. currentFolderFSEntry = GetDirectoryFSEntry (new DirectoryInfo (folder), currentTopFolderFSEntry);
  2361. }
  2362. }
  2363. return currentFolderFSEntry;
  2364. }
  2365. public string GetParent ()
  2366. {
  2367. return currentFolderFSEntry.Parent;
  2368. }
  2369. // directories_out and files_out contain FSEntry objects
  2370. public void GetFolderContent (StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
  2371. {
  2372. directories_out = new ArrayList ();
  2373. files_out = new ArrayList ();
  2374. if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
  2375. FSEntry personalFSEntry = GetPersonalFSEntry ();
  2376. directories_out.Add (personalFSEntry);
  2377. FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
  2378. directories_out.Add (myComputerFSEntry);
  2379. FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
  2380. directories_out.Add (myNetworkFSEntry);
  2381. ArrayList d_out = null;
  2382. ArrayList f_out = null;
  2383. GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesDesktop), filters, out d_out, out f_out);
  2384. directories_out.AddRange (d_out);
  2385. files_out.AddRange (f_out);
  2386. } else
  2387. if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
  2388. files_out = GetRecentlyUsedFiles ();
  2389. } else
  2390. if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
  2391. directories_out.AddRange (GetMyComputerContent ());
  2392. } else
  2393. if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
  2394. ArrayList d_out = null;
  2395. ArrayList f_out = null;
  2396. GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesPersonal), filters, out d_out, out f_out);
  2397. directories_out.AddRange (d_out);
  2398. files_out.AddRange (f_out);
  2399. } else
  2400. if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
  2401. directories_out.AddRange (GetMyNetworkContent ());
  2402. } else {
  2403. GetNormalFolderContent (currentFolderFSEntry.FullName, filters, out directories_out, out files_out);
  2404. }
  2405. }
  2406. public ArrayList GetFoldersOnly ()
  2407. {
  2408. ArrayList directories_out = new ArrayList ();
  2409. if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
  2410. FSEntry personalFSEntry = GetPersonalFSEntry ();
  2411. directories_out.Add (personalFSEntry);
  2412. FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
  2413. directories_out.Add (myComputerFSEntry);
  2414. FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
  2415. directories_out.Add (myNetworkFSEntry);
  2416. ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
  2417. directories_out.AddRange (d_out);
  2418. } else
  2419. if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
  2420. //files_out = GetRecentlyUsedFiles ();
  2421. } else
  2422. if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
  2423. directories_out.AddRange (GetMyComputerContent ());
  2424. } else
  2425. if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
  2426. ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
  2427. directories_out.AddRange (d_out);
  2428. } else
  2429. if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
  2430. directories_out.AddRange (GetMyNetworkContent ());
  2431. } else {
  2432. directories_out = GetNormalFolders (currentFolderFSEntry.FullName);
  2433. }
  2434. return directories_out;
  2435. }
  2436. protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
  2437. {
  2438. DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
  2439. directories_out = new ArrayList ();
  2440. DirectoryInfo[] dirs = null;
  2441. try {
  2442. dirs = dirinfo.GetDirectories ();
  2443. } catch (Exception) {}
  2444. if (dirs != null)
  2445. for (int i = 0; i < dirs.Length; i++) {
  2446. directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
  2447. }
  2448. files_out = new ArrayList ();
  2449. ArrayList files = new ArrayList ();
  2450. try {
  2451. if (filters == null) {
  2452. files.AddRange (dirinfo.GetFiles ());
  2453. } else {
  2454. foreach (string s in filters)
  2455. files.AddRange (dirinfo.GetFiles (s));
  2456. }
  2457. } catch (Exception) {}
  2458. for (int i = 0; i < files.Count; i++) {
  2459. FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
  2460. if (fs != null)
  2461. files_out.Add (fs);
  2462. }
  2463. }
  2464. protected ArrayList GetNormalFolders (string from_folder)
  2465. {
  2466. DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
  2467. ArrayList directories_out = new ArrayList ();
  2468. DirectoryInfo[] dirs = null;
  2469. try {
  2470. dirs = dirinfo.GetDirectories ();
  2471. } catch (Exception) {}
  2472. if (dirs != null)
  2473. for (int i = 0; i < dirs.Length; i++) {
  2474. directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
  2475. }
  2476. return directories_out;
  2477. }
  2478. protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
  2479. {
  2480. FSEntry fs = new FSEntry ();
  2481. fs.Attributes = dirinfo.Attributes;
  2482. fs.FullName = dirinfo.FullName;
  2483. fs.Name = dirinfo.Name;
  2484. fs.MainTopNode = topFolderFSEntry;
  2485. fs.FileType = FSEntry.FSEntryType.Directory;
  2486. fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
  2487. fs.LastAccessTime = dirinfo.LastAccessTime;
  2488. return fs;
  2489. }
  2490. protected virtual FSEntry GetFileFSEntry (FileInfo fileinfo)
  2491. {
  2492. // *sigh* FileInfo gives us no usable information for links to directories
  2493. // so, return null
  2494. if ((fileinfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  2495. return null;
  2496. FSEntry fs = new FSEntry ();
  2497. fs.Attributes = fileinfo.Attributes;
  2498. fs.FullName = fileinfo.FullName;
  2499. fs.Name = fileinfo.Name;
  2500. fs.FileType = FSEntry.FSEntryType.File;
  2501. fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
  2502. fs.FileSize = fileinfo.Length;
  2503. fs.LastAccessTime = fileinfo.LastAccessTime;
  2504. return fs;
  2505. }
  2506. protected abstract FSEntry GetDesktopFSEntry ();
  2507. protected abstract FSEntry GetRecentlyUsedFSEntry ();
  2508. protected abstract FSEntry GetPersonalFSEntry ();
  2509. protected abstract FSEntry GetMyComputerPersonalFSEntry ();
  2510. protected abstract FSEntry GetMyComputerFSEntry ();
  2511. protected abstract FSEntry GetMyNetworkFSEntry ();
  2512. public abstract void WriteRecentlyUsedFiles (string fileToAdd);
  2513. public abstract ArrayList GetRecentlyUsedFiles ();
  2514. public abstract ArrayList GetMyComputerContent ();
  2515. public abstract ArrayList GetMyNetworkContent ();
  2516. }
  2517. #endregion
  2518. #region UnixFileSystem
  2519. internal class UnixFileSystem : FileSystem
  2520. {
  2521. private MasterMount masterMount = new MasterMount ();
  2522. private FSEntry desktopFSEntry = null;
  2523. private FSEntry recentlyusedFSEntry = null;
  2524. private FSEntry personalFSEntry = null;
  2525. private FSEntry mycomputerpersonalFSEntry = null;
  2526. private FSEntry mycomputerFSEntry = null;
  2527. private FSEntry mynetworkFSEntry = null;
  2528. private string personal_folder;
  2529. private string recently_used_path;
  2530. private string full_kde_recent_document_dir;
  2531. public UnixFileSystem ()
  2532. {
  2533. personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
  2534. recently_used_path = Path.Combine (personal_folder, ".recently-used");
  2535. full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
  2536. desktopFSEntry = new FSEntry ();
  2537. desktopFSEntry.Attributes = FileAttributes.Directory;
  2538. desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
  2539. desktopFSEntry.Name = "Desktop";
  2540. desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
  2541. desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2542. desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
  2543. desktopFSEntry.LastAccessTime = DateTime.Now;
  2544. recentlyusedFSEntry = new FSEntry ();
  2545. recentlyusedFSEntry.Attributes = FileAttributes.Directory;
  2546. recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
  2547. recentlyusedFSEntry.Name = "Recently Used";
  2548. recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2549. recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
  2550. recentlyusedFSEntry.LastAccessTime = DateTime.Now;
  2551. personalFSEntry = new FSEntry ();
  2552. personalFSEntry.Attributes = FileAttributes.Directory;
  2553. personalFSEntry.FullName = MWFVFS.PersonalPrefix;
  2554. personalFSEntry.Name = "Personal";
  2555. personalFSEntry.MainTopNode = GetDesktopFSEntry ();
  2556. personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
  2557. personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2558. personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
  2559. personalFSEntry.LastAccessTime = DateTime.Now;
  2560. mycomputerpersonalFSEntry = new FSEntry ();
  2561. mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
  2562. mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
  2563. mycomputerpersonalFSEntry.Name = "Personal";
  2564. mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
  2565. mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
  2566. mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2567. mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
  2568. mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
  2569. mycomputerFSEntry = new FSEntry ();
  2570. mycomputerFSEntry.Attributes = FileAttributes.Directory;
  2571. mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
  2572. mycomputerFSEntry.Name = "My Computer";
  2573. mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
  2574. mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2575. mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
  2576. mycomputerFSEntry.LastAccessTime = DateTime.Now;
  2577. mynetworkFSEntry = new FSEntry ();
  2578. mynetworkFSEntry.Attributes = FileAttributes.Directory;
  2579. mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
  2580. mynetworkFSEntry.Name = "My Network";
  2581. mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
  2582. mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2583. mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
  2584. mynetworkFSEntry.LastAccessTime = DateTime.Now;
  2585. }
  2586. public override void WriteRecentlyUsedFiles (string fileToAdd)
  2587. {
  2588. if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
  2589. XmlDocument xml_doc = new XmlDocument ();
  2590. xml_doc.Load (recently_used_path);
  2591. XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
  2592. if (grand_parent_node != null) {
  2593. // create a new element
  2594. XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
  2595. XmlElement new_child = xml_doc.CreateElement ("URI");
  2596. UriBuilder ub = new UriBuilder ();
  2597. ub.Path = fileToAdd;
  2598. ub.Host = null;
  2599. ub.Scheme = "file";
  2600. XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
  2601. new_child.AppendChild (new_text_child);
  2602. new_recent_item_node.AppendChild (new_child);
  2603. new_child = xml_doc.CreateElement ("Mime-Type");
  2604. new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
  2605. new_child.AppendChild (new_text_child);
  2606. new_recent_item_node.AppendChild (new_child);
  2607. new_child = xml_doc.CreateElement ("Timestamp");
  2608. long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
  2609. new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
  2610. new_child.AppendChild (new_text_child);
  2611. new_recent_item_node.AppendChild (new_child);
  2612. new_child = xml_doc.CreateElement ("Groups");
  2613. new_recent_item_node.AppendChild (new_child);
  2614. // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
  2615. // so that the new node is the first one
  2616. foreach (XmlNode n in grand_parent_node.ChildNodes) {
  2617. XmlNode uri_node = n.SelectSingleNode ("URI");
  2618. if (uri_node != null) {
  2619. XmlNode uri_node_child = uri_node.FirstChild;
  2620. if (uri_node_child is XmlText)
  2621. if (ub.ToString () == ((XmlText)uri_node_child).Data) {
  2622. grand_parent_node.RemoveChild (n);
  2623. break;
  2624. }
  2625. }
  2626. }
  2627. // prepend the new recent item to the grand parent node list
  2628. grand_parent_node.PrependChild (new_recent_item_node);
  2629. // limit the # of RecentItems to 10
  2630. if (grand_parent_node.ChildNodes.Count > 10) {
  2631. while (grand_parent_node.ChildNodes.Count > 10)
  2632. grand_parent_node.RemoveChild (grand_parent_node.LastChild);
  2633. }
  2634. try {
  2635. xml_doc.Save (recently_used_path);
  2636. } catch (Exception) {
  2637. }
  2638. }
  2639. } else {
  2640. XmlDocument xml_doc = new XmlDocument ();
  2641. xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
  2642. XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
  2643. XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
  2644. XmlElement new_child = xml_doc.CreateElement ("URI");
  2645. UriBuilder ub = new UriBuilder ();
  2646. ub.Path = fileToAdd;
  2647. ub.Host = null;
  2648. ub.Scheme = "file";
  2649. XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
  2650. new_child.AppendChild (new_text_child);
  2651. new_recent_item_node.AppendChild (new_child);
  2652. new_child = xml_doc.CreateElement ("Mime-Type");
  2653. new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
  2654. new_child.AppendChild (new_text_child);
  2655. new_recent_item_node.AppendChild (new_child);
  2656. new_child = xml_doc.CreateElement ("Timestamp");
  2657. long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
  2658. new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
  2659. new_child.AppendChild (new_text_child);
  2660. new_recent_item_node.AppendChild (new_child);
  2661. new_child = xml_doc.CreateElement ("Groups");
  2662. new_recent_item_node.AppendChild (new_child);
  2663. recentFiles_element.AppendChild (new_recent_item_node);
  2664. xml_doc.AppendChild (recentFiles_element);
  2665. try {
  2666. xml_doc.Save (recently_used_path);
  2667. } catch (Exception) {
  2668. }
  2669. }
  2670. }
  2671. // return an ArrayList with FSEntry objects
  2672. public override ArrayList GetRecentlyUsedFiles ()
  2673. {
  2674. // check for GNOME and KDE
  2675. ArrayList files_al = new ArrayList ();
  2676. // GNOME
  2677. if (File.Exists (recently_used_path)) {
  2678. try {
  2679. XmlTextReader xtr = new XmlTextReader (recently_used_path);
  2680. while (xtr.Read ()) {
  2681. if (xtr.NodeType == XmlNodeType.Element && xtr.Name.ToUpper () == "URI") {
  2682. xtr.Read ();
  2683. Uri uri = new Uri (xtr.Value);
  2684. if (!files_al.Contains (uri.LocalPath))
  2685. if (File.Exists (uri.LocalPath)) {
  2686. FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
  2687. if (fs != null)
  2688. files_al.Add (fs);
  2689. }
  2690. }
  2691. }
  2692. xtr.Close ();
  2693. } catch (Exception) {
  2694. }
  2695. }
  2696. // KDE
  2697. if (Directory.Exists (full_kde_recent_document_dir)) {
  2698. string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
  2699. foreach (string file_name in files) {
  2700. StreamReader sr = new StreamReader (file_name);
  2701. string line = sr.ReadLine ();
  2702. while (line != null) {
  2703. line = line.Trim ();
  2704. if (line.StartsWith ("URL=")) {
  2705. line = line.Replace ("URL=", String.Empty);
  2706. line = line.Replace ("$HOME", personal_folder);
  2707. Uri uri = new Uri (line);
  2708. if (!files_al.Contains (uri.LocalPath))
  2709. if (File.Exists (uri.LocalPath)) {
  2710. FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
  2711. if (fs != null)
  2712. files_al.Add (fs);
  2713. }
  2714. break;
  2715. }
  2716. line = sr.ReadLine ();
  2717. }
  2718. sr.Close ();
  2719. }
  2720. }
  2721. return files_al;
  2722. }
  2723. // return an ArrayList with FSEntry objects
  2724. public override ArrayList GetMyComputerContent ()
  2725. {
  2726. ArrayList my_computer_content_arraylist = new ArrayList ();
  2727. if (masterMount.ProcMountAvailable) {
  2728. masterMount.GetMounts ();
  2729. foreach (MasterMount.Mount mount in masterMount.Block_devices) {
  2730. FSEntry fsEntry = new FSEntry ();
  2731. fsEntry.FileType = FSEntry.FSEntryType.Device;
  2732. fsEntry.FullName = mount.mount_point;
  2733. fsEntry.Name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
  2734. fsEntry.FsType = mount.fsType;
  2735. fsEntry.DeviceShort = mount.device_short;
  2736. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
  2737. fsEntry.Attributes = FileAttributes.Directory;
  2738. fsEntry.MainTopNode = GetMyComputerFSEntry ();
  2739. my_computer_content_arraylist.Add (fsEntry);
  2740. if (!MWFVFS.MyComputerDevicesPrefix.Contains (fsEntry.FullName + "://"))
  2741. MWFVFS.MyComputerDevicesPrefix.Add (fsEntry.FullName + "://", fsEntry);
  2742. }
  2743. foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
  2744. FSEntry fsEntry = new FSEntry ();
  2745. fsEntry.FileType = FSEntry.FSEntryType.RemovableDevice;
  2746. fsEntry.FullName = mount.mount_point;
  2747. bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
  2748. string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
  2749. string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
  2750. fsEntry.Name = type_name +" (" + mount.device_short + ")";
  2751. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType (mime_type);
  2752. fsEntry.FsType = mount.fsType;
  2753. fsEntry.DeviceShort = mount.device_short;
  2754. fsEntry.Attributes = FileAttributes.Directory;
  2755. fsEntry.MainTopNode = GetMyComputerFSEntry ();
  2756. my_computer_content_arraylist.Add (fsEntry);
  2757. string contain_string = fsEntry.FullName + "://";
  2758. if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
  2759. MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
  2760. }
  2761. }
  2762. my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
  2763. return my_computer_content_arraylist;
  2764. }
  2765. public override ArrayList GetMyNetworkContent ()
  2766. {
  2767. ArrayList fsEntries = new ArrayList ();
  2768. foreach (MasterMount.Mount mount in masterMount.Network_devices) {
  2769. FSEntry fsEntry = new FSEntry ();
  2770. fsEntry.FileType = FSEntry.FSEntryType.Network;
  2771. fsEntry.FullName = mount.mount_point;
  2772. fsEntry.FsType = mount.fsType;
  2773. fsEntry.DeviceShort = mount.device_short;
  2774. fsEntry.Name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
  2775. switch (mount.fsType) {
  2776. case MasterMount.FsTypes.nfs:
  2777. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
  2778. break;
  2779. case MasterMount.FsTypes.smbfs:
  2780. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
  2781. break;
  2782. case MasterMount.FsTypes.ncpfs:
  2783. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
  2784. break;
  2785. case MasterMount.FsTypes.cifs:
  2786. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
  2787. break;
  2788. default:
  2789. break;
  2790. }
  2791. fsEntry.Attributes = FileAttributes.Directory;
  2792. fsEntry.MainTopNode = GetMyNetworkFSEntry ();
  2793. fsEntries.Add (fsEntry);
  2794. }
  2795. return fsEntries;
  2796. }
  2797. protected override FSEntry GetDesktopFSEntry ()
  2798. {
  2799. return desktopFSEntry;
  2800. }
  2801. protected override FSEntry GetRecentlyUsedFSEntry ()
  2802. {
  2803. return recentlyusedFSEntry;
  2804. }
  2805. protected override FSEntry GetPersonalFSEntry ()
  2806. {
  2807. return personalFSEntry;
  2808. }
  2809. protected override FSEntry GetMyComputerPersonalFSEntry ()
  2810. {
  2811. return mycomputerpersonalFSEntry;
  2812. }
  2813. protected override FSEntry GetMyComputerFSEntry ()
  2814. {
  2815. return mycomputerFSEntry;
  2816. }
  2817. protected override FSEntry GetMyNetworkFSEntry ()
  2818. {
  2819. return mynetworkFSEntry;
  2820. }
  2821. }
  2822. #endregion
  2823. #region WinFileSystem
  2824. internal class WinFileSystem : FileSystem
  2825. {
  2826. private FSEntry desktopFSEntry = null;
  2827. private FSEntry recentlyusedFSEntry = null;
  2828. private FSEntry personalFSEntry = null;
  2829. private FSEntry mycomputerpersonalFSEntry = null;
  2830. private FSEntry mycomputerFSEntry = null;
  2831. private FSEntry mynetworkFSEntry = null;
  2832. public WinFileSystem ()
  2833. {
  2834. desktopFSEntry = new FSEntry ();
  2835. desktopFSEntry.Attributes = FileAttributes.Directory;
  2836. desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
  2837. desktopFSEntry.Name = "Desktop";
  2838. desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
  2839. desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2840. desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
  2841. desktopFSEntry.LastAccessTime = DateTime.Now;
  2842. recentlyusedFSEntry = new FSEntry ();
  2843. recentlyusedFSEntry.Attributes = FileAttributes.Directory;
  2844. recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
  2845. recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
  2846. recentlyusedFSEntry.Name = "Recently Used";
  2847. recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2848. recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
  2849. recentlyusedFSEntry.LastAccessTime = DateTime.Now;
  2850. personalFSEntry = new FSEntry ();
  2851. personalFSEntry.Attributes = FileAttributes.Directory;
  2852. personalFSEntry.FullName = MWFVFS.PersonalPrefix;
  2853. personalFSEntry.Name = "Personal";
  2854. personalFSEntry.MainTopNode = GetDesktopFSEntry ();
  2855. personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
  2856. personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2857. personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
  2858. personalFSEntry.LastAccessTime = DateTime.Now;
  2859. mycomputerpersonalFSEntry = new FSEntry ();
  2860. mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
  2861. mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
  2862. mycomputerpersonalFSEntry.Name = "Personal";
  2863. mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
  2864. mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
  2865. mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2866. mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
  2867. mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
  2868. mycomputerFSEntry = new FSEntry ();
  2869. mycomputerFSEntry.Attributes = FileAttributes.Directory;
  2870. mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
  2871. mycomputerFSEntry.Name = "My Computer";
  2872. mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
  2873. mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2874. mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
  2875. mycomputerFSEntry.LastAccessTime = DateTime.Now;
  2876. mynetworkFSEntry = new FSEntry ();
  2877. mynetworkFSEntry.Attributes = FileAttributes.Directory;
  2878. mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
  2879. mynetworkFSEntry.Name = "My Network";
  2880. mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
  2881. mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
  2882. mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
  2883. mynetworkFSEntry.LastAccessTime = DateTime.Now;
  2884. }
  2885. public override void WriteRecentlyUsedFiles (string fileToAdd)
  2886. {
  2887. // TODO: Implement this method
  2888. // use SHAddToRecentDocs ?
  2889. }
  2890. public override ArrayList GetRecentlyUsedFiles ()
  2891. {
  2892. ArrayList al = new ArrayList ();
  2893. DirectoryInfo di = new DirectoryInfo (recentlyusedFSEntry.RealName);
  2894. FileInfo[] fileinfos = di.GetFiles ();
  2895. foreach (FileInfo fi in fileinfos) {
  2896. FSEntry fs = GetFileFSEntry (fi);
  2897. if (fs != null)
  2898. al.Add (fs);
  2899. }
  2900. return al;
  2901. }
  2902. public override ArrayList GetMyComputerContent ()
  2903. {
  2904. string[] logical_drives = Directory.GetLogicalDrives ();
  2905. ArrayList my_computer_content_arraylist = new ArrayList ();
  2906. foreach (string drive in logical_drives) {
  2907. FSEntry fsEntry = new FSEntry ();
  2908. fsEntry.FileType = FSEntry.FSEntryType.Device;
  2909. fsEntry.FullName = drive;
  2910. fsEntry.Name = drive;
  2911. fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
  2912. fsEntry.Attributes = FileAttributes.Directory;
  2913. fsEntry.MainTopNode = GetMyComputerFSEntry ();
  2914. my_computer_content_arraylist.Add (fsEntry);
  2915. string contain_string = fsEntry.FullName + "://";
  2916. if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
  2917. MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
  2918. }
  2919. my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
  2920. return my_computer_content_arraylist;
  2921. }
  2922. public override ArrayList GetMyNetworkContent ()
  2923. {
  2924. // TODO: Implement this method
  2925. return new ArrayList ();
  2926. }
  2927. protected override FSEntry GetDesktopFSEntry ()
  2928. {
  2929. return desktopFSEntry;
  2930. }
  2931. protected override FSEntry GetRecentlyUsedFSEntry ()
  2932. {
  2933. return recentlyusedFSEntry;
  2934. }
  2935. protected override FSEntry GetPersonalFSEntry ()
  2936. {
  2937. return personalFSEntry;
  2938. }
  2939. protected override FSEntry GetMyComputerPersonalFSEntry ()
  2940. {
  2941. return mycomputerpersonalFSEntry;
  2942. }
  2943. protected override FSEntry GetMyComputerFSEntry ()
  2944. {
  2945. return mycomputerFSEntry;
  2946. }
  2947. protected override FSEntry GetMyNetworkFSEntry ()
  2948. {
  2949. return mynetworkFSEntry;
  2950. }
  2951. }
  2952. #endregion
  2953. #region FSEntry
  2954. internal class FSEntry
  2955. {
  2956. public enum FSEntryType
  2957. {
  2958. Desktop,
  2959. RecentlyUsed,
  2960. MyComputer,
  2961. File,
  2962. Directory,
  2963. Device,
  2964. RemovableDevice,
  2965. Network
  2966. }
  2967. private MasterMount.FsTypes fsType;
  2968. private string device_short;
  2969. private string fullName;
  2970. private string name;
  2971. private string realName = null;
  2972. private FileAttributes attributes = FileAttributes.Normal;
  2973. private long fileSize;
  2974. private FSEntryType fileType;
  2975. private DateTime lastAccessTime;
  2976. private FSEntry mainTopNode = null;
  2977. private int iconIndex;
  2978. private string parent;
  2979. public MasterMount.FsTypes FsType {
  2980. set {
  2981. fsType = value;
  2982. }
  2983. get {
  2984. return fsType;
  2985. }
  2986. }
  2987. public string DeviceShort {
  2988. set {
  2989. device_short = value;
  2990. }
  2991. get {
  2992. return device_short;
  2993. }
  2994. }
  2995. public string FullName {
  2996. set {
  2997. fullName = value;
  2998. }
  2999. get {
  3000. return fullName;
  3001. }
  3002. }
  3003. public string Name {
  3004. set {
  3005. name = value;
  3006. }
  3007. get {
  3008. return name;
  3009. }
  3010. }
  3011. public string RealName {
  3012. set {
  3013. realName = value;
  3014. }
  3015. get {
  3016. return realName;
  3017. }
  3018. }
  3019. public FileAttributes Attributes {
  3020. set {
  3021. attributes = value;
  3022. }
  3023. get {
  3024. return attributes;
  3025. }
  3026. }
  3027. public long FileSize {
  3028. set {
  3029. fileSize = value;
  3030. }
  3031. get {
  3032. return fileSize;
  3033. }
  3034. }
  3035. public FSEntryType FileType {
  3036. set {
  3037. fileType = value;
  3038. }
  3039. get {
  3040. return fileType;
  3041. }
  3042. }
  3043. public DateTime LastAccessTime {
  3044. set {
  3045. lastAccessTime = value;
  3046. }
  3047. get {
  3048. return lastAccessTime;
  3049. }
  3050. }
  3051. public int IconIndex {
  3052. set {
  3053. iconIndex = value;
  3054. }
  3055. get {
  3056. return iconIndex;
  3057. }
  3058. }
  3059. public FSEntry MainTopNode {
  3060. set {
  3061. mainTopNode = value;
  3062. }
  3063. get {
  3064. return mainTopNode;
  3065. }
  3066. }
  3067. public string Parent {
  3068. set {
  3069. parent = value;
  3070. }
  3071. get {
  3072. parent = GetParent ();
  3073. return parent;
  3074. }
  3075. }
  3076. private string GetParent ()
  3077. {
  3078. if (fullName == MWFVFS.PersonalPrefix) {
  3079. return MWFVFS.DesktopPrefix;
  3080. } else
  3081. if (fullName == MWFVFS.MyComputerPersonalPrefix) {
  3082. return MWFVFS.MyComputerPrefix;
  3083. } else
  3084. if (fullName == MWFVFS.MyComputerPrefix) {
  3085. return MWFVFS.DesktopPrefix;
  3086. } else
  3087. if (fullName == MWFVFS.MyNetworkPrefix) {
  3088. return MWFVFS.DesktopPrefix;
  3089. } else
  3090. if (fullName == MWFVFS.DesktopPrefix) {
  3091. return null;
  3092. } else
  3093. if (fullName == MWFVFS.RecentlyUsedPrefix) {
  3094. return null;
  3095. } else {
  3096. foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
  3097. FSEntry fsEntry = entry.Value as FSEntry;
  3098. if (fullName == fsEntry.FullName) {
  3099. return fsEntry.MainTopNode.FullName;
  3100. }
  3101. }
  3102. DirectoryInfo dirInfo = new DirectoryInfo (fullName);
  3103. DirectoryInfo dirInfoParent = dirInfo.Parent;
  3104. if (dirInfoParent != null) {
  3105. FSEntry fsEntry = MWFVFS.MyComputerDevicesPrefix [dirInfoParent.FullName + "://"] as FSEntry;
  3106. if (fsEntry != null) {
  3107. return fsEntry.FullName;
  3108. }
  3109. if (mainTopNode != null) {
  3110. if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop) &&
  3111. mainTopNode.FullName == MWFVFS.DesktopPrefix) {
  3112. return mainTopNode.FullName;
  3113. } else
  3114. if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
  3115. mainTopNode.FullName == MWFVFS.PersonalPrefix) {
  3116. return mainTopNode.FullName;
  3117. } else
  3118. if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
  3119. mainTopNode.FullName == MWFVFS.MyComputerPersonalPrefix) {
  3120. return mainTopNode.FullName;
  3121. }
  3122. }
  3123. return dirInfoParent.FullName;
  3124. }
  3125. }
  3126. return null;
  3127. }
  3128. }
  3129. #endregion
  3130. #region MasterMount
  3131. // Alexsantas little *nix helper
  3132. internal class MasterMount
  3133. {
  3134. // add more...
  3135. internal enum FsTypes
  3136. {
  3137. none,
  3138. ext2,
  3139. ext3,
  3140. hpfs,
  3141. iso9660,
  3142. jfs,
  3143. minix,
  3144. msdos,
  3145. ntfs,
  3146. reiserfs,
  3147. ufs,
  3148. umsdos,
  3149. vfat,
  3150. sysv,
  3151. xfs,
  3152. ncpfs,
  3153. nfs,
  3154. smbfs,
  3155. usbfs,
  3156. cifs
  3157. }
  3158. internal struct Mount
  3159. {
  3160. public string device_or_filesystem;
  3161. public string device_short;
  3162. public string mount_point;
  3163. public FsTypes fsType;
  3164. }
  3165. bool proc_mount_available = false;
  3166. ArrayList block_devices = new ArrayList ();
  3167. ArrayList network_devices = new ArrayList ();
  3168. ArrayList removable_devices = new ArrayList ();
  3169. private int platform = (int) Environment.OSVersion.Platform;
  3170. private MountComparer mountComparer = new MountComparer ();
  3171. public MasterMount ()
  3172. {
  3173. // maybe check if the current user can access /proc/mounts
  3174. if ((platform == 4) || (platform == 128))
  3175. if (File.Exists ("/proc/mounts"))
  3176. proc_mount_available = true;
  3177. }
  3178. public ArrayList Block_devices {
  3179. get {
  3180. return block_devices;
  3181. }
  3182. }
  3183. public ArrayList Network_devices {
  3184. get {
  3185. return network_devices;
  3186. }
  3187. }
  3188. public ArrayList Removable_devices {
  3189. get {
  3190. return removable_devices;
  3191. }
  3192. }
  3193. public bool ProcMountAvailable {
  3194. get {
  3195. return proc_mount_available;
  3196. }
  3197. }
  3198. public void GetMounts ()
  3199. {
  3200. if (!proc_mount_available)
  3201. return;
  3202. block_devices.Clear ();
  3203. network_devices.Clear ();
  3204. removable_devices.Clear ();
  3205. try {
  3206. StreamReader sr = new StreamReader ("/proc/mounts");
  3207. string line = sr.ReadLine ();
  3208. ArrayList lines = new ArrayList ();
  3209. while (line != null) {
  3210. if (lines.IndexOf (line) == -1) { // Avoid duplicates
  3211. ProcessProcMountLine (line);
  3212. lines.Add (line);
  3213. }
  3214. line = sr.ReadLine ();
  3215. }
  3216. sr.Close ();
  3217. block_devices.Sort (mountComparer);
  3218. network_devices.Sort (mountComparer);
  3219. removable_devices.Sort (mountComparer);
  3220. } catch {
  3221. // bla
  3222. }
  3223. }
  3224. private void ProcessProcMountLine (string line)
  3225. {
  3226. string[] split = line.Split (new char [] {' '});
  3227. if (split != null && split.Length > 0) {
  3228. Mount mount = new Mount ();
  3229. if (split [0].StartsWith ("/dev/"))
  3230. mount.device_short = split [0].Replace ("/dev/", String.Empty);
  3231. else
  3232. mount.device_short = split [0];
  3233. mount.device_or_filesystem = split [0];
  3234. mount.mount_point = split [1];
  3235. // TODO: other removable devices, floppy
  3236. // ssh
  3237. // network mount
  3238. if (split [2] == "nfs") {
  3239. mount.fsType = FsTypes.nfs;
  3240. network_devices.Add (mount);
  3241. } else if (split [2] == "smbfs") {
  3242. mount.fsType = FsTypes.smbfs;
  3243. network_devices.Add (mount);
  3244. } else if (split [2] == "cifs") {
  3245. mount.fsType = FsTypes.cifs;
  3246. network_devices.Add (mount);
  3247. } else if (split [2] == "ncpfs") {
  3248. mount.fsType = FsTypes.ncpfs;
  3249. network_devices.Add (mount);
  3250. } else if (split [2] == "iso9660") { //cdrom
  3251. mount.fsType = FsTypes.iso9660;
  3252. removable_devices.Add (mount);
  3253. } else if (split [2] == "usbfs") { //usb ? not tested
  3254. mount.fsType = FsTypes.usbfs;
  3255. removable_devices.Add (mount);
  3256. } else if (split [0].StartsWith ("/")) { //block devices
  3257. if (split [1].StartsWith ("/dev/")) // root static, do not add
  3258. return;
  3259. if (split [2] == "ext2")
  3260. mount.fsType = FsTypes.ext2;
  3261. else if (split [2] == "ext3")
  3262. mount.fsType = FsTypes.ext3;
  3263. else if (split [2] == "reiserfs")
  3264. mount.fsType = FsTypes.reiserfs;
  3265. else if (split [2] == "xfs")
  3266. mount.fsType = FsTypes.xfs;
  3267. else if (split [2] == "vfat")
  3268. mount.fsType = FsTypes.vfat;
  3269. else if (split [2] == "ntfs")
  3270. mount.fsType = FsTypes.ntfs;
  3271. else if (split [2] == "msdos")
  3272. mount.fsType = FsTypes.msdos;
  3273. else if (split [2] == "umsdos")
  3274. mount.fsType = FsTypes.umsdos;
  3275. else if (split [2] == "hpfs")
  3276. mount.fsType = FsTypes.hpfs;
  3277. else if (split [2] == "minix")
  3278. mount.fsType = FsTypes.minix;
  3279. else if (split [2] == "jfs")
  3280. mount.fsType = FsTypes.jfs;
  3281. block_devices.Add (mount);
  3282. }
  3283. }
  3284. }
  3285. public class MountComparer : IComparer
  3286. {
  3287. public int Compare (object mount1, object mount2)
  3288. {
  3289. return String.Compare (((Mount)mount1).device_short, ((Mount)mount2).device_short);
  3290. }
  3291. }
  3292. }
  3293. #endregion
  3294. #region MWFConfig
  3295. // easy to use class to store and read internal MWF config settings.
  3296. // the config values are stored in the users home dir as a hidden xml file called "mwf_config".
  3297. // currently supports int, string, byte, color and arrays (including byte arrays)
  3298. // don't forget, when you read a value you still have to cast this value.
  3299. //
  3300. // usage:
  3301. // MWFConfig.SetValue ("SomeClass", "What", value);
  3302. // object o = MWFConfig.GetValue ("SomeClass", "What");
  3303. //
  3304. // example:
  3305. //
  3306. // string[] configFileNames = (string[])MWFConfig.GetValue ("FileDialog", "FileNames");
  3307. // MWFConfig.SetValue ("FileDialog", "LastFolder", "/home/user");
  3308. internal class MWFConfig
  3309. {
  3310. private static MWFConfigInstance Instance = new MWFConfigInstance ();
  3311. private static object lock_object = new object();
  3312. public static object GetValue (string class_name, string value_name)
  3313. {
  3314. lock (lock_object) {
  3315. return Instance.GetValue (class_name, value_name);
  3316. }
  3317. }
  3318. public static void SetValue (string class_name, string value_name, object value)
  3319. {
  3320. lock (lock_object) {
  3321. Instance.SetValue (class_name, value_name, value);
  3322. }
  3323. }
  3324. public static void Flush ()
  3325. {
  3326. lock (lock_object) {
  3327. Instance.Flush ();
  3328. }
  3329. }
  3330. public static void RemoveClass (string class_name)
  3331. {
  3332. lock (lock_object) {
  3333. Instance.RemoveClass (class_name);
  3334. }
  3335. }
  3336. public static void RemoveClassValue (string class_name, string value_name)
  3337. {
  3338. lock (lock_object) {
  3339. Instance.RemoveClassValue (class_name, value_name);
  3340. }
  3341. }
  3342. public static void RemoveAllClassValues (string class_name)
  3343. {
  3344. lock (lock_object) {
  3345. Instance.RemoveAllClassValues (class_name);
  3346. }
  3347. }
  3348. internal class MWFConfigInstance
  3349. {
  3350. Hashtable classes_hashtable = new Hashtable ();
  3351. string path;
  3352. static string full_file_name;
  3353. XmlTextReader xtr;
  3354. XmlTextWriter xtw;
  3355. static string default_file_name;
  3356. readonly string configName = "MWFConfig";
  3357. static int platform = (int) Environment.OSVersion.Platform;
  3358. static bool IsUnix ()
  3359. {
  3360. return (platform == 4 || platform == 128);
  3361. }
  3362. static MWFConfigInstance ()
  3363. {
  3364. string b = "mwf_config";
  3365. string dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
  3366. if (IsUnix ()){
  3367. dir = Path.Combine (dir, ".mono");
  3368. try {
  3369. Directory.CreateDirectory (dir);
  3370. } catch {}
  3371. }
  3372. default_file_name = Path.Combine (dir, b);
  3373. full_file_name = default_file_name;
  3374. }
  3375. public MWFConfigInstance ()
  3376. {
  3377. Open (default_file_name);
  3378. }
  3379. // only for testing
  3380. public MWFConfigInstance (string filename)
  3381. {
  3382. path = Path.GetDirectoryName (filename);
  3383. if (path == null || path == String.Empty) {
  3384. path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
  3385. full_file_name = Path.Combine (path, filename);
  3386. } else
  3387. full_file_name = filename;
  3388. Open (full_file_name);
  3389. }
  3390. ~MWFConfigInstance ()
  3391. {
  3392. Flush ();
  3393. }
  3394. public object GetValue (string class_name, string value_name)
  3395. {
  3396. ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
  3397. if (class_entry != null)
  3398. return class_entry.GetValue (value_name);
  3399. return null;
  3400. }
  3401. public void SetValue (string class_name, string value_name, object value)
  3402. {
  3403. ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
  3404. if (class_entry == null) {
  3405. class_entry = new ClassEntry ();
  3406. class_entry.ClassName = class_name;
  3407. classes_hashtable [class_name] = class_entry;
  3408. }
  3409. class_entry.SetValue (value_name, value);
  3410. }
  3411. private void Open (string filename)
  3412. {
  3413. try {
  3414. xtr = new XmlTextReader (filename);
  3415. ReadConfig ();
  3416. xtr.Close ();
  3417. } catch (Exception) {
  3418. }
  3419. }
  3420. public void Flush ()
  3421. {
  3422. try {
  3423. xtw = new XmlTextWriter (full_file_name, null);
  3424. xtw.Formatting = Formatting.Indented;
  3425. WriteConfig ();
  3426. xtw.Close ();
  3427. if (!IsUnix ())
  3428. File.SetAttributes (full_file_name, FileAttributes.Hidden);
  3429. } catch (Exception){
  3430. }
  3431. }
  3432. public void RemoveClass (string class_name)
  3433. {
  3434. ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
  3435. if (class_entry != null) {
  3436. class_entry.RemoveAllClassValues ();
  3437. classes_hashtable.Remove (class_name);
  3438. }
  3439. }
  3440. public void RemoveClassValue (string class_name, string value_name)
  3441. {
  3442. ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
  3443. if (class_entry != null) {
  3444. class_entry.RemoveClassValue (value_name);
  3445. }
  3446. }
  3447. public void RemoveAllClassValues (string class_name)
  3448. {
  3449. ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
  3450. if (class_entry != null) {
  3451. class_entry.RemoveAllClassValues ();
  3452. }
  3453. }
  3454. private void ReadConfig ()
  3455. {
  3456. if (!CheckForMWFConfig ())
  3457. return;
  3458. while (xtr.Read ()) {
  3459. switch (xtr.NodeType) {
  3460. case XmlNodeType.Element:
  3461. ClassEntry class_entry = classes_hashtable [xtr.Name] as ClassEntry;
  3462. if (class_entry == null) {
  3463. class_entry = new ClassEntry ();
  3464. class_entry.ClassName = xtr.Name;
  3465. classes_hashtable [xtr.Name] = class_entry;
  3466. }
  3467. class_entry.ReadXml (xtr);
  3468. break;
  3469. }
  3470. }
  3471. }
  3472. private bool CheckForMWFConfig ()
  3473. {
  3474. if (xtr.Read ()) {
  3475. if (xtr.NodeType == XmlNodeType.Element) {
  3476. if (xtr.Name == configName)
  3477. return true;
  3478. }
  3479. }
  3480. return false;
  3481. }
  3482. private void WriteConfig ()
  3483. {
  3484. if (classes_hashtable.Count == 0)
  3485. return;
  3486. xtw.WriteStartElement (configName);
  3487. foreach (DictionaryEntry entry in classes_hashtable) {
  3488. ClassEntry class_entry = entry.Value as ClassEntry;
  3489. class_entry.WriteXml (xtw);
  3490. }
  3491. xtw.WriteEndElement ();
  3492. }
  3493. internal class ClassEntry
  3494. {
  3495. private Hashtable classvalues_hashtable = new Hashtable ();
  3496. private string className;
  3497. public string ClassName {
  3498. set {
  3499. className = value;
  3500. }
  3501. get {
  3502. return className;
  3503. }
  3504. }
  3505. public void SetValue (string value_name, object value)
  3506. {
  3507. ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
  3508. if (class_value == null) {
  3509. class_value = new ClassValue ();
  3510. class_value.Name = value_name;
  3511. classvalues_hashtable [value_name] = class_value;
  3512. }
  3513. class_value.SetValue (value);
  3514. }
  3515. public object GetValue (string value_name)
  3516. {
  3517. ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
  3518. if (class_value == null) {
  3519. return null;
  3520. }
  3521. return class_value.GetValue ();
  3522. }
  3523. public void RemoveAllClassValues ()
  3524. {
  3525. classvalues_hashtable.Clear ();
  3526. }
  3527. public void RemoveClassValue (string value_name)
  3528. {
  3529. ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
  3530. if (class_value != null) {
  3531. classvalues_hashtable.Remove (value_name);
  3532. }
  3533. }
  3534. public void ReadXml (XmlTextReader xtr)
  3535. {
  3536. while (xtr.Read ()) {
  3537. switch (xtr.NodeType) {
  3538. case XmlNodeType.Element:
  3539. string name = xtr.GetAttribute ("name");
  3540. ClassValue class_value = classvalues_hashtable [name] as ClassValue;
  3541. if (class_value == null) {
  3542. class_value = new ClassValue ();
  3543. class_value.Name = name;
  3544. classvalues_hashtable [name] = class_value;
  3545. }
  3546. class_value.ReadXml (xtr);
  3547. break;
  3548. case XmlNodeType.EndElement:
  3549. return;
  3550. }
  3551. }
  3552. }
  3553. public void WriteXml (XmlTextWriter xtw)
  3554. {
  3555. if (classvalues_hashtable.Count == 0)
  3556. return;
  3557. xtw.WriteStartElement (className);
  3558. foreach (DictionaryEntry entry in classvalues_hashtable) {
  3559. ClassValue class_value = entry.Value as ClassValue;
  3560. class_value.WriteXml (xtw);
  3561. }
  3562. xtw.WriteEndElement ();
  3563. }
  3564. }
  3565. internal class ClassValue
  3566. {
  3567. private object value;
  3568. private string name;
  3569. public string Name {
  3570. set {
  3571. name = value;
  3572. }
  3573. get {
  3574. return name;
  3575. }
  3576. }
  3577. public void SetValue (object value)
  3578. {
  3579. this.value = value;
  3580. }
  3581. public object GetValue ()
  3582. {
  3583. return value;
  3584. }
  3585. public void ReadXml (XmlTextReader xtr)
  3586. {
  3587. string type;
  3588. string single_value;
  3589. type = xtr.GetAttribute ("type");
  3590. if (type == "byte_array" || type.IndexOf ("-array") == -1) {
  3591. single_value = xtr.ReadString ();
  3592. if (type == "string") {
  3593. value = single_value;
  3594. } else
  3595. if (type == "int") {
  3596. value = Int32.Parse (single_value);
  3597. } else
  3598. if (type == "byte") {
  3599. value = Byte.Parse (single_value);
  3600. } else
  3601. if (type == "color") {
  3602. int color = Int32.Parse (single_value);
  3603. value = Color.FromArgb (color);
  3604. } else
  3605. if (type == "byte-array") {
  3606. byte[] b_array = Convert.FromBase64String (single_value);
  3607. value = b_array;
  3608. }
  3609. } else {
  3610. ReadXmlArrayValues (xtr, type);
  3611. }
  3612. }
  3613. private void ReadXmlArrayValues (XmlTextReader xtr, string type)
  3614. {
  3615. ArrayList al = new ArrayList ();
  3616. while (xtr.Read ()) {
  3617. switch (xtr.NodeType) {
  3618. case XmlNodeType.Element:
  3619. string single_value = xtr.ReadString ();
  3620. if (type == "int-array") {
  3621. int int_val = Int32.Parse (single_value);
  3622. al.Add (int_val);
  3623. } else
  3624. if (type == "string-array") {
  3625. string str_val = single_value;
  3626. al.Add (str_val);
  3627. }
  3628. break;
  3629. case XmlNodeType.EndElement:
  3630. if (xtr.Name == "value") {
  3631. if (type == "int-array") {
  3632. value = al.ToArray (typeof(int));
  3633. } else
  3634. if (type == "string-array") {
  3635. value = al.ToArray (typeof(string));
  3636. }
  3637. return;
  3638. }
  3639. break;
  3640. }
  3641. }
  3642. }
  3643. public void WriteXml (XmlTextWriter xtw)
  3644. {
  3645. xtw.WriteStartElement ("value");
  3646. xtw.WriteAttributeString ("name", name);
  3647. if (value is Array) {
  3648. WriteArrayContent (xtw);
  3649. } else {
  3650. WriteSingleContent (xtw);
  3651. }
  3652. xtw.WriteEndElement ();
  3653. }
  3654. private void WriteSingleContent (XmlTextWriter xtw)
  3655. {
  3656. string type_string = String.Empty;
  3657. if (value is string)
  3658. type_string = "string";
  3659. else
  3660. if (value is int)
  3661. type_string = "int";
  3662. else
  3663. if (value is byte)
  3664. type_string = "byte";
  3665. else
  3666. if (value is Color)
  3667. type_string = "color";
  3668. xtw.WriteAttributeString ("type", type_string);
  3669. if (value is Color)
  3670. xtw.WriteString (((Color)value).ToArgb ().ToString ());
  3671. else
  3672. xtw.WriteString (value.ToString ());
  3673. }
  3674. private void WriteArrayContent (XmlTextWriter xtw)
  3675. {
  3676. string type_string = String.Empty;
  3677. string type_name = String.Empty;
  3678. if (value is string[]) {
  3679. type_string = "string-array";
  3680. type_name = "string";
  3681. } else
  3682. if (value is int[]) {
  3683. type_string = "int-array";
  3684. type_name = "int";
  3685. } else
  3686. if (value is byte[]) {
  3687. type_string = "byte-array";
  3688. type_name = "byte";
  3689. }
  3690. xtw.WriteAttributeString ("type", type_string);
  3691. if (type_string != "byte-array") {
  3692. Array array = value as Array;
  3693. foreach (object o in array) {
  3694. xtw.WriteStartElement (type_name);
  3695. xtw.WriteString (o.ToString ());
  3696. xtw.WriteEndElement ();
  3697. }
  3698. } else {
  3699. byte[] b_array = value as byte [];
  3700. xtw.WriteString (Convert.ToBase64String (b_array, 0, b_array.Length));
  3701. }
  3702. }
  3703. }
  3704. }
  3705. }
  3706. #endregion
  3707. }